nnn/plugins/gutenread

50 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
# Description: Browse Project Gutenberg catalogue by popularity, then download
# and read a book of your choice.
#
# Details: Set the variable EBOOK_ID to download in html format and read in w3m.
# Clear EBOOK_ID to browse available ebooks by popularity and set it to
# the ID once you find an interesting one.
2019-10-13 05:41:39 +00:00
# To dowload and read in epub format set READER to an epub reader like
# epr: https://github.com/wustho/epr
#
2019-10-13 05:41:39 +00:00
# More on EBOOK_ID:
# Wuthering Heights by Emily Brontë is at https://www.gutenberg.org/ebooks/768
# So EBOOK_ID would be 768
#
2019-10-13 05:41:39 +00:00
# Downloaded ebooks are at ${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
EBOOK_ID=
DIR=${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/"$EBOOK_ID"
BROWSE_LINK="http://www.gutenberg.org/ebooks/search/?sort_order=downloads"
BROWSER=w3m
2019-10-13 05:41:39 +00:00
READER=
if [ ! -z "$EBOOK_ID" ]; then
2019-11-21 20:44:25 +00:00
if [ ! -e "$DIR" ]; then
mkdir -p "$DIR"
cd "$DIR" || exit 1
2019-10-13 05:41:39 +00:00
if [ -z "$READER" ]; then
2019-11-21 20:44:25 +00:00
curl -L -O https://www.gutenberg.org/files/"$EBOOK_ID"/"$EBOOK_ID"-h.zip
2019-10-13 05:41:39 +00:00
unzip "$EBOOK_ID"-h.zip
else
2019-11-21 20:44:25 +00:00
curl -L -o "$EBOOK_ID".epub http://www.gutenberg.org/ebooks/"$EBOOK_ID".epub.noimages
2019-10-13 05:41:39 +00:00
fi
fi
2019-11-21 20:44:25 +00:00
if [ -d "$DIR" ]; then
2019-10-13 05:41:39 +00:00
if [ -z "$READER" ]; then
2019-11-21 20:44:25 +00:00
"$BROWSER" "$DIR"/"$EBOOK_ID"-h/"$EBOOK_ID"-h.htm
2019-10-13 05:41:39 +00:00
else
2019-11-21 20:44:25 +00:00
"$READER" "$DIR"/"$EBOOK_ID".epub
2019-10-13 05:41:39 +00:00
fi
fi
else
2019-11-21 20:44:25 +00:00
"$BROWSER" "$BROWSE_LINK"
fi