-
Notifications
You must be signed in to change notification settings - Fork 0
/
NHdownloader.sh
350 lines (309 loc) · 9.51 KB
/
NHdownloader.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
############### PREQUISTE ###############
CONFIG_PATH="./main.config"
source $CONFIG_PATH
if [[ -z "$DOWNLOAD_DIR" ]];
then
DOWNLOAD_DIR="."
fi
if [[ -z "$LINKS_PATH" ]];
then
touch "./links.txt"
fi
if [[ -z "$FILENAMING" ]];
then
FILENAMING="{id} TITLE"
fi
if [[ -z "$USER_AGENT" ]];
then
echo "Enter User Agent in config before continuing !"
echo "Get it from here https://my-user-agent.com/"
exit
fi
############### HEADERS ###############
header_1="accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7,image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"
header_2="user-agent: $USER_AGENT"
header_3="referer: https://nhentai.net/"
header_4="cookie: cf_clearance=${cf_clearance}; csrftoken=${csrftoken}"
header_5="authority: nhentai.net"
h2r_header="referer: https://hentai2read.com/"
############### FUNCTIONS ###############
default_downloader(){
#echo "${links[@]}"
wget2 -t 2 -T 15 -P "./.temp" --header="$header_1" --header="$header_2" "${links[@]}"
echo "Downloaded !"
}
bulk_download_check(){
clear
echo -e "(1) Download Single File \n(2) Download in Bulk ( Make Sure you have ${LINKS_PATH} file! )"
echo -en "\n-> "
read download_choice
case "$download_choice" in
"1")
clear
links=()
mkdir -p "./.temp" && rm -rf ./.temp/*
echo "Enter ID or URL"
echo -en "\n-> "
read input
id=$(echo "$input" | grep -Eo '[0-9]*')
$(echo $site_name) && worker
;;
"2")
clear && bulk_download
;;
*)
clear && echo "ERROR: Please Choose a Valid Option!" && exit
;;
esac
}
bulk_download(){
totalLinks=$(cat ${LINKS_PATH} | sed '/^[[:space:]]*$/d' | wc -l)
if [ $totalLinks == 0 ]
then
clear
echo "ERROR: No Links in ${LINKS_PATH} exiting ..."
exit
fi
echo "Total Links Found: $totalLinks"
for (( m=1; m<=$totalLinks; m++ ));
do
links=()
mkdir -p "./.temp" && rm -rf ./.temp/*
input=$(cat ${LINKS_PATH} | sed -n $m\p)
id=$(echo $(cat ${LINKS_PATH} | sed -n $m\p) | grep -Eo '[0-9]*' | head -n 1)
echo "Downloading ${id}"
$(echo $site_name) && worker
done
}
convert_cleanup(){
TITLE=$(echo "$html" | grep -o '<title>.*</title>' | sed 's/<title>//g' | sed 's/<\/title>//g' | sed 's/\///g')
FILENAMING=$(echo $FILENAMING | sed "s/id/${id}/g" | sed "s/TITLE/${TITLE}/g" )
filename="$(echo ${FILENAMING}).cbz"
zip "${DOWNLOAD_DIR}/${filename}" ./.temp/* && rm -rf ./.temp
}
summary(){
echo "Title :- $(echo "$html" | grep -o '<title>.*</title>' | sed 's/<title>//g' | sed 's/<\/title>//g')"
echo "Total Pages :- $total_pages"
echo "Hentai ID :- $id"
}
pages_error(){
if [[ -z "$total_pages" ]]
then
clear
echo "ERROR: TOTAL PAGES NULL! "
exit
fi
}
images_error(){
if [[ -z "$image_link" ]];
then
clear
echo "ERROR: IMAGE LINK NULL! "
exit
fi
}
Nhentai.net(){
if [ -z ${cf_clearance} ] && [ -z ${csrftoke} ]
then
clear
echo "ERROR: EMPTY cf_clearance & csrftoken in config File please add or try another Website!"
exit
fi
url="https://nhentai.net/g/$id/"
html=$(curl -s "$url" -H "${header_5}" -H "${header_4}" -H "${header_2}" -H "${header_1}" -H "referer: $url" )
total_pages=$(echo "$html" | grep -Eo '<span class="name">[0-9]*</span>' | grep -Eo '[0-9]*')
sub_link="${url}"
image_link=$(curl -s "${sub_link}" -H "${header_5}" -H "${header_1}" -H "${header_4}" -H "${header_3}" -H "${header_2}" | grep -Eo 'https://[a-zA-Z0-9?%-_]*/galleries/[0-9]*/[0-9]*.[a-z]*' )
pages_error
images_error
for (( i=1 ; i<="$total_pages" ; i++ ));
do
sub_link="${url}${i}/"
image_link=$(curl -s "${sub_link}" -H "${header_5}" -H "${header_1}" -H "${header_4}" -H "${header_3}" -H "${header_2}" | grep -Eo 'https://[a-zA-Z0-9?%-_]*/galleries/[0-9]*/[0-9]*.[a-z]*' )
links+=([$i]="${image_link}")
echo -n "#"
done
echo " "
}
Nhentai.to(){
url="https://nhentai.to/g/$id"
header_3="referer: https://nhentai.to/"
html=$(curl -s "$url" -H "${header_1}" -H "${header_2}" -H "${header_3}")
total_pages=$(echo "$html" | grep -Eo '<span class="name">[0-9]*</span>' | grep -Eo '[0-9]*')
pages_error
for (( i=1 ; i<="$total_pages" ; i++ ));
do
sub_link="${url}/${i}"
image_link=$(curl -s "${sub_link}" -H "${header_1}" -H "${header_3}" -H "${header_2}" | grep -Eo 'https://[a-zA-Z0-9?%-_]*/galleries/[0-9]*/[0-9]*.[a-z]*' )
links+=([$i]="${image_link}")
echo -n "#"
done
echo " "
}
hentaifox(){
url="https://hentaifox.com/gallery/$id/"
header_3="referer: https://hentaifox.com/"
html=$(curl -s "$url" -H "${header_2}" )
total_pages=$(echo "$html" | grep -Eo 'Pages: [0-9]*' | sed 's/Pages: //g')
pages_error
for (( i=1 ; i<="$total_pages" ; i++ ));
do
image_url=$(curl -s "https://hentaifox.com/g/${id}/${i}/" -H "${header_2}" | grep -Eo 'data-src="https://.*[0-9]*\.[a-z]*"' | sed 's/data-src=//g' | sed 's/"//g')
links+=(
[$i]=${image_url}
)
echo -n "#"
done
echo " "
}
e-hentai(){
url="$input"
id=$(echo "$url" | grep -Eo 'g/[0-9]*/' | grep -Eo "[0-9]*" )
html=$(curl -s "$url")
total_pages=$(echo "$html" | grep -Eo 'https://e-hentai.org/s/[a-zA-Z0-9?%-_]*/[a-zA-Z0-9?%-_]*"><img alt=' | sed 's/"><img alt=//g' | wc -l )
sub_page_links=$(echo "$html" | grep -Eo 'https://e-hentai.org/s/[a-zA-Z0-9?%-_]*/[a-zA-Z0-9?%-_]*"><img alt=' | sed 's/"><img alt=//g' )
pages_error
for (( i=1 ; i<=$total_pages ; i++ ));
do
link=$(curl -s $(echo "$sub_page_links" | sed -n $i\p ) | grep -Eo 'https://[a-zA-Z0-9?%-_]*/h/[a-zA-Z0-9?%-_/]*.[a-z]*' | sed 's/"//g' )
is_png=$(echo "$link" | grep -Eo "\.png" )
if [[ -z $is_png ]]; then
ext="jpg"
else
ext="png"
fi
links+=(
[$i]="${link}","${i}.${ext}"
)
echo -n "#"
done
echo " "
}
3Hentai(){
id=$(echo "${id}" | tail -n 1)
url="https://3hentai.net/d/$id"
html=$(curl -s $url)
sub_page_links=$(echo "$html" | grep -Eo 'https://3hentai.net/d/[0-9]*/[0-9]*')
total_pages=$(echo "$html" | grep -Eo 'https://3hentai.net/d/[0-9]*/[0-9]*' | wc -l )
pages_error
for (( i=1 ; i<=$total_pages ; i++ ));
do
link=$(curl -s $(echo "$sub_page_links" | sed -n $i\p ) | grep -Eo 'https://[a-zA-Z0-9?%-_]*/[a-zA-Z0-9]*/[0-9]*\.[a-z]*' )
links+=([$i]=${link})
echo -n "#"
done
echo " "
}
Pururin(){
id=$(echo "${input}" | grep -Eo 'gallery/.[0-9]*' | sed 's/gallery\///g')
url="https://pururin.to/gallery/$id"
html=$(curl -s "${url}" -H "${header_1}" -H "${header_2}" -H "${header_3}" )
total_pages=$(echo "$html" | grep -Eo '"numberOfPages">[0-9]*' | grep -Eo '[0-9]*')
sub_page_links=$(echo "$html" | grep -Eo 'https://pururin.to/read/[a-zA-Z0-9?%-_/]*' | awk '!seen[$0]++' )
pages_error
for (( i=1 ; i<=$(echo "$sub_page_links" | wc -l ) ; i++ ));
do
link=$(curl -s $(echo "$sub_page_links" | sed -n $i\p ) | grep -Eo 'https://i.pururin.co/[0-9]*/[0-9]*.[a-z]*' | awk '!seen[$0]++' )
links+=(
[$i]="${link}"
)
echo -n "#"
done
echo " "
}
Asmhentai(){
url="https://asmhentai.com/g/$id/"
html=$(curl -s $url )
total_pages=$(echo "$html" | grep -Eo 'Pages: [0-9]*' | grep -Eo '[0-9]*')
pages_error
for (( i=1 ; i<=$total_pages ; i++ ));
do
image_link=$(curl -s $(echo "${url}${i}/" | sed 's/g/gallery/g') | grep -Eo "https://images.asmhentai.com/[0-9]*/[0-9]*/[a-z0-9?%-_]*" )
links+=(
[$i]="$image_link"
)
echo -n "#"
done
echo " "
}
Hentai2read(){
url="$input"
html=$(curl -s $url)
id=$(echo "$url" | sed 's/https:\/\/hentai2read.com\///g' | sed 's/\///g' )
total_pages=$(echo "$html" | grep -Eo '[0-9]* pages' | grep -Eo '[0-9]*' )
pages_error
for (( i=1 ; i<=$total_pages ; i++ ));
do
image_link=$(curl -s "${url}1/${i}/" | grep -Eo 'https://static.hentai.direct/hentai/[0-9]*/[0-9]*/[a-zA-Z0-9?%-_]*' )
links+=(
[$i]="$image_link"
)
echo -n "#"
done
echo " "
wget2 -t 2 -T 15 -P "./.temp" --header="$header_1" --header="$header_2" --header="$h2r_header" "${links[@]}"
echo "Downloaded !"
}
############### WORKER ###############
worker(){
default_downloader && convert_cleanup && summary
}
############### NHLOGO ###############
logo(){
echo "CiAgXyAgXyBfICBfICAgIF8gICAgICAgICAgICAgICAgIF8gICAgICAgICAgICAgIF8gICAgICAgICAKIHwgXHwgfCB8fCB8X198IHxfX19fXyBfXyBfX18gXyB8IHxfX18gIF9fIF8gX198IHxfX18gXyBfIAogfCAuYCB8IF9fIC8gX2AgLyBfIFwgViAgViAvICcgXHwgLyBfIFwvIF9gIC8gX2AgLyAtXykgJ198CiB8X3xcX3xffHxfXF9fLF9cX19fL1xfL1xfL3xffHxffF9cX19fL1xfXyxfXF9fLF9cX19ffF98ICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAo=" | base64 -d
}
############### INPUT ###############
choose_website(){
echo -e "(1) Nhentai.net
(2) Hentaifox.com
(3) E-Hentai.org ( Enter Full URL! )
(4) 3Hentai.net
(5) Pururin.to
(6) Asmhentai.com
(7) Hentai2read.com ( Enter Full URL! )
(8) Nhentai.to"
echo -en "\n-> "
read website
}
############### EXECUTION ###############
clear && logo && choose_website
case "$website" in
"1")
site_name="Nhentai.net"
bulk_download_check
;;
"2")
site_name="hentaifox"
bulk_download_check
;;
"3")
site_name="e-hentai"
bulk_download_check
;;
"4")
site_name="3Hentai"
bulk_download_check
;;
"5")
site_name="Pururin"
bulk_download_check
;;
"6")
site_name="Asmhentai"
bulk_download_check
;;
"7")
site_name="Hentai2read"
echo "I will fix it later :( [ Rest are Working! ]"
;;
"8")
site_name="Nhentai.to"
bulk_download_check
;;
*)
clear
echo "ERROR: Please choose a valid option ! "
exit
;;
esac