-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenTVOnDemand.sh
1941 lines (1857 loc) · 72.2 KB
/
OpenTVOnDemand.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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
# OpenTVOnDemand
#
# Copyright (c) 2014 Cai, Zhi-Wei. All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#-------------------- Configurations --------------------
# OS Setting. [Darwin/Linux/CYGWIN_NT-5.1]
# Currently, only Mac OS X(Darwin) and Lunix are supported.
# Default(Auto detect): "$(uname -s)"
readonly CONST_OS="$(uname -s)"
# Debug Mode. [0|1]
# If 1 and Debug Output Path is not empty, func_log will output to debug output path.
# Default: 0
readonly CONST_DEBUG_MODE=0
# Debug Output Path. (Absolute Path Only.)
# If Debug Mode is 1 and this is not empty, func_log will output to debug output path.
readonly CONST_DEBUG_PATH="${HOME}/OpenTVOnDemand.log"
# Server Mode. [0|1]
# Server will upload files to FTP instead of asking for playback.
# Default: 0
readonly CONST_IS_SERVER=0
# FTP setting.
# FTP server used in Server Mode.
readonly CONST_REMOTE_FTP_HOST="my.host.com"
readonly CONST_REMOTE_FTP_PORT="21"
readonly CONST_REMOTE_FTP_USER="user"
readonly CONST_REMOTE_FTP_PASS="password"
readonly CONST_REMOTE_FTP_PATH="/"
# VPN Name.
# For Darwin only. The VPN connection names to use to bypass the geo lockdown.
readonly CONST_VPN_NAME_US="My VPN Connection - US"
readonly CONST_VPN_NAME_GB="My VPN Connection - UK"
readonly CONST_VPN_NAME_CA="My VPN Connection - CA"
readonly CONST_VPN_NAME_AU="My VPN Connection - AU"
# HTTP Proxy Sever.
# e.g. 1.2.3.4:3128. Leave Blank to ignore.
# Default:
readonly CONST_PROXY=
# Search Results.
# The max number of results to display in search. Greater the number will significantly increase the loading time.
# Default: 8
readonly CONST_SEARCH_MAX=8
# CURL Threads Per Session.
# The max number of threads CURL uses when catupring streams. > 10 might cause problem.
# Default: 5
readonly CONST_FETCH_THREADS=5
# Working Path. (Without Ending Slash!)
# Temp storing location path.
# Default: "/tmp"
readonly CONST_WORK_PATH="/tmp"
# Download Path. (Without Ending Slash!)
# Location for sucessful downloads.
# Default: "${HOME}/Movies"
readonly CONST_STORE_PATH="${HOME}/Movies"
# User-Agent.
# Use only in some cases.
# Default: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
readonly CONST_CURL_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
#-------------------- Configurations --------------------
# DO NOT TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!!!
# DO NOT TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!!!
# DO NOT TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!!!
# DO NOT TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!!!
# DO NOT TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!!!
#-------------------- Consts --------------------
# Job control.
set -m
# Window Size.
readonly originalColumns=$(tput cols)
readonly originalLines=$(tput lines)
printf "\033[8;40;120t"
# Timezone.
readonly timezone=$(date +%Z)
if [ "${CONST_OS}" == "Darwin" ]; then
readonly CONST_DATE_BIN="gdate" # OS X
else
readonly CONST_DATE_BIN="date" # Linux
fi
# Colors.
readonly COLOR_NONE="\033[m"
readonly COLOR_RED="\033[0;32;31m"
readonly COLOR_LIGHT_RED="\033[1;31m"
readonly COLOR_GREEN="\033[0;32;32m"
readonly COLOR_LIGHT_GREEN="\033[1;32m"
readonly COLOR_BLUE="\033[0;32;34m"
readonly COLOR_LIGHT_BLUE="\033[1;34m"
readonly COLOR_DARY_GRAY="\033[1;30m"
readonly COLOR_CYAN="\033[0;36m"
readonly COLOR_LIGHT_CYAN="\033[1;36m"
readonly COLOR_PURPLE="\033[0;35m"
readonly COLOR_LIGHT_PURPLE="\033[1;35m"
readonly COLOR_BROWN="\033[0;33m"
readonly COLOR_YELLOW="\033[1;33m"
readonly COLOR_LIGHT_GRAY="\033[0;37m"
readonly COLOR_WHITE="\033[1;37m"
readonly COLOR_BG_RED="\033[41m"
readonly COLOR_BG_DARY_GRAY="\033[40m"
readonly COLOR_BG_LIGHT_CYAN="\033[46m"
readonly COLOR_BG_LIGHT_PURPLE="\033[1;45m"
readonly CURSOR_HIDE="\033[?25l"
readonly CURSOR_SHOW="\033[?25h"
readonly TEXT_BLINK="\033[5m"
readonly TEXT_UNDERLINE="\033[4m"
readonly TEXT_HIGHLIGHT="\033[1m"
readonly TEXT_PADDING=' '
readonly TABS="\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
readonly BACKSPACES="\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
# Consts.
appversion="v0.1"
appname="OpenTVOnDemand"
applogo="
${TABS:0:$((6*2))}${COLOR_LIGHT_RED}
${TABS:0:$((6*2))} ${COLOR_DARY_GRAY}|${COLOR_LIGHT_RED}\_/${COLOR_DARY_GRAY}|,,${COLOR_LIGHT_RED}___${COLOR_BROWN}__,${COLOR_BROWN}~${COLOR_WHITE}~${COLOR_DARY_GRAY}\`${COLOR_LIGHT_RED}
${TABS:0:$((6*2))} (${TEXT_BLINK}${COLOR_LIGHT_BLUE}.${COLOR_NONE}${COLOR_DARY_GRAY}\"${TEXT_BLINK}${COLOR_LIGHT_BLUE}.${COLOR_NONE}${COLOR_LIGHT_RED})${COLOR_DARY_GRAY}~~${COLOR_LIGHT_RED} ${COLOR_BROWN})${COLOR_LIGHT_RED}\`${COLOR_BROWN}~${COLOR_WHITE}}${COLOR_DARY_GRAY}}${COLOR_LIGHT_RED}
${TABS:0:$((6*2))} ${COLOR_DARY_GRAY}\./${COLOR_LIGHT_RED}\ /${COLOR_WHITE}--${COLOR_BROWN}-${COLOR_DARY_GRAY}~${COLOR_LIGHT_RED}\\\ ${COLOR_BROWN}~${COLOR_WHITE}}${COLOR_DARY_GRAY}}${COLOR_LIGHT_RED}
${TABS:0:$((6*2))} ${COLOR_WHITE}_${COLOR_BROWN}// ${COLOR_WHITE}_${COLOR_BROWN}// ${COLOR_WHITE}~${COLOR_DARY_GRAY}}${COLOR_LIGHT_RED}
${TABS:0:$((6*2))} ${COLOR_NONE}"
banner="$applogo\n${TABS:0:$((5*2))} [${COLOR_BG_RED} $appname - $appversion ${COLOR_NONE}]\n"
function func_uuidgen () {
uuid=$(uuidgen | rev | cut -f 1 -d "-" | tr [:upper:] [:lower:])
}
function func_log () {
if [[ "${CONST_DEBUG_MODE}" -eq 1 ]] && [[ "${#CONST_DEBUG_PATH}" -gt 0 ]]; then
touch "${CONST_DEBUG_PATH}" 2>/dev/null
echo "[$($CONST_DATE_BIN +"%Y-%m-%d %I:%M %p")] $1" | cat - "${CONST_DEBUG_PATH}" > temp && mv temp "${CONST_DEBUG_PATH}" 2>/dev/null
fi
}
function func_notification () {
if [ "${CONST_OS}" == "Darwin" ]; then
local sound=
if [[ "$3" -eq 1 ]]; then
sound="-sound default"
fi
terminal-notifier -group "tvondemand-notification-$uuid" -title "${appname}" -subtitle "$2" -message "$1" -activate 'com.apple.Terminal' -sender 'com.apple.Terminal' $sound >/dev/null 2>&1
fi
}
function func_depandency () {
printf "\n${TABS:0:$((4*2))}${COLOR_RED}* Checking depandency...${COLOR_NONE}\n\n"
local allfine=0
while [[ "$allfine" -ne 1 ]]; do
func_banner
printf "\n"
if [ "${CONST_OS}" == "Darwin" ] && [ "$(which brew)" == "" ]; then
printf "${TABS:0:$((4*2))}${COLOR_RED}* Installing \"Homebrew\"...${COLOR_NONE}\n\n"
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew doctor
elif [ "${CONST_OS}" == "Darwin" ] && [ "$(which gdate)" == "" ]; then
printf "${TABS:0:$((4*2))}${COLOR_RED}* Installing \"GNU Core Utilities\"...${COLOR_NONE}\n\n"
brew install coreutils
elif [ "$(which rtmpdump)" == "" ]; then
printf "${TABS:0:$((4*2))}${COLOR_RED}* Installing \"RTMPDump\"...${COLOR_NONE}\n\n"
if [ "${CONST_OS}" == "Darwin" ]; then
brew install rtmpdump
else
sudo apt-get install rtmpdump
fi
elif [ "$(which ffmpeg)" == "" ]; then
printf "${TABS:0:$((4*2))}${COLOR_RED}* Installing \"FFmpeg\"...${COLOR_NONE}\n\n"
if [ "${CONST_OS}" == "Darwin" ]; then
brew install ffmpeg
else
sudo apt-get install ffmpeg
fi
elif [ "$(which parallel)" == "" ]; then
printf "${TABS:0:$((4*2))}${COLOR_RED}* Installing \"GNU parallel\"...${COLOR_NONE}\n\n"
if [ "${CONST_OS}" == "Darwin" ]; then
brew install parallel
else
sudo apt-get install parallel
fi
elif [ "$(which jsawk)" == "" ]; then
printf "${TABS:0:$((4*2))}${COLOR_RED}* Installing \"jsawk\"...${COLOR_NONE}\n\n"
if [ "${CONST_OS}" == "Darwin" ]; then
brew reinstall readline --force
brew install jsawk
else
wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
tar -zxvf js-1.7.0.tar.gz
cd js/src
make BUILD_OPT=1 -f Makefile.ref
make BUILD_OPT=1 JS_DIST=/usr/local -f Makefile.ref export
cd ..
cd ..
rm -rf js
curl -L http://github.com/micha/jsawk/raw/master/jsawk > jsawk
chmod 755 jsawk
mv jsawk /usr/local/bin/
fi
elif [ "${CONST_OS}" == "Darwin" ] && [ "$(which terminal-notifier)" == "" ]; then
if [ ! -f "/Applications/Xcode.app" ]; then
printf "${TABS:0:$((4*2))}${COLOR_RED}* Terminal-Notifier requires Xcode in order to build.\n\n${TABS:0:$((4*2))} However it's not a must if you don't want the notification feature.${COLOR_NONE}"
sleep 3
allfine=1
else
printf "${TABS:0:$((4*2))}${COLOR_RED}* Installing \"Terminal-Notifier\"...${COLOR_NONE}\n\n"
brew install terminal-notifier
fi
else
allfine=1
fi
done
}
function func_theplatform_sig () {
local t=$(($($CONST_DATE_BIN +"%s") + 600))
local u=$(printf "$1" | xxd -ps)
local h=$(printf "00%0.2x%s" "$t" "$u" | perl -pe 's/([0-9a-f]{2})/chr hex $1/gie' | openssl dgst -sha1 -hmac "$2")
local s=$(printf "$3" | xxd -ps)
sig=$(printf "00%0.2x%s%s" "$t" "$h" "$s")
}
function func_initiate () {
CURRENT_DIR=$(pwd)
WORKING_DIR="${CONST_WORK_PATH}/_tvr_$uuid"
mkdir "${WORKING_DIR}"
cd "${WORKING_DIR}"
base64 -D > "_t_$uuid" <<-_DECRYPT
IyBVc2FnZTogcHl0aG9uIHR0MnNydC5weSBzb3VyY2UueG1sIG91dHB1dC5zcnQKCmZyb20geG1sLmRvbS5taW5pZG9tIGltcG9ydCBwYXJzZQppbXBvcnQgc3lzCmk9MQpkb20gPSBwYXJzZShzeXMuYXJndlsxXSkKb3V0ID0gb3BlbihzeXMuYXJndlsyXSwgJ3cnKQpib2R5ID0gZG9tLmdldEVsZW1lbnRzQnlUYWdOYW1lKCJib2R5IilbMF0KcGFyYXMgPSBib2R5LmdldEVsZW1lbnRzQnlUYWdOYW1lKCJwIikKZm9yIHBhcmEgaW4gcGFyYXM6CiAgICBvdXQud3JpdGUoc3RyKGkpICsgIlxuIikKICAgIG91dC53cml0ZShwYXJhLmF0dHJpYnV0ZXNbJ2JlZ2luJ10udmFsdWUucmVwbGFjZSgnLicsJywnKSArICcgLS0+ICcgKyBwYXJhLmF0dHJpYnV0ZXNbJ2VuZCddLnZhbHVlLnJlcGxhY2UoJy4nLCcsJykgKyAiXG4iKQogICAgZm9yIGNoaWxkIGluIHBhcmEuY2hpbGROb2RlczoKICAgICAgICBpZiBjaGlsZC5ub2RlTmFtZSA9PSAnYnInOgogICAgICAgICAgICBvdXQud3JpdGUoIlxuIikKICAgICAgICBlbGlmIGNoaWxkLm5vZGVOYW1lID09ICcjdGV4dCc6CiAgICAgICAgICAgIG91dC53cml0ZSh1bmljb2RlKGNoaWxkLmRhdGEpLmVuY29kZSgndXRmPTgnKSkKICAgIG91dC53cml0ZSgiXG5cbiIpCiAgICBpICs9IDE=
_DECRYPT
mode=
drmMode=
pid=
lastpid=
quitsession=
filenameOrig=
filename=
searchDone=
VAR_BANDWIDTH=
VAR_SIZE_PREDICT=
VAR_KEY_SIZE=
VAR_KEY_HEX=
VAR_M3U_SIZE=
VAR_SUB_SIZE=
VAR_CLIPS=
VAR_FOLDER_SERIES=
VAR_FOLDER_SEASON=
}
function func_clear_input () {
while read -t 0 notused; do
read input
echo "ignoring $input"
done
}
function func_null_input () {
local notused=
read notused
}
function func_clear_line () {
printf "\r${TEXT_PADDING}${TEXT_PADDING}${TEXT_PADDING}${TEXT_PADDING}${TEXT_PADDING}"
}
function func_copyright () {
printf "\n${TABS:0:$((5*2))}${COLOR_LIGHT_BLUE}© 2013 Cai. All Rights Reserved.${COLOR_NONE}"
sleep .1
}
function func_mode () {
if [[ "${#mode}" -gt 0 ]]; then
local info=
local filename_disp=
local working_pid_disp=
if [ "$filenameOrig" != "" ]; then
if [[ "${#filenameOrig}" -gt 23 ]]; then
filename_disp=$(printf "%s..." "${filenameOrig:0:20}")
else
filename_disp=$filenameOrig
fi
info="\r${TABS:0:$((5*2))}* Fetching File: ${COLOR_LIGHT_BLUE}$filename_disp${COLOR_NONE}\n"
elif [ "$pid" != "" ]; then
if [[ "${#pid}" -gt 23 ]]; then
working_pid_disp=$(printf "%s...%s" "${pid:0:17}" "${pid:0:20}")
else
working_pid_disp=$pid
fi
info="\r${TABS:0:$((5*2))}* Working URL/PID: ${COLOR_RED}$working_pid_disp${COLOR_NONE}\n"
fi
printf "\r${TABS:0:$((5*2))}* Channel: ${COLOR_LIGHT_BLUE}$mode${COLOR_NONE} ${COLOR_DARY_GRAY}($drmMode)${COLOR_NONE}\n$info"
fi
}
function func_banner () {
clear
printf "$banner\n"
printf "${TABS:0:$((5*2))}* Operating System: ${COLOR_LIGHT_BLUE}${CONST_OS}${COLOR_NONE}\n"
func_mode
local uuid_disp="-"
if [[ "${#uuid}" -gt 0 ]]; then
uuid_disp=$uuid
fi
printf "\r${TABS:0:$((5*2))}* Session UUID: ${COLOR_LIGHT_BLUE}$uuid_disp${COLOR_NONE}\n"
}
function func_cursor_switch () {
if [[ $1 -ne 0 ]]; then
printf "${CURSOR_SHOW}"
else
printf "${CURSOR_HIDE}${COLOR_NONE}"
fi
}
function func_size () {
if [ "${CONST_OS}" == "Darwin" ]; then
echo "$(stat -f%z "$1")"
else
echo "$(stat --format="%s" "$1")"
fi
}
function func_search_string () {
local regex=$(printf "(%q)([^%q]+)(%q)" "$2" "$3" "$3")
shopt -s nocasematch ; [[ $1 =~ $regex ]] ; echo "${BASH_REMATCH[2]}"
}
function func_json_parser () {
echo "$1" | jsawk "return this.$2" 2>/dev/null
}
function func_urlencode() {
local length="${#1}"
for (( i = 0 ; i < length ; i++ )); do
local c="${1:i:1}"
case "$c" in
[a-zA-Z0-9.~_-]) printf "$c" ;;
' ') printf + ;;
*) printf '%%%X' "'$c"
esac
done
}
function func_urldecode() {
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\x}"
}
function func_field_gen () {
printf "${COLOR_NONE}${COLOR_BG_DARY_GRAY}${TEXT_PADDING:0:$1}${COLOR_NONE}${COLOR_DARY_GRAY} $2${COLOR_NONE}${COLOR_BG_DARY_GRAY}${BACKSPACES:0:$((($1+${#2}+2)*2))}"
}
function func_air_date () {
local airtimestamp=
if [[ $1 -eq 0 ]]; then
airtimestamp=$($CONST_DATE_BIN --date "$2" +"%s")
else
airtimestamp=${2:0:10}
fi
local airdatestring=$($CONST_DATE_BIN --date "@$airtimestamp" +"%Y-%m-%d %I:%M %p")
local daysAgo=$(TZ="$timezone" $CONST_DATE_BIN +"%s")
local daysAgo=$(( ( $daysAgo - $airtimestamp )/86400 ))
local days_disp=
local color_disp=${COLOR_LIGHT_BLUE}
if [[ "$daysAgo" -eq -1 ]]; then
days_disp="Tomorrow"
color_disp=${COLOR_LIGHT_GREEN}
elif [[ "$daysAgo" -lt 0 ]]; then
days_disp="In ${daysAgo#-} days"
color_disp=${COLOR_RED}
elif [[ "$daysAgo" -eq 1 ]]; then
days_disp="Yesterday"
color_disp=${COLOR_YELLOW}
elif [[ "$daysAgo" -eq 0 ]]; then
days_disp="Today"
color_disp=${COLOR_YELLOW}
elif [[ "$daysAgo" -lt 7 ]]; then
days_disp="This Week"
color_disp=${COLOR_PURPLE}
else
days_disp="$daysAgo days ago"
fi
printf "$color_disp$airdatestring${COLOR_NONE} ${COLOR_DARY_GRAY}$days_disp${COLOR_NONE}\n"
}
function func_vpn_connect () {
bncMode=
local vpn_name=
case "$geoReq" in
AU ) vpn_name=$CONST_VPN_NAME_AU ;;
CA ) vpn_name=$CONST_VPN_NAME_CA ;;
US ) vpn_name=$CONST_VPN_NAME_US ;;
GB ) vpn_name=$CONST_VPN_NAME_GB ;;
esac
if [ "$country" != "$geoReq" ] && [ "$CONST_PROXY" != "" ]; then
proxy="-x \"http://${CONST_PROXY}\""
bncMode="Proxy: ${CONST_PROXY}"
func_geo_ip
elif [ "$country" != "$geoReq" ]; then
printf "\r\n${COLOR_RED}${TABS:0:$((4*2))} >> Connecting to VPN...${COLOR_NONE}"
func_vpn_connect_core >/dev/null 2>&1
bncMode="VPN: $vpn_name"
func_geo_ip
else
return
fi
}
function func_vpn_disconnect () {
func_vpn_disconnect_core >/dev/null 2>&1
func_geo_ip
}
function func_vpn_connect_core () {
local vpn_name=
case "$geoReq" in
AU ) vpn_name=$CONST_VPN_NAME_AU ;;
CA ) vpn_name=$CONST_VPN_NAME_CA ;;
US ) vpn_name=$CONST_VPN_NAME_US ;;
GB ) vpn_name=$CONST_VPN_NAME_GB ;;
esac
if [ "${CONST_OS}" == "Darwin" ]; then
/usr/bin/env osascript <<-EOF
tell application "System Events"
tell current location of network preferences
set VPN to service "$vpn_name" -- your VPN name here
if exists VPN then connect VPN
repeat while (current configuration of VPN is not connected)
delay 1
end repeat
end tell
end tell
EOF
else
nmcli con up id "$vpn_name" >/dev/null 2>&1
fi
sleep 1
}
function func_vpn_disconnect_core () {
local vpn_name=
case "$geoReq" in
AU ) vpn_name=$CONST_VPN_NAME_AU ;;
CA ) vpn_name=$CONST_VPN_NAME_CA ;;
US ) vpn_name=$CONST_VPN_NAME_US ;;
GB ) vpn_name=$CONST_VPN_NAME_GB ;;
esac
if [ "${CONST_OS}" == "Darwin" ]; then
/usr/bin/env osascript <<-EOF
tell application "System Events"
tell current location of network preferences
set VPN to service "$vpn_name" -- your VPN name here
if exists VPN then disconnect VPN
end tell
end tell
EOF
else
nmcli con up down "$vpn_name" >/dev/null 2>&1
fi
sleep 1
}
function func_geo_ip () {
country="$(curl -sL $proxy "http://video.nbcuni.com/geoCountry.xml" | tr "<>" "\n" | sed '5q;d')"
}
function func_geo_show () {
local color=
local bnc_disp=
if [ "$country" != "$geoReq" ]; then
color="${COLOR_RED}"
if [[ "${#bncMode}" -gt 0 ]]; then
if [[ "${#bncMode}" -gt 18 ]]; then
bnc_disp=$(printf "(%s...%s)" "${bncMode:0:12}" "${bncMode:$((${#bncMode}-3))}")
else
bnc_disp="($bncMode)"
fi
fi
else
color="${COLOR_LIGHT_BLUE}"
fi
printf "\r${TABS:0:$((5*2))}* Current Region: $color$country${COLOR_NONE} ${COLOR_DARY_GRAY}$bnc_disp${COLOR_NONE}\n"
}
function func_continue_searching () {
printf "\n"
if [[ "$totalcount" -gt 0 ]]; then
printf "\r${COLOR_CYAN}${TABS:0:$((4*2))} >> Enter a number to use it's PID: # "
func_field_gen 3 "(e.g. 3)"
func_cursor_switch 1
read -e pidSelect
func_cursor_switch 0
tput cuu1
if [[ "$pidSelect" -gt 0 ]]; then
pid=${pidArray[$(($pidSelect-1))]}
searchDone=1;
fi
func_clear_line
if [[ "$(tput cols)" -le 132 ]]; then
tput cuu1
fi
fi
if [[ "$pidSelect" -lt 1 ]]; then
printf "\r${COLOR_CYAN}${TABS:0:$((4*2))} >> Search again? "
func_field_gen 4 "[y|n]"
func_cursor_switch 1
read -n 1 -e searchDone
func_cursor_switch 0
tput cuu1
case $searchDone in
y|Y) pid=""; searchDone=0 ;;
*) searchDone=1 ;;
esac
fi
}
function func_show_recommands () {
printf "\r\n${COLOR_CYAN}${TABS:0:$((4*2))} >> Want recommands? "
func_field_gen 4 "[y|n]"
func_cursor_switch 1
read -n 1 -e recommands
func_cursor_switch 0
tput ccu1
func_banner
case $recommands in
y|Y)
printf "\r\n${TABS:0:$((4*2))} * Processing...${TEXT_PADDING}"
recommands=1
;;
*)
printf "\r\n${TABS:0:$((4*2))} * Searching Canceled.${TEXT_PADDING}"
recommands=0
;;
esac
}
function func_limit_results () {
if [[ "$totalcount" -gt $CONST_SEARCH_MAX ]] && [[ "$VAR_SEARCH_IGNORE" -eq 0 ]]; then
totalcount=$CONST_SEARCH_MAX
fi
}
function func_bandwidth () {
if [[ "$2" -eq 0 ]]; then
VAR_BANDWIDTH=$(echo "$1" | tr ',' '\n' | grep "BANDWIDTH" | cut -f2 -d'=' | sort -nr | head -n1 | sed -e s/[^0-9]//g)
elif [[ "$2" -eq 1 ]]; then
VAR_BANDWIDTH=$(echo "$1" | tr ' ' '\n' | grep "system-bitrate" | tr -d '"'| cut -f2 -d'=' | sort -nr | head -n1 | sed -e s/[^0-9]//g)
else
VAR_BANDWIDTH=$(echo "$1" | tr ' ' '\n' | grep "bitrate" | tr -d '"'| cut -f2 -d'=' | sort -nr | head -n1 | sed -e s/[^0-9]//g)
fi
}
function func_progress_status () {
func_banner
func_geo_show
toDoList=(
"Revieving Manifest." #1
"Capturing Subtitle." #2
"Capturing M3U." #3
"Capturing Stream List." #4
"Capturing DRM Key." #5
"Capturing Stream." #6
"Creating File List." #7
"Generating Local M3U." #8
"Decrypting Stream." #9
"Transcoding Stream." #10
"Removing Cache." #10
"???") #11
printf "\n${TABS:0:$((4*2))} * Progress Status:\n\n"
local y=0
for i in "${toDoList[@]}"
do
y=$((++y))
local STAGE_MARK=" "
local STAGE_MARK_COLOR=${COLOR_LIGHT_BLUE}
local STAGE_COLOR=
local STAGE_EFFECT=
if [[ $y -lt $1 ]]; then
STAGE_MARK="√"
STAGE_COLOR=${COLOR_LIGHT_BLUE}
elif [[ $y -eq $1 ]]; then
STAGE_MARK="-"
STAGE_MARK_COLOR=${COLOR_YELLOW}
STAGE_COLOR=${COLOR_RED}
else
STAGE_MARK=" "
STAGE_COLOR=${COLOR_DARY_GRAY}
fi
if [[ $y -eq 2 ]] && [ "${VAR_SUB_SIZE}" != "" ]; then
i=$(printf "%s${COLOR_NONE} ${COLOR_DARY_GRAY}(%d kB)${COLOR_NONE}$STAGE_COLOR" "$i" $(($VAR_SUB_SIZE/1000)))
elif [[ $y -eq 2 ]] && [[ $y -lt $1 ]]; then
STAGE_MARK="x"
STAGE_MARK_COLOR=${COLOR_RED}
STAGE_COLOR=${COLOR_YELLOW}
elif [[ $y -eq 3 ]] && [ "${VAR_M3U_SIZE}" != "" ]; then
i=$(printf "%s${COLOR_NONE} ${COLOR_DARY_GRAY}(%d kB)${COLOR_NONE}$STAGE_COLOR" "$i" $(($VAR_M3U_SIZE/1000)))
elif [[ $y -eq 4 ]] && [ "${VAR_CLIPS}" != "" ]; then
i=$(printf "%s${COLOR_NONE} ${COLOR_DARY_GRAY}(%d files)${COLOR_NONE}$STAGE_COLOR" "$i" $VAR_CLIPS)
elif [[ $y -eq 5 ]] && [ "${VAR_KEY_HEX}" != "" ]; then
i=$(printf "%s${COLOR_NONE} ${COLOR_DARY_GRAY}(0x%s)${COLOR_NONE}$STAGE_COLOR" "$i" "${VAR_KEY_HEX}")
elif ([[ $y -ge 4 ]] && [[ $y -le 5 ]] || [[ $y -ge 7 ]] && [[ $y -le 9 ]]) && [ "$drmMode" == "Adobe RTMP" ]; then
if [[ $y -lt $1 ]]; then
STAGE_MARK="x"
fi
STAGE_MARK_COLOR=${COLOR_DARY_GRAY}
STAGE_COLOR=${COLOR_DARY_GRAY}
elif [[ $y -eq 6 ]] && [ "${VAR_BANDWIDTH}" != "" ]; then
i=$(printf "%s${COLOR_NONE} ${COLOR_DARY_GRAY}(Bandwidth: %d kbps)${COLOR_NONE}$STAGE_COLOR" "$i" $(($VAR_BANDWIDTH/1000)))
else
echo 1 >/dev/null 2>&1
fi
printf "${TABS:0:$((4*2))} [$STAGE_MARK_COLOR $STAGE_MARK ${COLOR_NONE}] $STAGE_COLOR%s${COLOR_NONE}\n" "$i"
done
}
function func_filename () {
local file=$(/usr/bin/basename "$2")
if [[ "$1" -eq 0 ]]; then
echo "${file%.*}"
else
echo "${file##*.}"
fi
}
function func_subtitle () {
local subUrl="$1"
local newName="$2"
local extension=$(func_filename 1 "$subUrl")
VAR_SUB_ONLY=
VAR_SUB_NAME="$newName.$extension"
curl -sL --user-agent "${CONST_CURL_AGENT}" "$subUrl" > "$VAR_SUB_NAME"
VAR_SUB_SIZE=$(func_size "$VAR_SUB_NAME")
python _t_$uuid "$VAR_SUB_NAME" "$newName.srt" >/dev/null 2>&1
func_notification "Subtitle downloaded." "$filename" 0
}
function func_transcoding () {
local filename_disp=
local lengthLimit=30
if [[ "${#filename}" -gt $lengthLimit ]]; then
filename_disp=$(printf "%s...%s" "${filename:0:$(($lengthLimit-6))}" "${filename:$((${#filename}-3))}")
else
filename_disp=$filename
fi
printf "\r\n${COLOR_RED}${TABS:0:$((3*2))} >> [${COLOR_NONE}${COLOR_LIGHT_CYAN}${TEXT_BLINK} Transcoding ${COLOR_NONE}${COLOR_RED}]${COLOR_NONE} ${COLOR_DARY_GRAY} \"%s.mp4\" in progress.${COLOR_NONE}${TEXT_PADDING}" $filename_disp
if [[ "$1" -eq 0 ]]; then
ffmpeg -loglevel panic -i $filename.mp4.flv -c copy -bsf:a aac_adtstoasc $filename.mp4
else
ffmpeg -loglevel panic -f concat -i file_list.txt -c copy -bsf:a aac_adtstoasc $filename.mp4
fi
func_notification "Finished transcoding." "$filename" 1
}
function func_download_status () {
local progressbar='-\|/'
local start_time=`$CONST_DATE_BIN +%s`
local i=0
local percent=0
local etaTime=
local elapsedTime=
local padding=' '
local t=0
local h=0
local m=0
local s=0
VAR_STREAM_SIZE=
func_notification "Download started. (Approx. ${VAR_SIZE_PREDICT} MB)" "$filename" 0
printf "\n"
while kill -0 $lastpid >/dev/null 2>&1
do
i=$(((i+1)%4))
local currentSize=$(du -sk)
currentSize=${currentSize%.*}
t=$(expr `$CONST_DATE_BIN +%s` - $start_time + 1)
currentSize=$(echo "scale=2; ${currentSize}/1024" | bc)
speed=$(echo "scale=2; ${currentSize}*8/${t}" | bc)
h=$((${t}/3600))
m=$(((${t}%3600)/60))
s=$((${t}%60))
elapsedTime=$(printf "%02d:%02d:%02d" $h $m $s)
if [[ "$VAR_CLIPS" -lt 1 ]]; then
if [ "${currentSize:0:1}" == "." ]; then
currentSize=0.001
elif [[ "${currentSize%.*}" -lt 1 ]]; then
currentSize="0$currentSize"
fi
t=$(echo "scale=0; ${t}/${currentSize}*(${VAR_SIZE_PREDICT}-${currentSize})" | bc)
t=$(printf "%d" ${t%.*})
h=$((${t}/3600))
m=$(((${t}%3600)/60))
s=$((${t}%60))
etaTime=$(printf "%02d:%02d:%02d" $h $m $s)
percent=$(echo "scale=0; ${currentSize}*100/${VAR_SIZE_PREDICT}" | bc)
percent=$(printf "%d" ${percent%.*})
printf "\r${COLOR_RED}${TABS:0:$((2*2))} >> [${COLOR_NONE}${COLOR_LIGHT_CYAN}${TEXT_BLINK} Capturing %3d%% ${COLOR_NONE}${COLOR_RED}]${COLOR_NONE} ${progressbar:$i:1} ${COLOR_DARY_GRAY} %.2f of %.2f MB in $elapsedTime. (%.2f Mbps, ETA: %s)${COLOR_NONE}${TEXT_PADDING}" $percent $currentSize $VAR_SIZE_PREDICT $speed "$etaTime"
if [[ "$(tput cols)" -le 132 ]]; then
tput cuu1
fi
else
currentFiles=$(ls -1 *.ts 2>/dev/null | wc -l)
if [[ "$currentFiles" -lt 1 ]]; then
currentFiles=1
fi
t=$((${t}/${currentFiles}*(${VAR_CLIPS}-${currentFiles})))
h=$((${t}/3600))
m=$(((${t}%3600)/60))
s=$((${t}%60))
etaTime=$(printf "%02d:%02d:%02d" $h $m $s)
percent=$((${currentFiles}*100/${VAR_CLIPS}))
printf "\r${COLOR_RED}${TABS:0:$((2*2))} >> [${COLOR_NONE}${COLOR_LIGHT_CYAN}${TEXT_BLINK} Downloading %3d%% ${COLOR_NONE}${COLOR_RED}]${COLOR_NONE} ${progressbar:$i:1} ${COLOR_DARY_GRAY} %.2f of %.2f MB in $elapsedTime. (%.2f Mbps, ETA: %s)${COLOR_NONE}${TEXT_PADDING}" $percent $currentSize $VAR_SIZE_PREDICT $speed "$etaTime"
if [[ "$(tput cols)" -le 132 ]]; then
tput cuu1
fi
fi
sleep 1
done
printf "\r${TEXT_PADDING}${TEXT_PADDING}${TEXT_PADDING}${TEXT_PADDING}${TEXT_PADDING}${TEXT_PADDING}"
currentSizeReadable=$(du -sh | awk '{print $1;}')
VAR_STREAM_SIZE=$(du -sk | awk '{print $1;}')
if [[ "$(tput cols)" -le 132 ]]; then
tput cuu1
fi
printf "\r${TABS:0:$((4*2))} * Done fetching. ${COLOR_LIGHT_BLUE}$currentSizeReadable${COLOR_NONE} in ${COLOR_RED}$elapsedTime${COLOR_NONE}.${TEXT_PADDING}"
func_notification "Downloaded $currentSizeReadable in $elapsedTime." "$filename" 0
sleep .5
}
function func_get_pid () {
while [[ "${#pid}" -ne $1 ]]; do
printf "${COLOR_NONE}"
func_banner
printf "\r\n${COLOR_NONE}${COLOR_CYAN}${TABS:0:$((4*2))} >> Enter a PID to fetch: "
func_field_gen $1 "(e.g. $2)"
func_cursor_switch 1
read -n $1 -e pid
tput cuu1
done
func_cursor_switch 0
}
function func_decrypt () {
local iv=0
local iv_hex=
local iv_gen=
local file_in=
local file_out=
local key=
local key_hex=
local i=0
printf "\n"
while read s; do
if [ ${s:0:30} == "#EXT-X-KEY:METHOD=AES-128,URI=" ]; then
key=${s#*URI=\"*}
key=${key%\"*}
key_hex=$(xxd -p "$key" 2>/dev/null | tr -d '\n')
iv_gen=0
iv="$(echo "$s" | grep "IV=" | sed 's/.*IV=//')"
if [[ ${#iv} -gt 0 ]] && [ ${iv:0:2} == "0x" ]; then
iv=${iv##*0x}
iv_hex="${iv:0:32}"
elif [[ ${#iv} -gt 0 ]]; then
iv_hex=$(printf "%032x" "$iv" 2>/dev/null)
else
iv=0
iv_hex=$(printf "%032x" "$iv" 2>/dev/null)
iv_gen=1
fi
elif [ ${s:0:15} == "#EXT-X-KEY:NONE" ]; then
key=
iv=
iv_hex=
iv_gen=0
elif [ ${s:0:1} != "#" ]; then
file_in="$s"
file_out=$(printf "_%s" "$s")
i=$(($i+1))
if [[ ${#key} -lt 1 ]]; then
continue
fi
printf "\r${COLOR_RED}${TABS:0:$((4*2))} >> [${COLOR_NONE}${COLOR_LIGHT_CYAN}${TEXT_BLINK} Decrypting ${COLOR_NONE}${COLOR_RED}]${COLOR_NONE} ${COLOR_DARY_GRAY} %d of ${VAR_CLIPS} files.${COLOR_NONE}${TEXT_PADDING}" $i
openssl aes-128-cbc -d -K $key_hex -iv $iv_hex -nosalt -in $file_in -out $file_out & 2>/dev/null
if [[ "$iv_gen" -gt 0 ]]; then
iv=$(($iv+1))
iv_hex=$(printf "%032x" "$iv" 2>/dev/null)
fi
else
echo "" >/dev/null 2>&1
fi
done < "$1"
func_notification "Decrypted ${VAR_CLIPS} files." "$filename" 0
}
function func_exit_quick () {
printf "${COLOR_NONE}"
func_cursor_switch 1
kill -9 $lastpid >/dev/null 2>&1
killall -9 parallel >/dev/null 2>&1
killall -9 curl >/dev/null 2>&1
killall -9 rtmpdump >/dev/null 2>&1
rm -rf "${WORKING_DIR}"
cd "${CURRENT_DIR}"
clear
printf "\033[8;${originalLines};${originalColumns}t"
exit 0
}
# Traps.
trap 'func_exit_quick;' INT
#-------------------- Consts --------------------
#-------------------- Starts --------------------
func_main () {
func_uuidgen
func_cursor_switch 0
func_initiate
geoReq="US"
func_banner
local providersList=(
"ABC"
"CBS"
"FOX"
"Lifetime"
"NBC"
"BBC"
"SyFy"
"USA"
"Bravo"
"A&E"
"Bio"
"TheCW"
"GlobalTV"
"FX"
"SBS")
IFS=$'\n' providersList=($(sort <<<"${providersList[*]}"))
providerid=
while [[ "$providerid" -lt 1 ]] || [[ "$providerid" -gt ${#providersList[@]} ]]
do
func_banner
printf "\n${TABS:0:$((4*2))} * Avaliable providers:\n\n"
local n=
for i in "${providersList[@]}"
do
n=$((++n))
printf "${TABS:0:$((5*2))}[${COLOR_YELLOW} %2d ${COLOR_NONE}] ${COLOR_LIGHT_BLUE}%s${COLOR_NONE}\n" $n "$i"
done
printf "\r\n${COLOR_CYAN}${TABS:0:$((4*2))} >> Choose a provider: # "
func_field_gen 4 "(e.g. 2)"
func_cursor_switch 1
read -n 3 -e providerid
func_cursor_switch 0
done
providerid="${providersList[$(($providerid-1))]}"
#-------------------- Ends --------------------
#-------------------- ABC Mode Starts --------------------
if [ "$providerid" == "ABC" ]; then
mode="ABC"
drmMode="Apple HLS"
pidLength=14
local pidPrefix="VDKA0_"
while [[ "$searchDone" -eq 0 ]]; do
func_banner
printf "\n${TABS:0:$((3*2))} * Enter a full episode URL or a PID. (Starts with \"${COLOR_CYAN}http://${COLOR_NONE}\" or \"${COLOR_CYAN}$pidPrefix${COLOR_NONE}\")\n"
printf "\r\n${COLOR_CYAN}${TABS:0:$((4*2))} >> URL/PID: "
func_field_gen "$pidLength" "VDKA0_hsogkucz"
func_cursor_switch 1
read -e pid
func_cursor_switch 0
func_banner
printf "\r\n${TABS:0:$((4*2))} * Searching for PID...\n"
if [[ "${#pid}" -eq "$pidLength" ]] && [ "${pid:0:${#pidPrefix}}" == "$pidPrefix" ]; then
func_banner
printf "\r\n${TABS:0:$((4*2))} * Getting details of PID \"${COLOR_BG_RED}$pid${COLOR_NONE}\"...\n"
elif [ "${pid:0:7}" == "http://" ] && [ "${pid:0:8}" == "https://" ]; then
feed=$(curl -sL "$pid" | iconv -f UTF-8 | grep "og:url")
pid=$(func_search_string "$feed" "/$pidPrefix" "/")
pid=$(printf "VDKA0_%s" "$pid")
func_banner
if [[ "${#pid}" -eq "$pidLength" ]]; then
printf "\r\n${TABS:0:$((4*2))} * Getting details of PID \"${COLOR_BG_RED}$pid${COLOR_NONE}\"...\n"
else
printf "\r\n${TABS:0:$((4*2))} * No PID found.\n"
sleep 1
fi
else
func_banner
printf "\r\n${TABS:0:$((4*2))} * Invalid input.\n"
sleep 1
fi
if [[ "${#pid}" -eq "$pidLength" ]]; then
pid=$(echo $pid | rev | cut -f1 -d"_" | rev)
local series_disp=
local title_disp=
local season_disp=
local episode_disp=
local description_disp=
local airdate_disp=
local availdate_disp=
local expiredate_disp=
local duration_disp=
json=$(curl -sL $proxy --cookie-jar cookies.txt "http://api.watchabc.go.com/vp2/ws/s/contents/2015/videos/jsonp/001/001/-1/-1/-1/VDKA0_$pid/-1/-1")
series_disp=$(func_json_parser "$json" "videos.video.show.title")
if [[ "${#series_disp}" -gt 0 ]]; then
title_disp=$(func_json_parser "$json" "videos.video.title")
season_disp=$(func_json_parser "$json" "videos.video.season[\"@id\"]")
episode_disp=$(func_json_parser "$json" "videos.video.number")
description_disp=$(func_json_parser "$json" "videos.video.description")
airdate_disp=$(func_json_parser "$json" "videos.video.airdates.airdate")
airdate_disp=$(func_air_date 0 "$airdate_disp")
availdate_disp=$(func_json_parser "$json" "videos.video.availdate")
availdate_disp=$(func_air_date 0 "$availdate_disp")
expiredate_disp=$(func_json_parser "$json" "videos.video.expiredate")
expiredate_disp=$(func_air_date 0 "$expiredate_disp")
duration_disp=$(func_json_parser "$json" "videos.video.duration.$")
if [[ "${#series_disp}" -gt 33 ]]; then
series_disp=$(printf "%s..." "${series_disp:0:33}")
fi
if [[ "${#description_disp}" -gt 49 ]]; then
description_disp=$(printf "%s..." "${description_disp:0:46}")
fi
printf "\n"
printf "${TABS:0:$((3*2))} * Series: ${COLOR_LIGHT_BLUE}$series_disp${COLOR_NONE} ${TEXT_PADDING:${#series_disp}} [${COLOR_BG_RED}VDKA0_$pid${COLOR_NONE}]\n"
printf "${TABS:0:$((3*2))} * Title: ${COLOR_LIGHT_BLUE}$title_disp${COLOR_NONE}\n"
printf "${TABS:0:$((3*2))} * Season: ${COLOR_LIGHT_BLUE}$season_disp${COLOR_NONE}\n"
printf "${TABS:0:$((3*2))} * Episode: ${COLOR_LIGHT_BLUE}$episode_disp${COLOR_NONE}\n"
printf "${TABS:0:$((3*2))} * Duration: ${COLOR_LIGHT_BLUE}$(($duration_disp/60000)) mins${COLOR_NONE}\n"
printf "${TABS:0:$((3*2))} * Air: $airdate_disp\n"
printf "${TABS:0:$((3*2))} * Avaliable: $availdate_disp\n"
printf "${TABS:0:$((3*2))} * Expire: $expiredate_disp\n"
printf "${TABS:0:$((3*2))} * Description: ${COLOR_LIGHT_BLUE}$description_disp${COLOR_NONE}"
else
printf "\r\n${TABS:0:$((4*2))} * No episode found."
fi
if [[ "${#pid}" -eq "$(($pidLength-${#pidPrefix}))" ]]; then
printf "\n"
func_continue_searching
fi
fi
done
func_progress_status 1
func_vpn_connect
text=$(curl -sL $proxy --cookie-jar cookies.txt "http://www.kaltura.com/p/585231/sp/58523100/playManifest/format/http/entryId/0_$pid/a.f4m?playbackContext=brand%3D001%26device%3D001")
url=$(func_search_string "$text" "<media url=\"" "\"")
url=$(echo "$url" | sed 's/&/\&/g' )
func_progress_status 2
tturl=$(func_json_parser "$json" "videos.video.closedcaption.src.$")
if [[ "${#season_disp}" -ne 0 ]]; then
season_disp=$(printf "S%02d" "$season_disp")
else
season_disp=""
fi
if [[ "${#episode_disp}" -ne 0 ]]; then
episode_disp=$(printf "E%02d" "$episode_disp")
else
episode_disp=""
fi
filenameOrig=$(printf "%s_%s%s_%s_%s" "$series_disp" "$season_disp" "$episode_disp" "$title_disp" "$pid_disp" | sed -e 's/[^A-Za-z0-9._-]/_/g' | sed 's/__*/_/g')
VAR_FOLDER_SERIES=$(printf "%s" "$series_disp" | sed -e 's/[^A-Za-z0-9._-]/ /g' | sed 's/ */ /g')
VAR_FOLDER_SEASON=$(printf "%s" "$season_disp" | sed -e 's/[^A-Za-z0-9._-]/ /g' | sed 's/ */ /g')
filename=$(printf "%s_%s" "$filenameOrig" "$uuid")
func_subtitle "$tturl" "$filename"
cat "$filename.srt" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n01:/\'$'\n00:/g' | sed 's/ --> 01:/\ --> 00:/g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n02:/\'$'\n01:/g' | sed 's/ --> 02:/\ --> 01:/g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n03:/\'$'\n02:/g' | sed 's/ --> 03:/\ --> 02:/g' > "$filename.srt"
func_progress_status 3
text=$(curl -sL $proxy --cookie cookies.txt --cookie-jar cookies.txt "$url")