-
Notifications
You must be signed in to change notification settings - Fork 0
/
comic-dl
executable file
·85 lines (72 loc) · 1.69 KB
/
comic-dl
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
#!/bin/bash
TMPDIR=$(mktemp -d -t comic-dl)
q='""'
parseTitle() {
echo "$1" | perl -pe 's#^.*/Comic/(.*)/Issue.*#$1#'
}
parseIssue() {
echo "$1" | perl -pe 's#^.*/Issue-(\d+).*#$1#'
}
download() {
# check for valid arguments
if [ $# -lt 3 ]; then
echo "Usage: download url title issue"
return
fi
url="$1"
title="$2"
issue=$(printf "%03d" $3)
page=1
echo -n "$title #${3}: "
curl --silent --location -u '${username}:${password}' "${url}" \
| perl -ne 'if(/lstImages.push\("(.*)"\)/) { print "$1\n" }' \
| while read url; do
echo "url=$url"
pageStr=$(printf "%04d" $page)
curl --silent "${url//[$'\t\r\n']}" -o "${TMPDIR}/${title}.${issue}.${pageStr}.jpg"
echo -n "[$page]"
((page++))
done
echo ""
if [ $page -lt 2 ]; then
echo "Not enough pages? - $title.$issue $url"
else
# don't specify ".jpg" since it might be .png or .gif or whatever
zip -q "$title.$issue.cbz" "${TMPDIR}/$title.$issue."[0-9][0-9]*.* && rm "${TMPDIR}/$title.$issue."[0-9][0-9]*.*
fi
}
cleanup() {
rm -rf "${TMPDIR}"
echo "## issue interrupt"
exit 1
}
RCFILE=~/.comic-dl
if [ ! -r $RCFILE ]; then
echo -n "Username: ";
read username
echo -n "Password: "
read -s password
echo "username=$q$username$q; password=$q$password$q" > "$RCFILE"
else
. $RCFILE
fi
trap 'cleanup' INT
if [ $# = 0 ]; then
cat <<-EOF
Usage: comic-dl url
- url is from https://readcomiconline.li
EOF
exit 0
fi
for url; do
title=$(parseTitle "$url")
issue=$(parseIssue "$url")
issueString=$(printf "%03d" $issue)
filename="$title.$issueString.cbz"
if [ -r "$filename" ]; then
echo "Skipping $filename (exists)"
else
download "$url" "$title" "$issue" && sleep 2
fi
done
rm -rf "${TMPDIR}"