-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
make-pdfs.sh
executable file
·90 lines (68 loc) · 2.39 KB
/
make-pdfs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /usr/bin/env nix-shell
#! nix-shell -i zsh -p jq curl imagemagick ghostscript file zsh
OUTDIR="${0:a:h}"
while getopts f o
do case "$o" in
f) FORCE="yes";
esac
done
EPISODES=("${(@f)$(jq -r '.[]' episodes.json)}")
LANGUAGES=("${(@f)$(jq -r '.[]' languages.json)}")
function download() {
EPISODE=$1
NUMBER="${(l:2::0:)2}"
LANGUAGE=$3
i=0
while
FILE="${LANGUAGE}_Pepper-and-Carrot_by-David-Revoy_E${NUMBER}P${(l:2::0:)i}.jpg"
URL="https://www.peppercarrot.com/0_sources/ep${NUMBER}_${EPISODE}/hi-res/${FILE}"
STATUSCODE=$(curl --silent --remote-name --write-out "%{http_code}" $URL)
if [ $STATUSCODE -ne 200 ] || ! [[ $(file -b $FILE) =~ JPEG ]]; then
URL="https://www.peppercarrot.com/0_sources/ep${NUMBER}_${EPISODE}/low-res/${FILE}"
STATUSCODE=$(curl --silent --remote-name --write-out "%{http_code}" $URL)
fi
if ! [[ $(file -b $FILE) =~ JPEG ]]; then
rm $FILE
fi
(( i = i + 1 ))
[ $STATUSCODE -eq 200 ]
do :; done
}
function build() {
NUMBER="${(l:2::0:)1}"
LANGUAGE=$2
convert -rotate 270 -extent 1240x1753 -units PixelsPerInch \
-density 150x150 -gravity center *P00.jpg title-page.pdf
convert *P<1-99>.jpg -compress jpeg -resize 1240x1753 \
-extent 1240x1753 -gravity center \
-units PixelsPerInch -density 150x150 story.pdf
mkdir -p "${OUTDIR}/$LANGUAGE"
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
-sOutputFile="${OUTDIR}/$LANGUAGE/episode-${NUMBER}.pdf" \
title-page.pdf story.pdf
}
for ((lang = 1; lang <= $#LANGUAGES; lang++)); do
echo "Language: ${LANGUAGES[lang]}"
for ((ep = 1; ep <= $#EPISODES; ep++)); do
echo -n "Episode: ${EPISODES[ep]}"
if [ -z $FORCE ] && [ -f "${LANGUAGES[lang]}/episode-${(l:2::0:)ep}.pdf" ]; then
echo -n " exists, skipping ..."
else
tempDir=$(mktemp -d)
cd $tempDir
download "${EPISODES[ep]}" $ep "${LANGUAGES[lang]}"
set -o NULL_GLOB
set -- *P00.jpg
if [ "$#" -eq 0 ]; then
echo " doesn't exist in language ${LANGUAGES[lang]}, skipping ..."
cd -
rm -rf $tempDir
break;
fi
build $ep "${LANGUAGES[lang]}"
cd -
rm -rf $tempDir
fi
echo
done
done