This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdl.sh
executable file
·87 lines (80 loc) · 2.46 KB
/
dl.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
#!/bin/bash
CURL_TRUE="no"
wget_or_curl(){
if ! [ -x "$(command -v curl)" ]; then
CURL_TRUE="no"
else
CURL_TRUE="yes"
fi
}
wget_or_curl
anime=$(basename $PWD)
echo "anime is $anime"
echo "curl is installed: $CURL_TRUE"
IFS=$'\n'
total=$(cat list.txt | wc -l | xargs)
if [ $# -ne 2 ]
then
echo Total no of episodes : $total
echo Enter \'a\' for all episodes
echo start at:
read s
if [[ $s != "a" ]]
then
echo end at:
read e
fi
else
s=$1
e=$2
fi
if [[ "$e" == "a" ]]
then
e=$total
fi
# number of digits in the totalcount
maxpad=$(echo $total | wc -m)
# echo $total|wc -m
maxpad=$((maxpad-1))
if [[ "$s" == "a" ]]
then
count=0
for i in $(cat list.txt)
do
count=$((count+1))
# https://stackoverflow.com/a/8789815/8608146
printf -v paded_count "%0${maxpad}d" $count
name=$anime-$paded_count.mp4
# this is extremely important
# without this the file will not download
# the url will become a 404
# https://stackoverflow.com/a/35019553/8608146
i=${i%$'\r'}
echo "downloading $name"
if [[ $CURL_TRUE == "yes" ]]
then
curl -L -o $name -C - "$i" -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36' -H "Referer: https://twist.moe/"
else
wget -c -q --show-progress $i -O $name --header='user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36' --header="Referer: https://twist.moe/"
fi || break
done
else
j=1
for i in $(cat list.txt)
do
if [ $j -ge $s -a $j -le $e ]
then
printf -v paded_count "%0${maxpad}d" $j
name=$anime-$paded_count.mp4
echo "downloading $name"
i=${i%$'\r'}
if [[ $CURL_TRUE == "yes" ]]
then
curl -L -o $name -C - "$i" -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36' -H "Referer: https://twist.moe/"
else
wget -c -q --show-progress $i -O $name --header='user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36' --header="Referer: https://twist.moe/"
fi || break
fi
j=$((j+1))
done
fi