Created
April 9, 2018 13:46
-
-
Save vwrs/6cbaea865ed4a3e88f4f6a2496ded712 to your computer and use it in GitHub Desktop.
download as pdf from Dropbox when the download option is disabled
This file contains 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 -eu | |
# first, get the image URLs using such as Chrome DevTools | |
# The URLs is assumed to be "xxxxx?page={page number}" | |
URI=("https://path/to/file1" "https://path/to/file2") | |
PAGES=(10 20) | |
RED="" | |
GREEN="" | |
BLUE="" | |
NORMAL="" | |
if which tput >/dev/null 2>&1; then | |
ncolors=$(tput colors) | |
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then | |
RED="$(tput setaf 1)" | |
GREEN="$(tput setaf 2)" | |
BLUE="$(tput setaf 4)" | |
NORMAL="$(tput sgr0)" | |
fi | |
fi | |
# check | |
if ! type wget > /dev/null 2>&1 ; then | |
echo "please install wget." | |
exit 1 | |
fi | |
if ! type convert > /dev/null 2>&1 ; then | |
echo "please install imagemagick." | |
exit 1 | |
fi | |
# main | |
# ----------- | |
for ch in `seq 0 $(( ${#URI[@]}-1 ))` ; do | |
echo "chapter $(( $ch+1 )):" | |
# download | |
for i in `seq 0 ${PAGES[$ch]}` ; do | |
echo "==> wget ${URI[$ch]}$i -O $i.png" | |
wget ${URI[$ch]}$i -O $i.png > /dev/null 2>&1 | |
done | |
# convert | |
echo "${BLUE}==> convert {0..${PAGES[$ch]}}.png ch$(( $ch+1 )).pdf$NORMAL" | |
eval convert {0..${PAGES[$ch]}}.png ch$(( $ch+1 )).pdf | |
if [ $? = 0 ]; then | |
echo "${BLUE}==> rm {0..${PAGES[$ch]}}.png$NORMAL" | |
eval rm {0..${PAGES[$ch]}}.png | |
echo "${GREEN}saved chapter $ch files to ch$(( $ch+1 )).pdf. ✔︎ $NORMAL" | |
else | |
echo "${RED}An unexpected error occurred when converting png files to pdf.$NORMAL" | |
exit 1 | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment