-
Notifications
You must be signed in to change notification settings - Fork 11
/
iwara-dl.sh
executable file
·231 lines (190 loc) · 6.35 KB
/
iwara-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
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
#!/usr/bin/env bash
#set -x
if [ "$(uname)" == "Darwin" ]; then
SCRIPT=$(greadlink -f "$0");
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
SCRIPT=$(readlink -f "$0");
else
SCRIPT=$(readlink -f "$0");
fi
export SCRIPTPATH=$(dirname "$SCRIPT");
source "$SCRIPTPATH/iwaralib.sh";
export DOWNLOAD_FAILED_LIST=();
export IWARA_IGNORE=();
export DOWNLOADED_ID_LIST=();
export DOWNLOADING_ID_LIST=();
export ENABLE_CONTINUE="--continue-at -";
export ENABLE_SLEEP="TRUE"
trap '
trap - INT # restore default INT handler
kill -s INT "$$"
' INT
usage() {
cat - <<EOF
usage: iwara-dl.sh [-u [U]] [-p [P]] [-i [n]] [-rhftcsdn] [-F [M]] [-l [f]] [url [url ...]]
positional arguments:
url
optional arguments:
-h --help show this help message and exit
--username [U] username
--userpass [P] password
--load-ignore-list [File] load the list in file that should not download
-r --retry [Count] try to redownload the video at most [Count] times if not download completely
--user treat input url as usernames
--max-page [Maxpage] only download users' videos from page 1 to [Maxpage]
--cduser-dir cd to each user directory
--quiet-mode quiet mode
--login log in upfront
--accept-insecure accept insecure https connection
--disable-continue make all video download from start
--disable-sleep do not add sleep when download a list of video
--name-only output downloaded file name only(hides curl download bar)
--shallow-update only download users first page
--updater-v1 cd to each username folder; update each folder;
--updater-v2 create ./dl/ folder and update;
--rm [File] add a name to iwara ignore list and delete the file
--follow [M] Download videos of people you are following. M:MaxPage
--dl-list [f] Download using the VideoID in the [F] VideoID List file.
extra:
.iwara_ignore file => newline-saperated list of filenames of skipping download
dl/.iwara_downloaded file => newline-saperated list of VideoID of skipping download
EOF
}
PARSE_AS="";
while true; do
case "$1" in
-h | --help ) usage; exit 01 ;;
--rm )
IGN_NAME="$2";
echo "$IGN_NAME" >> .iwara_ignore;
rm -v *"$IGN_NAME"*;
exit 0; ;;
--username ) IWARA_USER="$2"; shift 2; ;;
--userpass ) IWARA_PASS="$2"; shift 2; ;;
--load-ignore-list )
add-iwara-ignore-list "$2";
shift 2; ;;
--login )
iwara-login;
shift; ;;
-r | --retry )
export RETRY_COUNT=0;
export MAX_RETRY_COUNT="$2";
export IWARA_RETRY="TRUE";
shift 2; ;;
--user )
export PARSE_AS="username";
shift; ;;
--max-page )
export MAX_PAGE="$2"
shift 2; ;;
--cduser-dir )
export CDUSER="TRUE";
export CREATE_USER_DIR="TRUE";
shift; ;;
--quiet-mode )
export IWARA_QUIET="TRUE";
shift; ;;
--shallow-update )
export SHALLOW_UPDATE="TRUE";
shift; ;;
--accept-insecure )
export CURL_ACCEPT_INSECURE_CONNECTION="--insecure";
shift; ;;
--disable-continue )
export ENABLE_CONTINUE="";
shift; ;;
--disable-sleep )
export ENABLE_SLEEP="FALSE";
shift; ;;
--name-only )
export PRINT_NAME_ONLY="--silent";
shift; ;;
--updater-v1 )
export CDUSER="TRUE";
export SHALLOW_UPDATE="TRUE";
export PARSE_AS="username";
update_list=()
for d in */ ; do update_list+=("${d::-1}"); done
shift; ;;
--updater-v2 )
export ENABLE_UPDATER_V2="TRUE";
mkdir -p dl;
cd dl;
shift; ;;
--follow )
export ENABLE_UPDATER_V2="TRUE";
shift 2; ;;
--dl-list )
export PARSE_AS="videoidListfile";
export ENABLE_UPDATER_V2="TRUE";
export VIDEO_ID_LIST_FILE="$2";
load_downloading_id_list $VIDEO_ID_LIST_FILE;
shift; ;;
-- ) shift; break ;;
* ) break ;;
esac
done
args=("$@")
for u in "${update_list[@]}"; do
args+=("$u");
done
if [[ "${PARSE_AS}" == "following" ]]; then
expr "$FOLLOWING_MAXPAGE" + 1 >&/dev/null
if ! [ $? -lt 2 ]; then
echo "Missing [MaxPage]";
exit 0;
fi
elif [[ "${PARSE_AS}" == "videoidListfile" ]]; then
if ! [ -e $VIDEO_ID_LIST_FILE ]; then
echo "Missing [VideoID List File]" ;
exit 0;
fi
load_downloading_id_list $VIDEO_ID_LIST_FILE
elif ! (( $(calc-argc "${args[@]}") )); then
echo "Missing [urls/ids]";
exit 0;
fi
load-downloaded-id-list ".iwara_downloaded"
if [[ "${PARSE_AS}" == "username" ]]; then
for user in "${args[@]}"; do
echo "[[$user]]"
if [[ -f ".iwara_ignore" ]]; then
add-iwara-ignore-list ".iwara_ignore"
fi
if [[ "$CDUSER" ]]; then
if [[ "$CREATE_USER_DIR" == "TRUE" ]]; then
mkdir -p "$user";
fi
cd "$user" || { echo "Skip user [$user]"; continue; }
if [[ -f ".iwara_ignore" ]]; then
add-iwara-ignore-list ".iwara_ignore"
fi
if [[ "$SHALLOW_UPDATE" == "TRUE" ]]; then
iwara-dl-update-user "$user" "0";
else
iwara-dl-update-user "$user";
fi
iwara-dl-retry-dl;
cd "$OLDPWD" || exit 1
else
iwara-dl-update-user "$user"
iwara-dl-retry-dl
fi
done
elif [[ "${PARSE_AS}" == "following" ]]; then
iwara-dl-subscriptions
elif [[ "${PARSE_AS}" == "videoidListfile" ]]; then
iwara-dl-videoidlistfile
else
for url in "${args[@]}"; do
if [[ "$url" == *"iwara.tv/video"* ]]; then
iwara-dl-by-videoid $(url-get-id "$url")
elif [[ "$url" == *"iwara.tv/playlist"* ]]; then
iwara-dl-by-playlist $(url-get-id "$url")
else
iwara-dl-by-videoid "$url"
fi
done
fi
iwara-dl-retry-dl