forked from mathieu-aubin/video-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.sh
793 lines (576 loc) · 25.7 KB
/
video.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
#!/bin/bash
# Video download script v4.0.77
# Created by Daniil Gentili (http://daniil.it)
# Video-dl - Video download programs
#
# Copyright 2016 Daniil Gentili (https://daniil.it)
# This file is part of video-dl.
# video-dl is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# video-dl is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
# You should have received a copy of the GNU General Public License along with the video-dl.
# If not, see <http://www.gnu.org/licenses/>.
#
# Changelog:
# v1 (and revisions): initial version.
# v2 (and revisions): added support for Rai Replay, support for multiple qualities, advanced video info and custom API server.
# v3 (and revisions): added support for Mediaset, Witty TV, La7, etc..
# v3.1 Included built in API engine, bug fixes
# v3.2 Added support for youtube and https
# v3.3 Fixed auto update and squashed some bugs.
# v3.3.1 Improved the auto update function and player choice
# v3.3.2 Squashed some other bugs, fixed download of 302 videos on Mac OS X (curl redirection).
echo "Video download script v4.0.77
Copyright (C) 2016 Daniil Gentili
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions; see https://github.com/danog/video-dl/raw/master/LICENSE."
lineclear() { echo -en "\r\033[K"; }
##### Tools detection and selection #####
which smooth.sh &>/dev/null && smoothsh=y || smoothsh=n
which ffmpeg &>/dev/null && ffmpeg=y || ffmpeg=n
which wget &>/dev/null && {
dl() {
wget "$1" -cO $2 $3
}
Q="-q"
} || {
dl() {
curl -L "$1" -o $2 $3
}
Q="-s"
}
##### Self updating section #####
ME=$(which $0 || echo $0)
# !!!!!! Comment the following line before editing the script or all changes will be overwritten !!!!!! #
echo -n "Self-updating script..." && dl http://daniilgentili.magix.net/video.sh $ME $Q 2>/dev/null;chmod 755 $ME 2>/dev/null; lineclear
##### Help section #####
help() {
echo "Created by Daniil Gentili (http://daniil.it)
Supported websites: $(dl http://api.daniil.it/?p=websites - $Q)
Usage:
$(basename $0) [ -qabp=player ] URL URL2 URL3 ...
$(basename $0) [ -qabfp=player ] URLS.txt URLS2.txt URLS3.txt ...
Options:
-q Quiet mode: useful for crontab jobs, automatically enables -a.
-a Automatic mode: automatically download the video in the maximum quality.
-b Use built-in API engine: requires additional programs and may not work properly on some systems but may be faster than the API server.
-f Read URL(s) from specified text file(s). If specified, you cannot provide URLs as arguments.
-p=player Play the video instead of downloading it using specified player, mplayer if none specified.
--help Show this extremely helpful message.
If the script doesn't behave like it should, update it by running this command
sudo apt-get update && sudo apt-get dist upgrade
If you installed it with apt or use this command
sudo video.sh
if you installed it manually.
"
exit
}
[ "$1" = "--help" ] && help
##### URL format detection #####
urlformatcheck() {
case $urlformat in
smooth\ streaming)
queue="$queue
`[ "$smoothsh" = "y" ] && echo "smooth.sh \\"$url\\" \\"$title.mkv\\"" || echo "echo \"Manifest URL: $url\""`
"
;;
apple\ streaming)
queue="$queue
`[ "$ffmpeg" = "y" ] && echo "ffmpeg -i \\"$url\\" -c copy \\"$title.mkv\\"" || echo "echo \"URL: $url\""`
"
;;
*)
queue="$queue
dl \"$url\" $title.$ext $WOPT
"
;;
esac
}
##### Internal API #####
internalapi() {
echo -n "Downloading latest version of the API engine..." && eval "$(dl http://daniil.magix.net/api.sh - $Q)" && lineclear && type api | grep -q replaytv || {
echo "Couldn't download the API engine, using built-in engine..."
# 1st part ends here
api() {
####################################################
####### Beginning of URL recognition section #######
####################################################
dl="$(echo "$1" | grep -q '^//' && echo "http:$1" || echo "$1")"
urltype="$(curl -w "%{url_effective}\n" -L -s -I -S "$dl" -o /dev/null | sed 's/^HTTP:\/\//http:\/\//g')"
echo "$urltype" | grep -qE '.*rai.it/.*|.*rai.tv/.*|.*rainews.it/.*' && ptype=rai
echo "$urltype" | grep -qE '.*raiplay.it/.*' && ptype=rai_play
# grep -qE 'http://www.*.rai..*/dl/RaiTV/programmi/media/.*|http://www.*.rai..*/dl/RaiTV/tematiche/.*|http://www.*.rai..*/ dl/.*PublishingBlock-.*|http://www.*.rai..*/dl/replaytv/replaytv.html.*|http://.*.rai.it/.*|http://www.rainews.it/dl/rainews/.*|https://www.*.rai..*/dl/ RaiTV/programmi/media/.*|https://www.*.rai..*/dl/RaiTV/tematiche/.*|https://www.*.rai..*/dl/.*PublishingBlock-.*|https://www.*.rai..*/dl/ replaytv/replaytv.html.*|https://.*.rai.it/.*|https://www.rainews.it/dl/rainews/.*' && ptype=rai
echo "$urltype" | grep -qE '.*mediaset.it/.*|http://www.video.mediaset.it/player/playerIFrame.*|https://www.video.mediaset.it/video/.*|https://www.video.mediaset.it/player/playerIFrame.*|tgcom24.mediaset.it/video/.*|http://mediaset.it/.*|https://mediaset.it/.*' && ptype=mediaset
echo "$urltype" | grep -qE 'http://.*wittytv.it/.*|https://.*wittytv.it/.*' && ptype=mediaset && witty=y
echo "$urltype" | grep -qE 'http://la7.it/.*|http://.*.la7.it/.*|http://la7.tv/.*|http://.*.la7.tv/.*|https://la7.it/.*|https://.*.la7.it/.*|https://la7.tv/.*| https://.*.la7.tv/.*' && ptype=lasette
echo "$urltype" | grep -qE '.*dplay.com/.*|.*dmax.it.*|.*realtimetv.it.*|.*giallotv.it.*|.*focustv.it.*|.*k2tv.it.*|.*frisbeetv.it.*' && ptype=dplay
echo "$urltype" | grep -qE '.*deejay.it.*' && ptype=deejay
echo "$urltype" | grep -qE '.*eurosport.com.*' && ptype=eurosport
echo "$urltype" | grep -qE '.*wat.tv.*' && ptype=wat
[ "$ptype" = "" ] && ptype="common"
dl="$urltype"
[ "$ptype" = "rai" ] && echo "$1" | grep -q '#' && dl="$1"
##############################################################################
####### End of URL recognition section, beginning of Functions section #######
##############################################################################
# Declare javascript variable
var() {
eval $(echo "$*" | sed 's/var//g;s/\s=\s/=/g')
}
# Get video information
getsize() {
minfo="$(timeout -skill 10s mediainfo "$a")"
d=$(echo "$a" | sed "s/.*\.//;s/[^a-z|0-9].*//")
b=$(echo "$minfo" | sed '/File size/!d;s/.*:\s//g')
c=$(echo "$minfo" | sed '/Width\|Height/!d;s/.*:\s//g;s/\spixels//g;s/\s//g;/^\s*$/d' | tr -s "\n" x | sed 's/x$//g')
[ "$b" = "" ] && b="Unkown size"
[ "$c" = "" ] && c="Unkown quality"
info="($d, $b, $c)"
#sed 's/\
#//g;s/^, //g;s/, B,/, Unkown size,/g;s/, ,/,/g;s/^B,//g;s/, $//;s/ $//g'))"
minfo=
}
# Check if URL exists and remove copies of the same URL
checkurl() {
tbase="$(echo "$base" | sed 's/ /%20/g;s/%20http:\/\//\
http:\/\//g;s/%20https:\/\//\
https:\/\//g;s/%20$//g;s/ /\
/g' | awk '!x[$0]++')"
base=
for u in $tbase;do echo "$u" | grep -q 'rmtp://\|mms://' && {
base="$base
$u"
} || {
wget -S --tries=3 --spider "$u" 2>&1 | grep -q '200 OK\|206 Partial' && base="$base
$u"
}; done
}
# Nicely format input
formatoutput() {
case $ptype in
rai*)
two="$(echo "$unformatted" | grep '.*_250.mp4')"
four="$(echo "$unformatted" | grep '.*_400.mp4')"
six="$(echo "$unformatted" | grep '.*_600.mp4')"
seven="$(echo "$unformatted" | grep '.*_700.mp4')"
eight="$(echo "$unformatted" | grep '.*_800.mp4')"
twelve="$(echo "$unformatted" | grep '.*_1200.mp4')"
fifteen="$(echo "$unformatted" | grep '.*_1500.mp4')"
eighteen="$(echo "$unformatted" | grep '.*_1800.mp4')"
twentyfour="$(echo "$unformatted" | grep '.*_2400.mp4')"
thirtytwo="$(echo "$unformatted" | grep '.*_3200.mp4')"
fourthousand="$(echo "$unformatted" | grep '.*_4000.mp4')"
normal="$(echo "$unformatted" | sed '/.*_250\.mp4/d;/.*_400\.mp4/d;/.*_600\.mp4/d;/.*_700\.mp4/d;/.*_800\.mp4/d;/.*_1200\.mp4/d;/.*_1500\.mp4/d;/.*_1800\.mp4/d;/.*_2400\.mp4/d;/.*_3200\.mp4/d;/.*_4000\.mp4/d')"
;;
mediaset)
mp4="$(echo "$unformatted" | grep ".mp4")"
smooth="$(echo "$unformatted" | sed '/pl[)]/d;/est/!d')"
apple="$(echo "$unformatted" | grep "pl)")"
wmv="$(echo "$unformatted" | grep ".wmv")"
flv="$(echo "$unformatted" | grep ".flv")"
f4v="$(echo "$unformatted" | grep ".f4v")"
;;
lasette)
lamp4="$(echo "$unformatted" | sed '/master/d;/manifest/d;/\.mp4/!d')"
;;
*)
common="$unformatted"
esac
formats="$(
[ "$common" != "" ] && for a in $common; do getsize
# info="$(echo "$info" | sed 's/[(]//;s/[)]//')"
echo "$info $a";done
[ "$lamp4" != "" ] && for a in $lamp4; do getsize
echo "$info $a";done
[ "$normal" != "" ] && for a in $normal; do getsize
echo "$info $a";done
[ "$fourthousand" != "" ] && for a in $fourthousand; do getsize
echo "Full HD quality $info $a";done
[ "$thirtytwo" != "" ] && for a in $thirtytwo; do getsize
echo "HD quality $info $a";done
[ "$twentyfour" != "" ] && for a in $twentyfour; do getsize
echo "Super-high quality $info $a";done
[ "$eighteen" != "" ] && for a in $eighteen; do getsize
echo "High quality $info $a";done
[ "$fifteen" != "" ] && for a in $fifteen; do getsize
echo "Medium-high quality $info $a";done
[ "$twelve" != "" ] && for a in $twelve; do getsize
echo "Medium quality $info $a";done
[ "$seven" != "" ] && for a in $seven; do getsize
echo "Medium-medium quality $info $a";done
[ "$eight" != "" ] && for a in $eight; do getsize
echo "Medium-low quality $info $a";done
[ "$six" != "" ] && for a in $six; do getsize
echo "Low quality $info $a";done
[ "$four" != "" ] && for a in $four; do getsize
echo "Minimum quality $info $a";done
[ "$two" != "" ] && for a in $two; do getsize
echo "Lowest Minimum quality $info $a";done
[ "$mp4" != "" ] && for a in $mp4; do getsize
echo "Medium-high quality $info $a";done
[ "$wmv" != "" ] && for a in $wmv; do getsize
echo "Low quality $info $a";done
[ "$flv" != "" ] && for a in $flv; do getsize
echo "Low quality $info $a";done
[ "$f4v" != "" ] && for a in $f4v; do getsize
echo "Low quality $info $a";done
[ "$smooth" != "" ] && for a in $smooth; do echo "High quality (smooth streaming, smooth) $a";done
[ "$apple" != "" ] && for a in $apple; do echo "Medium-low quality (apple streaming, pseudo-m3u8, m3u8) $a";done
)"
formats="$(echo "$formats" | awk '!x[$0]++' | awk '{print $(NF-1), $0}' | sort -gr | cut -d' ' -f2- | sed '/^\s*$/d')"
videoTitolo=$(echo "$videoTitolo" | tr -d '\015' | tr -s "\n" " ")
title="${videoTitolo//[^a-zA-Z0-9 ]/}"
title=$(echo $title | sed 's/^\s*//g;s/\s*$//g')
title=${title// /_}
}
###########################################################################################
################## End of formatting section, beginning of Rai section ##################
###########################################################################################
rai() {
saferai="$1"
# Store the page in a variable
file=$(wget "$saferai" -qQ 50000000 -O -)
# Rai replay or normal rai website choice
echo "$1" | grep -q 'http://www.*.rai..*/dl/replaytv/replaytv.html.*' && replay "$saferai" || rai_normal "$saferai"
links="$videoURL_M3U8 $videoURL_MP4 $videoURL_H264 $videoURL_WMV $videoURL $replay"
links="$(echo "$links" | sed '/^\s*$/d')"
videoTitolo="$(echo -en "$videoTitolo")"
[ "$links" = "" ] && replay "$saferai"
links="$videoURL_M3U8 $videoURL_MP4 $videoURL_H264 $videoURL_WMV $videoURL $replay"
[ "$videoTitolo" = "" ] && videoTitolo=$(echo "$file" | tr '\n' ' ' | sed 's/.*<title>//;s/<\/title>.*//;s/^ //')
# Resolve relinkers
relinker_rai "$links"
}
# Rai website
rai_normal() {
echo "$1" | grep -q "rainews.it" && {
bsp=$(echo "$file" | sed '/parentPage.bsp /!d;'"s/.* '//;s/'.*//")
jsons=$(echo "$file" | sed '/"url" : "http/!d;s/.* : "//;s/".*//')
json=$(curl -s $jsons)
} || {
# iframe check
echo "$file" | grep -q videoURL || {
urls="http://www.rai.it/dl/RaiTV/programmi/media/"$(echo "$file" | sed '/content="ContentItem/!d;s/.*content="//g;s/".*//g')".html http://www.rai.tv$(echo "$file" | grep -A1 '<div id="idFramePlayer">' | sed '/\<iframe/!d;s/.*src="//g;s/?.*//g') $(echo "$file" | sed '/drawMediaRaiTV/!d;s/.*http/http/g;s/'"'"'.*//g')"
file="$(wget -Q 50000000 -qO- $urls)"
}
}
# read and declare videoURL and videoTitolo variables from javascript in page
$(echo "$file" | grep 'videoTitolo\|videoURL')
}
# raplay.it function
rai_play() {
saferai="$1"
# Store the page in a variable
file=$(wget "$saferai" -qQ 50000000 -O -)
links=$(echo "$file" | sed '/data-video-url=/!d;s/.*data-video-url="//g;s/".*//g')
links="$(echo "$links" | sed '/^\s*$/d')"
videoTitolo=$(echo "$file" |sed '/<title>/!d;s/^.*<title>//;s/<\/title>.*//g;s/^ //' | head -1)
relinker_rai "$links"
}
# Rai replay function
replay() {
# Get the video id
v=$(echo "$1" | sed 's/.*v=//;s/\&.*//')
# Get the day
day=$(echo "$1" | sed 's/.*day=//;s/\&.*//;s/-/_/g;/http/d')
[ "$day" = "" ] && day=$(echo "$1" | sed 's/.*vd=//;s/\&.*//;s/-/_/g')
ch=$(echo "$1" | sed 's/.*ch=//;s/\&.*//;/http/d')
[ "$ch" = "" ] && ch=$(echo "$1" | sed 's/.*vc=//;s/\&.*//')
# Get the channel
case $ch in
1)
ch=RaiUno
;;
2)
ch=RaiDue
;;
3)
ch=RaiTre
;;
31)
ch=RaiCinque
;;
32)
ch=RaiPremium
;;
23)
ch=RaiGulp
;;
38)
ch=RaiYoyo
;;
esac
# Get the json
tmpjson="$(wget http://www.rai.it/dl/portale/html/palinsesti/replaytv/static/"$ch"_$day.html -qO- | tr '\n' ' ')"
# Keep only section with correct video id and make it grepable
json="$(echo "$tmpjson" | sed 's/'$v'.*//g;s/.*[{]//g;s/\,/\
/g')"
# Get the relinkers
replay=$(echo "$json" | sed '/mediapolis/!d;s/.*\"://g;s/\"//g;s/^ *//g')
# Get the title
videoTitolo=$(echo "$json" | sed '/\"t\":/!d;s/.*\"://;s/\"//g;s/^ *//g')
}
# Relinker function
relinker_rai() {
# Resolve relinker
for f in $(echo $* | awk '{ while(++i<=NF) printf (!a[$i]++) ? $i FS : ""; i=split("",a); print "" }'); do
dl=$(echo "$f" | grep -q '^//' && echo "http:$f" || echo "$f")
base="$(curl "$dl" | sed 's/ /%20/g')" && checkurl
# 1st method
url="$(timeout -skill 5s wget -qO- "$dl&output=25")
$(timeout -skill 5s wget "$dl&output=43" -U="" -q -O -)"
url="$(echo "$url" | sed 's/ /%20/g;s/[>]/\
/g;s/[<]/\
/g')"
[ "$url" != "" ] && base="$(echo "$url" | sed '/\.mp4\|\.wmv\|\.mov/!d;s/mms/http/g;/http/!d;s/\.mp4.*/\.mp4/;s/\.wmv.*/\.wmv/;s/\.mov.*/\.mov/')" && checkurl
# 2nd method
[ "$base" = "" ] && {
base=$(curl -w "%{url_effective}\n" -L -s -I -S "$dl" -A "" -o /dev/null) && checkurl
}
[ "$base" = "" ] && {
base="$(for f in $(echo "$url" | grep ","); do number="$(echo "$f" | sed 's/http\:\/\///g;s/\/.*//;s/[^0-9]//g;s/^.*\(.\{1\}\)$/\1/')"; echo "$f" | sed 's/.*Italy/Italy/;s/^/http\:\/\/creativemedia'$number'\.rai\.it\//;s/,/{/;s/,\./}\./;s/\.mp4.*/\.mp4/'; done)"
base="$(eval echo "$base")" && checkurl
}
# 3rd and 4th method
[ "$base" = "" ] && {
url="$(wget "$dl&output=4" -q -O -)"
[ "$url" != "" ] && echo "$url" | grep -q 'creativemedia\|wms' && base="$url" && checkurl
}
TMPURLS="$TMPURLS
$base"
done
# Remove copies of the same url
base="$(echo "$TMPURLS" | sort | awk '!x[$0]++')"
# Find all qualities in every video
tbase=
loop="_250 _400 _600 _700 _800 _1200 _1500 _1800 _2400 _3200 _4000"
for t in $loop \ ; do [ "$t" = " " ] && t=; for i in $loop; do tbase="$tbase
${base//$t\.mp4/$i\.mp4}"; tbase="$(echo "$tbase" | grep -Ev "_([0-9]{3,4})_([0-9]{3,4})\.mp4" | awk '!seen[$0]++')"; done;done
base="$tbase"
checkurl
unformatted="$base"
formatoutput
}
###########################################################################################
##################### End of Rai section, beginning of Lasette section ####################
###########################################################################################
lasette() {
# Store the page in a variable
page="$(wget "$1" -Q 50000000 -q -O -)"
# Get the javascript with the URLs
unformatted="$(wget -q -O - $(echo "$page" | sed '/starter/!d;s/.*src\=\"//;s/\".*//') | sed '/src:.*\|src_.*/!d;s/.*\: \"//;s/\".*//')"
# Get the title
videoTitolo="$(echo "$page" | tr '\n' ' ' | sed 's/.*<title>//;s/<\/title>.*//;s/^ //')"
formatoutput
}
###########################################################################################
################## End of Lasette section, beginning of Mediaset section ##################
###########################################################################################
mediaset() {
# Store the page in a variable
page=$(wget "$1" -Q 50000000 -q -O -)
# Witty tv recongition
[ "$witty" = "y" ] && {
# Get the video id
id=$(echo "$page" | sed '/[<]iframe id=\"playeriframe\" src=\"[^\/]*\/\/www.video.mediaset.it\/player\/playerIFrame.shtml?id\=/!d;s/.*\<iframe id=\"playeriframe\" src=\"[^\/]*\/\/www.video.mediaset.it\/player\/playerIFrame.shtml?id\=//;s/\&.*//')
# Get the title
videoTitolo=$(echo "$page" | sed '/[<]meta content=\".*\" property=\".*title\"\/[>]/!d;s/\" property=\".*title\".*//g;s/.*\<meta content\=\"//;s/\".*//g')
} || {
$(echo "$page" | grep "var videoMetadataId")
id="$videoMetadataId"
videoTitolo=$(echo "$page" | sed '/[<]meta content=\".*\" property=\".*title\"\/[>]/!d;s/\" property=\".*title\".*//g;s/.*\<meta content\=\"//;s/\".*//g')
}
# Get the video URLs using the video id
unformatted="$(wget "http://cdnselector.xuniplay.fdnames.com/GetCDN.aspx?streamid=$id" -O - -q -U="" | sed 's/</\
/g' | grep http | sed 's/.*http/http/g;s/\".*//g')"
formatoutput
}
###########################################################################################
##################### End of Mediaset section, beginning of dplay section ################
###########################################################################################
dplay() {
id=$(curl -Ls "$dl" | sed '/data-video-id\=\"/!d;s/.*data-video-id\=\"//g;s/\".*//g')
[ "$id" = "" ] && {
orig=$(curl -Ls "$dl" | sed '/dplay.com/!d;s/.*href="http/http/g;s/".*//g') &&
id=$(curl -Ls "$orig" | sed '/data-video-id\=\"/!d;s/.*data-video-id\=\"//g;s/\".*//g')
}
json="$(curl -Ls http://it.dplay.com/api/v2/ajax/videos?video_id=$id)"
unformatted="$(echo "$json" | sed 's/\"\:\"/\
/g' | sed '/mp4/!d;s/\".*//g;s/\\//g')"
videoTitolo=$(echo "$json" | sed 's/.*","title":"//g;s/".*//g')
formatoutput
}
###########################################################################################
##################### End of dplay section, beginning of deejay section ################
###########################################################################################
deejay() {
file="$(curl -sL "$1")"
unformatted="$(echo "$file" | sed '/addParam[(]'"'"'format'"'"', /!d;s/.*'"'"'http/http/g;s/'"'"'.*//g')"
videoTitolo=$(echo $file | sed 's/.*<title>//;s/<\/title>.*//;s/^ //')
formatoutput
}
###########################################################################################
##################### End of deejay section, beginning of eurosport section ################
###########################################################################################
eurosport() {
file="$(curl -sL "$1")"
frame="$(echo $file | sed 's/.*src=\"http:\/\/www.wat.tv\/embedframe/http:\/\/www.wat.tv\/embedframe/g;s/\".*//g')"
videoTitolo=$(echo $file | sed 's/.*<title>//;s/<\/title>.*//;s/^ //')
wat_base "$frame"
formatoutput
}
###########################################################################################
##################### End of eurosport section, beginning of wat section ################
###########################################################################################
wat_base() {
file="$(curl -sL "$1")"
unformatted="$(echo "$file" | sed 's/,/\
/g' | sed '/PlayerLite.swf?videoId=/!d;s/.*\/\/www.wat.tv\/images/\/\/wat.tv\/images/g;s/\".*//g' | awk '!x[$0]++')"
}
wat() {
wat_base "$1"
videoTitolo=$(echo $file | sed 's/.*<title>//;s/<\/title>.*//;s/^ //')
formatoutput
}
###########################################################################################
##################### End of wat section, beginning of common section ################
common() {
# Store the page in a variable
page="$(wget -q -O - "$1")"
# Get the video URLs
base="$(echo "$page" | egrep '\.mp4|\.mkv|\.flv|\.f4v|\.wmv|\.mov|\.3gp|\.avi|\.m4v|\.mpg|\.mpe|\.mpeg' | sed 's/.*http:\/\//http:\/\//;s/\".*//' | sed "s/'.*//" | sed 's/.mp4.*/.mp4/g;s/.mkv.*/.mkv/g;s/.flv.*/.flv/g;s/.f4v.*/.f4v/g;s/.wmv.*/.wmv/g;s/.mov.*/.mov/g;s/.3gp.*/.3gp/g;s/.avi.*/.avi/g;s/.m4v.*/.m4v/g;s/.mpg.*/.mpg/g;s/.mpe.*/.mpe/g;s/.mpeg.*/.mpeg/g' | awk '!x[$0]++')"
checkurl
[ "$base" = "" ] && continue
videoTitolo="$(echo $page | sed 's/.*<title>//;s/<\/title>.*//;s/^ //')"
title="${videoTitolo//[^a-zA-Z0-9 ]/}"
title=${title// /_}
unformatted="$base"
formatoutput
}
# OK, here's the problem: The following function uses youtube-dl to get the download info, but offering the functionality of youtube-dl using an http api is one thing, while using the above mentioned program when the user can already use it is another thing. Comment the auto update line and change common_yt_dl to common if you still want to use youtube-dl trough this script.
common_yt_dl() {
tmpjson="$(youtube-dl -J "$1")"
videoTitolo=$(echo "$tmpjson" | sed 's/.*\"title\": \"//g;s/\".*//g')
json="$(echo "$tmpjson" | sed 's/.*requested_formats//g;s/, [{]/\
/g')"
while read -r line; do
l=$(echo "$line" | sed 's/,/\
/g')
for f in format url ext; do
temp="$(echo "$l" | sed '/"'$f'":/!d;s/"'$f'"\: "//g;s/"$//g;s/^ //g;s/^.* - //g')"
eval $f=\""$temp"\"
done
url=$(echo "$url" | tr -s "\n" " " | sed 's/\s.*//')
format=$(echo "$format" | awk '!x[$0]++' | tr -s "\n" " ")
ext=$(echo "$ext" | tr -s "\n" " " | sed 's/\s.*//')
[ "$url" != "" ] && {
size=
timeout -skill 3s wget -S --spider "$url" &>/dev/null && size=", $(wget -S --spider "$url" 2>&1 | sed '/^Length\|^Lunghezza/!d;s/.*(//;s/).*//')B" || size=", Unkown size"
format=$(echo "$format" | sed 's/[(]//g;s/[)]//g')
echo "$url" | grep -q "://" && formats="$format ($ext$size) $url
$formats"
}
done <<< "$json"
# Get the title
title="${videoTitolo//[^a-zA-Z0-9 ]/}"
title=${title// /_}
}
error() {
videoTitolo=$(basename "$dl")
a="$dl"
getsize
formats="$info $dl"
[ "$formats" = "" ] && exit || echo "$videoTitolo
video $formats"
exit
}
size="$(wget -S --spider "$dl" 2>&1 | sed '/^Length\|^Lunghezza/!d;s/.*[(]//g;s/[)].*//g')"
echo "$size" | grep -q G && error
###########################################################################################
##################### End of Common section, beginning of database section ################
$ptype "$dl"
[ "$formats" = "" ] && continue || echo "$title $videoTitolo
$formats"
}
# 2nd part starts here
}
}
##### Default API #####
[ "$(dl http://api.daniil.it/?p=websites - $Q)" != "" ] && api() { sane="$(echo "$1" | sed 's:%:%25:g;s: :%20:g;s:<:%3C:g;s:>:%3E:g;s:#:%23:g;s:{:%7B:g;s:}:%7D:g;s:|:%7C:g;s:\\:%5C:g;s:\^:%5E:g;s:~:%7E:g;s:\[:%5B:g;s:\]:%5D:g;s:`:%60:g;s:;:%3B:g;s:/:%2F:g;s:?:%3F:g;s^:^%3A^g;s:@:%40:g;s:=:%3D:g;s:&:%26:g;s:\$:%24:g;s:\!:%21:g;s:\*:%2A:g')"; dl "http://api.daniil.it/?url=$sane" - $Q; } || internalapi
##### Option detection #####
while getopts qabfp: FLAG; do
case "$FLAG" in
b)
internalapi
;;
q)
WOPT="$Q" && A=y
;;
a)
A=y
;;
f)
F=y
;;
p)
{
play=y
tmplayer="$(echo $OPTARG | sed 's/=//g')"
[ "$tmplayer" != "" ] && which "$tmplayer" &>/dev/null && player="$tmplayer" || player="mplayer"
}
;;
\?)
echo "Invalid option: -$OPTARG" >&2
esac
done
shift $((OPTIND-1))
##### Player choice #####
[ "$play" = y ] && dlvideo() {
queue="$queue
$player $url
"
} || dlvideo() {
urlformatcheck
}
[ "$*" = "" ] && echo "No url specified." && help
[ "$F" = "y" ] && URL="$(cat "$*")" || URL="$*"
##### To be automatic or to be selected by the user, that is the question. #####
[ "$A" = "y" ] && dlcmd() {
url="$(echo "$api" | sed '1!d;s/.*\s//')"
ext=$(echo "$api" | sed '1!d;s/.*[(]//g;s/, .*//g')
dlvideo
} || {
echo "Video(s) info:" &&
dlcmd() {
videoTitolo=$(echo "$titles" | sed 's/^\S*\s//g;s/è/e/g;s/é/e/g;s/ì/i/g;s/í/i/g;s/ù/u/g;s/ú/u/g')
max="$(echo "$api" | sed -n '$p' | grep -Eo '^[^ ]+')"
echo "Title: $videoTitolo
$(echo "$api" | sed 's/\S*$//')
"
until [ "$l" -le "$max" ] && [ "$l" -gt 0 ] ; do echo -n "What quality do you whish to download (number, enter q to skip this video and enter to download the maximum quality)? "; read l; [ "$l" = "q" ] && break;[ "$l" = "" ] && {
url="$(echo "$api" | sed '1!d;s/.*\s//')"
ext=$(echo "$api" | sed '1!d;s/.*[(]//g;s/, .*//g')
dlvideo
break
};done 2>/dev/null
[ "$l" = "q" ] || [ "$l" = "" ] && continue
selection=$(echo "$api" | sed "$l!d")
urlformat=$(echo "$selection" | sed 's/http:\/\/.*//;s/https:\/\/.*//g;s/.*[(]//;s/[)].*//')
url=$(echo "$selection" | sed 's/.*\s//g')
ext=$(echo "$selection" | sed 's/.*[(]//g;s/, .*//g')
dlvideo
}
}
for u in $URL; do
echo -n "Getting video info for $u..."
api="$(api "$u" | sed '/^\s*$/d')"
[ "$api" = "" ] && { echo "Couldn't download $u." && continue; } || lineclear
titles=$(echo "$api" | sed -n 1p)
api=$(echo "$api" | sed '1d' | sed = | sed 'N;s/\n/ /')
title=$(echo "$titles" | sed 's/\s.*//g')
dlcmd
done
[ "$queue" = "" ] && { echo "ERROR: download list is empty."; exit 1; }
[ "$play" != "y" ] && { echo "Downloading videos..." && eval "$queue" && echo "All downloads completed successfully." || echo "An error occurred";exit 1; }
[ "$play" = "y" ] && { eval $queue || echo "An error occurred";exit 1; }
exit $?