-
Notifications
You must be signed in to change notification settings - Fork 1
/
iView_Downloader_OSX_7.0.sh
executable file
·361 lines (311 loc) · 9.48 KB
/
iView_Downloader_OSX_7.0.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
351
352
353
354
355
356
357
358
359
360
361
#!/bin/bash
SLEEPTIME=5s
MAXRETRIES=5
SWFPARAMS='-w 96cc76f1d5385fb5cda6e2ce5c73323a399043d0bb6c687edd807e5c73c42b37 -x 2122'
CURDIR=$(dirname "${0}")
FFMPEG='ffmpeg'
FLVSTREAMER='rtmpdump_universal'
TEMPDIR=$(mktemp -d -t iview)
DOWNLOAD_LIST=${TEMPDIR}/download_list.txt
COMPLETE_DOWNLOADS=${TEMPDIR}/CompleteDownloads.txt
INCOMPLETE_DOWNLOADS=${TEMPDIR}/IncompleteDownloads.txt
SEARCH_RESULTS=${TEMPDIR}/searchresults.txt
RAWSEARCH_RESULTS=${TEMPDIR}/rawsearchresults.txt
POSSIBLE_SHOWS=${TEMPDIR}/possibleshows.txt
SERIES=${TEMPDIR}/series.txt
FILTERED_SHOWS=${TEMPDIR}/filtered_shows.txt
AUTH_XML=${TEMPDIR}/auth.xml
TEMP_TXT=${TEMPDIR}/temp.txt
SHOW_INDEX=${TEMPDIR}/showindex
function jsonval {
JSON=${1}
PROPERTY=${2}
TEMP=$(echo ${JSON} | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w ${PROPERTY})
echo ${TEMP##*|}
}
function searchShows() {
echo "Enter search string (not case sensitive):"
read SEARCHSTRING
cat ${POSSIBLE_SHOWS} | grep -i ${SEARCHSTRING} > ${RAWSEARCH_RESULTS}
nl ${RAWSEARCH_RESULTS} | sed 's/ *//' > ${SEARCH_RESULTS}
cat ${SEARCH_RESULTS} | sed 's/\(.*\) .*/\1/'
LINES=$(cat ${SEARCH_RESULTS} | wc -l | sed 's/ //g')
case ${LINES} in
0)
echo "No matching results found"
read -p "Press enter to continue..."
return
;;
*)
;;
esac
echo "Select a number to add a show to download list, 'a' adds all, 0 adds nothing:"
read NUMBER
case ${NUMBER} in
a|A)
cat ${RAWSEARCH_RESULTS} | sed 's/.* //' >> ${DOWNLOAD_LIST}
;;
0)
;;
*)
SHOWPATH=$(grep -w ^"${NUMBER}" ${SEARCH_RESULTS} | sed "s/^${NUMBER}//g" | tr -d '\t')
echo "${SHOWPATH}" >> ${DOWNLOAD_LIST}
;;
esac
}
function downloadShowList() {
# Erase old lists
rm ${POSSIBLE_SHOWS}
TEMPINDEX=$(mktemp -t iview-temp-index)
echo "Downloading Index..."
for CATEGORY in "0-z"
do
curl -q "http://tviview.abc.net.au/iview/api2/?keyword=${CATEGORY}" >> ${TEMPINDEX}
cat ${TEMPINDEX} >> ${SHOW_INDEX}
rm ${TEMPINDEX}
done
echo "Reading Index..."
#This will separate the lines out with either a series or a show descriptor on each line
cat ${SHOW_INDEX} | sed -e 's/{"a":"/\
{"a":"/g' -e '/^\[$/d' -e '/^\]$/d' > ${SERIES}
LINES=$(cat ${SERIES} | wc -l | sed 's/ //g')
COUNTER=1
while [ ${COUNTER} -lt ${LINES} ]; do
let COUNTER=COUNTER+1
CURRENT=$(sed "${COUNTER}!d" ${SERIES})
ID=$(jsonval "${CURRENT}" a)
echo ${ID}
COUNT=$(echo ${ID} | wc -m)
# If 7 chars then find showpath and add to list otherwise grab the series name for the next few shows (8 defines a series, 7 defines a show)
if [ ${COUNT} = "7" ]; then
CURRENT=$(echo "${CURRENT}" | sed 's/[0-9]*\"\,\"b\"\:\"//' | sed 's/\\//g' | sed 's/mp4.*/\mp4/' | sed 's/flv.*/flv/')
SHOWNAME=$(echo "${CURRENT}" | sed 's/\".*//g' | sed 's,\/,-,g' | sed 's/\&\;/\&/') # This also replaces / with - and replaces & with &
SHOWPATH=$(echo "${CURRENT}" | sed 's/.*\"//g')
echo "${SERIESNAME} ${SHOWNAME} ${SHOWPATH}" >> ${POSSIBLE_SHOWS}
else
CURRENT=$(echo "${CURRENT}" | sed 's/[0-9]*\"\,\"b\"\:\"//' | sed 's/\\//g' | sed 's/mp4.*/\mp4/' | sed 's/flv.*/flv/')
SERIESNAME=$(echo "${CURRENT}" | sed 's/\".*//g' | sed 's,\/,-,g' | sed 's/\&\;/\&/') # This also replaces / with - and replaces & with
fi
done
sort ${POSSIBLE_SHOWS} > ${TEMP_TXT}
mv ${TEMP_TXT} ${POSSIBLE_SHOWS}
}
function getShow() {
echo
echo "Which list do you wish to browse:"
echo
echo "A. Download new list from iView server"
echo
echo "B. Use existing list"
echo
echo "C. Manually Enter"
echo
echo "Type the letter and press Enter:"
read SELECTION
echo
echo "You selected ${SELECTION}"
MANUAL='false'
case ${SELECTION} in
a|A)
downloadShowList
;;
b|B)
;;
c|C)
echo "Enter showname (What you want the file to be saved as):"
read SHOWNAME
echo "Enter showpath (The server path):"
read SHOWPATH
echo "${SHOWNAME} ${SHOWPATH}" >> ${DOWNLOAD_LIST}
MANUAL='true'
;;
*)
echo "Invalid Selection, Please pick again."
MANUAL='true'
;;
esac
clear
case ${MANUAL} in
'false')
cat ${POSSIBLE_SHOWS} | nl | sed 's/ *//' > ${FILTERED_SHOWS}
cat ${FILTERED_SHOWS} | sed 's/\(.*\) .*/\1/'
echo "Select a number to add a show to download list, 'a' adds all,"
echo "0 adds nothing, and 's' allows you to search this list:"
read NUMBER
case ${NUMBER} in
a|A)
cat ${POSSIBLE_SHOWS} >> ${DOWNLOAD_LIST}
;;
s|S)
searchShows
;;
0)
;;
*)
SHOWPATH=$(grep -w ^"${NUMBER}" ${FILTERED_SHOWS} | sed "s/^${NUMBER}//g" | tr -d '\t')
echo "${SHOWPATH}" >> ${DOWNLOAD_LIST}
;;
esac
;;
*)
;;
esac
}
function downloadShow() {
FILENAME=$(echo ${1} | sed 's/\(.*\) .*/\1/')
SHOWPATH=$(echo ${1} | sed 's/.* //')
SHOWEXT=$(echo ${1} | sed 's/.*\.//g')
RETRY=0
SUCCESS='false'
while [ ${MAXRETRIES} -gt ${RETRY} ]; do
let RETRY=RETRY+1
echo "Attempt ${RETRY} of ${MAXRETRIES}"
echo "Retrieving Token..."
curl -q http://tviview.abc.net.au/iview/auth/?v2 > ${AUTH_XML}
TOKEN=$(cat ${AUTH_XML} | grep token | sed 's/.*<token>//g' | sed 's/\\&/\\&/g' | sed 's,</token>.*,,g' | sed 's/ //g')
HOST=$(cat ${AUTH_XML} | grep host | sed 's/<host>//g' | sed 's,</host>,,g' | sed 's/ //g' | tr -d '\r')
case ${SHOWEXT} in
"mp4")
case ${HOST} in
"Akamai")
SERVERPATH=${SHOWPATH}.mp4
;;
*)
SERVERPATH=mp4:${SHOWPATH}
;;
esac
;;
*)
SERVERPATH=${SHOWPATH}
;;
esac
echo "Ok, you will be requesting ${SERVERPATH}"
echo "and saving the stream with the filename ${FILENAME}.${SHOWEXT}"
echo "from ABC iView servers on ${HOST}"
echo "using the auth ${TOKEN}"
case ${HOST} in
"Akamai")
echo "Running Akamai..."
${FLVSTREAMER} --resume -r "rtmp://cp53909.edgefcs.net////flash/playback/_definst_/${SERVERPATH}" -t "rtmp://cp53909.edgefcs.net/ondemand?auth=${TOKEN}" -o "${CURDIR}"/"${FILENAME}.${SHOWEXT}" ${SWFPARAMS}
;;
*)
echo "Running Hostworks..."
${FLVSTREAMER} --resume -r "rtmp://203.18.195.10/ondemand?auth=${TOKEN}&${SERVERPATH}" -y ${SERVERPATH} -o "${CURDIR}"/"${FILENAME}.${SHOWEXT}" ${SWFPARAMS}
;;
esac
case ${?} in
0)
SUCCESS='true'
;;
*)
echo "Error code ${?}"
echo "Sleeping for ${SLEEPTIME}"
sleep ${SLEEPTIME}
;;
esac
# case ${SHOWEXT} in
# "mp4")
# SHOWEXT=flv
# ;;
# *)
# SHOWEXT=mp4
# ;;
# esac
done
case ${SUCCESS} in
'true')
echo ${1} >> ${COMPLETE_DOWNLOADS}
;;
*)
echo ${1} >> ${INCOMPLETE_DOWNLOADS}
;;
esac
}
function runDownloadShow() {
touch ${COMPLETE_DOWNLOADS}
touch ${INCOMPLETE_DOWNLOADS}
LINES=$(cat ${DOWNLOAD_LIST} | wc -l | sed 's/ //g')
echo "Number of downloads ${LINES}"
COUNTER=0
while [ ${COUNTER} -lt ${LINES} ]; do
let COUNTER=COUNTER+1
CURRENT=$(sed "${COUNTER}!d" ${DOWNLOAD_LIST})
downloadShow "${CURRENT}"
done
echo
echo
echo "Completed Downloads:"
cat ${COMPLETE_DOWNLOADS} | sed 's/\(.*\) .*/\1/'
echo
echo
echo "Incomplete Downloads:"
cat ${INCOMPLETE_DOWNLOADS} | sed 's/\(.*\) .*/\1/'
mv ${INCOMPLETE_DOWNLOADS} ${DOWNLOAD_LIST}
read -p "Press enter to continue..."
}
function convertFiles() {
LINES=$(cat ${COMPLETE_DOWNLOADS} | wc -l | sed 's/ //g')
echo "Number of downloads ${LINES}"
COUNTER=0
while [ ${COUNTER} -lt ${LINES} ]; do
let COUNTER=COUNTER+1
CURRENT=$(sed "${COUNTER}!d" ${COMPLETE_DOWNLOADS})
FILENAME=$(echo ${1} | sed 's/\(.*\) .*/\1/')
SHOWPATH=$(echo ${1} | sed 's/.* //')
SHOWEXT=$(echo ${1} | sed 's/.*\.//g')
${FFMPEG} -i "${CURDIR}"/"${FILENAME}.${SHOWEXT}" -aspect 16:9 -acodec copy -vcodec copy "${CURDIR}"/FIXED_"${FILENAME}".avi
done
read -p "Press enter to continue..."
}
clear
echo "ABC iView Downloader by sge, converted to OSX by lightguard, updated by vipher"
echo "Version 7.0"
echo "This script simplifies the process of downloading streams off ABC iView."
echo
echo "NOTE THIS CAREFULLY: THIS SCRIPT CAN BE UNRELIABLE."
echo "WHEN IF FAILS, TRY AGAIN, OR PICK ANOTHER SHOW."
echo
echo "The creators provide no warranty for this script. It may stop working with no notice."
read -p "Press enter to continue..."
until [ 1 -lt 0 ]; do
clear
echo
echo "Please Select an Option"
echo "1. Add another show to the download list"
echo "2. View the download list"
echo "3. Clear the download list"
echo "4. Download the list (Attempts to retry ${MAXRETRIES} times)"
echo "5. View the completed download list"
echo "6. Convert all files in completed list"
echo "7. Exit"
read OPTION
case ${OPTION} in
1)
getShow
;;
2)
echo
cat ${DOWNLOAD_LIST}
read -p "Press enter to continue..."
;;
3)
rm ${DOWNLOAD_LIST}
rm ${COMPLETE_DOWNLOADS}
rm ${INCOMPLETE_DOWNLOADS}
;;
4)
runDownloadShow
;;
5)
echo
cat ${COMPLETE_DOWNLOADS}
read -p "Press enter to continue..."
;;
6)
convertFiles
;;
7)
exit
;;
esac
done