gutenread (1620B)
1 #!/usr/bin/env sh 2 3 # Description: Browse Project Gutenberg catalogue by popularity, then download 4 # and read a book of your choice. 5 # 6 # Details: Set the variable EBOOK_ID to download in html format and read in w3m. 7 # Clear EBOOK_ID to browse available ebooks by popularity and set it to 8 # the ID once you find an interesting one. 9 # To download and read in epub format set READER to an epub reader like 10 # epr: https://github.com/wustho/epr 11 # 12 # More on EBOOK_ID: 13 # Wuthering Heights by Emily Brontë is at https://www.gutenberg.org/ebooks/768 14 # So EBOOK_ID would be 768 15 # 16 # Downloaded ebooks are at ${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/ 17 # 18 # Shell: POSIX compliant 19 # Author: Arun Prakash Jana 20 21 EBOOK_ID="${EBOOK_ID}" 22 DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/$EBOOK_ID" 23 BROWSE_LINK="https://www.gutenberg.org/ebooks/search/?sort_order=downloads" 24 BROWSER="${BROWSER:-w3m}" 25 READER="${READER}" 26 27 if [ -n "$EBOOK_ID" ]; then 28 if [ ! -e "$DIR" ]; then 29 mkdir -p "$DIR" 30 cd "$DIR" || exit 1 31 32 if [ -z "$READER" ]; then 33 curl -L -O "https://www.gutenberg.org/files/$EBOOK_ID/$EBOOK_ID-h.zip" 34 unzip "$EBOOK_ID"-h.zip 35 else 36 curl -L -o "$EBOOK_ID".epub "https://www.gutenberg.org/ebooks/$EBOOK_ID.epub.noimages" 37 fi 38 fi 39 40 if [ -d "$DIR" ]; then 41 if [ -z "$READER" ]; then 42 "$BROWSER" "$DIR/$EBOOK_ID-h/$EBOOK_ID-h.htm" 43 else 44 "$READER" "$DIR/$EBOOK_ID.epub" 45 fi 46 fi 47 else 48 "$BROWSER" "$BROWSE_LINK" 49 fi