E-readers

Many years ago, I bought an e-ink Kindle Touch. I find it's quite useful for focusing on a single piece of content. In the past I've used it with Calibre to trim down my browser's tab count. I also have a Bluetooth transmitter which has allowed me to listen to documents via text-to-speech on my Bluetooth headphones while working with my hands. I've found it quite helpful, even if I haven't been using it much lately.

I use two scripts to get webpages onto my Kindle, one which converts the page in question to an ebook and one which uploads everything to my e-reader once it's mounted.

The ebook conversion script:

#!/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!"

The uploading script:

#!/usr/bin/env sh

set -e

# Guess the directory the Kindle is mounted to
kindle="$(find /media -type d -name amazon-cover-bug -exec dirname {} ;)"

[ "$kindle" ] || { >&2 echo "Could not find Kindle."; exit 1; }

# The old Kindle only knows about mobi files
rsync -rv --include="*/" --include="*.mobi" --exclude="*" 
  "$HOME/extramuros/documents/ebooks/" "$kindle/documents/"

I hadn't written these for general use, so at the very least you will need to change the "extramuros" path to point to wherever you like to save your ebooks. You may also need to change the second script to look for a different file, possibly under a different directory, to identify where your e-reader is mounted, and you may also need to change where rsync uploads the files. (That script is, upon reflection, quite specific to my Kindle.)

relevant links:

=> https://calibre-ebook.com/ Calibre

Page Created:: 2021-07-14

Last Updated:: 2024-12-12

Last Reviewed:: 2024-12-12