Created
August 16, 2021 11:49
-
-
Save dorneanu/6445acd2bcc4eae89df2b6596fa3f664 to your computer and use it in GitHub Desktop.
This will fetch readable content from an URL (using rdrview), convert HTML content to Epub (using pandoc) and finally upload the e-book to Dropbox (using rclone)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RDRVIEW_OUTPUT=~/work/dropbox/rdrview | |
DROPBOX_DIR="dropbox:Apps/Dropbox PocketBook/articles/2021/" | |
add_link_to_dropbox() { | |
# Create tmp file | |
TEMP_FILE=$(mktemp) | |
# Make link readable | |
rdrview -T title,body -H $1 > $TEMP_FILE | |
# Extract title | |
TITLE=$(xmllint --html --xpath "//div/h1/text()" 2>/dev/null ${TEMP_FILE}) | |
echo "[-] Converting $TITLE" | |
# Convert to PDF | |
OUTPUT_FILE="${RDRVIEW_OUTPUT}/${TITLE// /_}".epub | |
pandoc --pdf-engine=xelatex --metadata title="${TITLE}" -f html -t epub -o ${OUTPUT_FILE} ${TEMP_FILE} | |
# Copy to dropbox | |
rclone copy ${OUTPUT_FILE} "${DROPBOX_DIR}" | |
# Log | |
echo "[-] Successfully added ${OUTPUT_FILE} to dropbox." | |
# Clean up | |
rm $TEMP_FILE | |
rm $OUTPUT_FILE | |
} | |
add_link_to_dropbox $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment