💾 Archived View for lyk.so › systems › e-reader › scripts › ebook-from-web.sh captured on 2023-06-16 at 16:18:22.

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

#!/usr/bin/env sh

# Dependencies:
# calibre

set -e

EBOOK_DIR="$HOME/extramuros/documents/ebooks"

[ "$2" ] || { >&2 echo "usage: $0 <author> <URL> [formats]"; exit 1; }

temp="$(mktemp -d)"
trap 'rm -fr "$temp"' EXIT INT HUP

web2disk -r0 -d "$temp" "$2"

fname="$(basename "$2")"
formats="${3:-epub,mobi}" # Mobi is compatible with old Kindles
mkdir -p "$EBOOK_DIR/$1"

echo "$formats" | tr , "\n" | while read format; do
  dest="$EBOOK_DIR/$1/${fname%.*}.$format"

  ebook-convert "$temp/"*.xhtml "$dest"
  ebook-meta -a "$(echo "$1" | sed 's/ and / & /')" --identifier "uri:$2" "$dest"
done

echo "Done!"