-
Notifications
You must be signed in to change notification settings - Fork 3
/
dl_manga_grep_page_JBs.sh
executable file
·146 lines (122 loc) · 4.73 KB
/
dl_manga_grep_page_JBs.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
#
# Autor= João Batista Ribeiro
# Bugs, Agradecimentos, Críticas "construtivas"
# me envie um e-mail. Ficarei Grato!
# e-mail: joao42lbatista@gmail.com
#
# Este programa é um software livre; você pode redistribui-lo e/ou
# modifica-lo dentro dos termos da Licença Pública Geral GNU como
# publicada pela Fundação do Software Livre (FSF); na versão 2 da
# Licença, ou (na sua opinião) qualquer versão.
#
# Este programa é distribuído na esperança que possa ser útil,
# mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a
# qualquer MERCADO ou APLICAÇÃO EM PARTICULAR.
#
# Veja a Licença Pública Geral GNU para mais detalhes.
# Você deve ter recebido uma cópia da Licença Pública Geral GNU
# junto com este programa, se não, escreva para a Fundação do Software
#
# Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Script: Download images (manga) from a link
#
# Last update: 19/06/2023
#
echo -e "\n# Download images (manga) from a link #\n"
help() {
echo "Usage:"
echo " $0 [OPTION] ..."
echo "The script's parameters are:"
echo " -h This help"
echo " -n <name> Manga name to download. With space use \"manga name\" as \"One Piece\""
echo " -l <link> Link to download the manga (with out chapter number)"
echo " -s Chapter to start the download"
echo -e " -e Chapter to end the download\n"
exit 0
}
while getopts "hn:l:s:e:" optionInput; do
case $optionInput in
'h' ) help ;;
'n' ) mangaName=${OPTARG} ;;
'l' ) linkDl=${OPTARG} ;;
's' ) chapterStart=${OPTARG} ;;
'e' ) chapterEnd=${OPTARG} ;;
* )
echo -e "\nInvalid option inputted\n"
exit 1
esac
done
if [ "$mangaName" == '' ]; then
echo -en "Manga name: "
read -r mangaName
if [ "$mangaName" == '' ]; then
echo -e "\nError: The manga name can't be empty\n"
exit 1
fi
fi
if [ "$linkDl" == '' ]; then
echo -en "\nManga link to download (without chapter number): "
read -r linkDl
if [ "$linkDl" == '' ]; then
echo -e "\nError: The link <site> can't be empty\n"
exit 1
fi
fi
echo -en "\nOne change in the Manga link to download (e.g., link/mangaName-01) (hit enter to none): "
read -r linkBeginChange
if [ "$chapterStart" == '' ]; then
echo -en "\nChapter to start: "
read -r chapterStart
if [ "$chapterStart" == '' ]; then
echo -e "\nError: The chapter to start can't be empty\n"
exit 1
fi
fi
if [ "$chapterEnd" == '' ]; then
echo -en "\nChapter to end: "
read -r chapterEnd
if [ "$chapterEnd" == '' ]; then
chapterEnd=$chapterStart
fi
fi
echo -e "\nWill download \"$mangaName\" from the chapter \"$chapterStart\" to \"$chapterEnd\""
echo -en "From: \"${linkDl}$linkBeginChange\"\n\nContinue? (y)es or (n)o (hit enter to yes): "
read -r ContinueOrNot
if [ "$ContinueOrNot" == 'n' ]; then
echo -e "\nJust exiting by local choice\n"
else
mkdir "$mangaName"
cd "$mangaName" || exit
((chapterEnd+=1)) # To download the last chapter in the while condition
IFS=$(echo -en "\n\b") # Change the Internal Field Separator (IFS) to "\n\b"
while [ "$chapterStart" -lt "$chapterEnd" ]; do # Run until chapter download equal to end chapter to download
zeroChapter=0 # Just for zero to 0 to 9
if [ "$chapterStart" -gt 9 ]; then
zeroChapter='' # Greater then 9, don't need zero in begin
fi
chapterDl="$zeroChapter$chapterStart"
mangaNameAndChapterDl="$mangaName $chapterDl"
echo -e "\nDownload the HTML file from page $chapterDl\n"
wget --tries=3 "${linkDl}$linkBeginChange$chapterDl" -O "${chapterDl}.html"
linksPageDl=$(grep -E ".jpg|.png|.PNG|.JPG|.webp|.WEBP" "${chapterDl}.html" | grep "[[:digit:]]" | grep -o "src=.*" | cut -d '"' -f2 | grep "$mangaName") # Grep link to all images (png, jpg)
rm "${chapterDl}.html" # Delete HTML page file
linksPageDl=$(echo -e "$linksPageDl" | sed 's/^\/\///g') # Remove "//" from the begin of some links
i=1
countImg=$(echo "$linksPageDl" | wc -l)
mkdir "$mangaNameAndChapterDl" # Create folder to download the images
cd "$mangaNameAndChapterDl" || exit
for linkImg in $linksPageDl; do
echo -e "\nDownloading chapter: $chapterDl images: $i of $countImg (\"$linkImg\")\n"
echo "wget --tries=3 -c \"$linkImg\""
wget --tries=3 -c "$linkImg"
((i++))
done
cd .. || exit
zip -r "${mangaNameAndChapterDl}.zip" "$mangaNameAndChapterDl"
rm -r "$mangaNameAndChapterDl" # Delete the folder with the images
((chapterStart++))
done
echo -e "\nScript end\n"
fi