forked from sunsettrack4/telerising
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zattoo.pl
7481 lines (6265 loc) · 301 KB
/
zattoo.pl
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
#!/usr/bin/perl
# Copyright (C) 2019-2021 Jan-Luca Neumann
# https://github.com/sunsettrack4/telerising/
#
# Collaborators:
# - DeBaschdi ( https://github.com/DeBaschdi )
#
# 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, 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 telerising. If not, see <http://www.gnu.org/licenses/>.
# ####################################
# TELERISING API FOR ZATTOO + WILMAA #
# ####################################
unlink "log.txt";
unlink "error.txt";
use IO::Tee;
my $tee = new IO::Tee(\*STDOUT, ">>log.txt");
select $tee;
print "\n ========================= I + \n";
print " TELERISING API v0.4.6 I I + \n";
print " ========================= I I + + \n";
print " II \n";
print "ZZZZZZZZZ AA TTTTTTTTTT TTTTTTTTTT 888888 888888 \n";
print " ZZ AA TT TT 88 88 88 88 \n";
print " ZZ A A TT TT 88 88 88 88 \n";
print " ZZ AA AA TT TT 88 888 88\n";
print " ZZ AAAAAAAA TT TT 88 888 88\n";
print " ZZ AA AA TT TT 88 88 88 88 \n";
print " ZZ AA AA TT TT 88 88 88 88 \n";
print "ZZZZZZZZZ AA AA TT TT 888888 888888 \n\n";
print "(c) 2019-2020 Jan-Luca Neumann (sunsettrack4)\n";
print "Please donate to support my work: https://paypal.me/sunsettrack4\n\n";
print "==== API CONFIGURATION ====\n\n";
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($INFO);
my $logConfiguration = qq(
log4perl.logger = ALL, Logfile, Screen
log4perl.appender.Logfile = Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename = log.txt
log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Logfile.layout.ConversionPattern =%p[%d{MM/dd HH:mm} %3L] %m%n
log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 0
log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout
log4perl.appender.Screen.layout.ConversionPattern = %m%n
);
Log::Log4perl::init( \$logConfiguration );
use strict;
use warnings;
binmode STDOUT, ":utf8";
use utf8;
use LWP;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Daemon;
use HTTP::Status;
use HTTP::Request::Params;
use HTTP::Request::Common;
use HTTP::Cookies;
use HTML::TreeBuilder;
use URI::Escape;
use Time::Piece;
use IO::Interface::Simple;
use IO::Socket::SSL;
use Mozilla::CA;
use JSON;
use Encode;
use POSIX qw/ WNOHANG /;
use POSIX qw( strftime );
#
# LOGIN PROCESS
#
sub login_process {
my $login;
unless( $login = fork() ) {
while(1) {
# READ USERFILE
my $json;
{
local $/; #Enable 'slurp' mode
open my $fh, "<", "userfile.json" or die ERROR "UNABLE TO LOGIN TO WEBSERVICE! (User data can't be found!)\n\n";
$json = <$fh>;
close $fh;
}
# SET LOGIN PARAMS
my $userfile;
eval{
$userfile = decode_json($json);
};
if( not defined $userfile ) {
ERROR "Unable to parse user data\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: Unable to parse user data";
close $error_file;
exit;
}
my $provider = $userfile->{'provider'};
my $login_mail = $userfile->{'login'};
my $login_passwd = $userfile->{'password'};
my $interface = $userfile->{'interface'};
my $customip = $userfile->{'address'};
my $zserver = $userfile->{'server'};
my $ffmpeglib = $userfile->{'ffmpeg_lib'};
my $port = $userfile->{'port'};
my $pin = $userfile->{'youth_protection_pin'};
my $ssl_mode = $userfile->{'ssl_mode'};
my $code = $userfile->{'code'};
my $ondemand = $userfile->{'ondemand'};
my $ssldomain = $userfile->{'ssldomain'};
# my $easyepg = $userfile->{'epg'};
my $ssl_verify;
if( defined $ondemand ) {
if( $ondemand ne "true" ) {
undef $ondemand
}
}
# SET DEFAULT VALUES TO REPLACE URL QUERY STRINGS
my $user_platform = $userfile->{'platform'};
my $user_bandwidth = $userfile->{'bw'};
my $user_audio2 = $userfile->{'audio2'};
my $user_dolby = $userfile->{'dolby'};
my $user_profile = $userfile->{'profile'};
my $user_loglevel = $userfile->{'loglevel'};
my $user_maxrate = $userfile->{'ignore_maxrate'};
if( not defined $provider ) {
ERROR "No provider selected\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: No provider selected";
close $error_file;
exit;
} elsif( $provider ne "wilmaa.com" ) {
if( not defined $login_mail or not defined $login_passwd ) {
ERROR "Unable to retrieve complete login data\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "Unable to retrieve complete login data";
close $error_file;
exit;
}
} elsif( $provider eq "wilmaa.com" ) {
if( not defined $login_mail and defined $login_passwd ) {
ERROR "Unable to retrieve complete login data\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "Unable to retrieve complete login data";
close $error_file;
exit;
} elsif( defined $login_mail and not defined $login_passwd ) {
ERROR "Unable to retrieve complete login data\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "Unable to retrieve complete login data";
close $error_file;
exit;
}
}
# SET DEFAULT VALUES
if( not defined $interface and not defined $customip ) {
$interface = "";
$customip = "";
} elsif( defined $customip ) {
if( $customip ne "" ) {
$interface = "";
INFO "Custom IP address or domain \"$customip\" will be used.\n";
} elsif( defined $interface ) {
if( $interface ne "" ) {
$customip = "";
INFO "Custom interface \"$interface\" will be used.\n";
} else {
$customip = "";
$interface = "";
}
} else {
$customip = "";
$interface = "";
}
} elsif( defined $interface ) {
if( $interface ne "" ) {
$customip = "";
INFO "Custom interface \"$interface\" will be used.\n";
} else {
$customip = "";
$interface = "";
}
}
if( not defined $ssldomain ) {
$ssldomain = "false";
} elsif( $ssldomain eq "" ) {
$ssldomain = "false";
} else {
INFO "Custom Domain(SSL) \"$ssldomain\" will be used.\n";
}
if( not defined $zserver ) {
$zserver = "fr5-0";
} elsif( $zserver eq "" ) {
$zserver = "fr5-0";
} elsif( $zserver =~ /fr5-[0-5]|fra3-[0-3]|zh2-[0-9]|zba6-[0-2]|1und1-fra1902-[1-4]|1und1-hhb1000-[1-4]|1und1-dus1901-[1-4]|1und1-ess1901-[1-2]|1und1-stu1903-[1-2]|matterlau1-[0-1]|matterzrh1-[0-1]|1und1-unn1101-[1-2]|1und1-mun1901-[1-2]|1und1-mun1902-[1-4]|1und1-dor1101-[1-2]|1und1-dor1901-[1-2]|1und1-wup1101-[1-2]/ ) {
INFO "Custom Zattoo server \"$zserver\" will be used.\n";
} else {
INFO "Custom Zattoo server \"$zserver\" is not supported, default server will be used instead.\n";
$zserver = "fr5-0";
}
if( not defined $ffmpeglib ) {
$ffmpeglib = "/usr/bin/ffmpeg";
} elsif( $ffmpeglib eq "" ) {
$ffmpeglib = "/usr/bin/ffmpeg";
} else {
INFO "Use custom ffmpeg library path \"$ffmpeglib\"\n";
}
if( not defined $port ) {
$port = "8080";
} elsif( $port eq "" ) {
$port = "8080";
} else {
INFO "Custom port \"$port\" will be used.\n";
}
if( not defined $pin ) {
$pin = "NONE";
} elsif( $provider eq "wilmaa.com" ) {
$pin = "NONE";
} elsif( $pin eq "" ) {
$pin = "NONE";
} elsif( $pin =~ /[0-9][0-9][0-9][0-9]/ ) {
INFO "Youth protection pin will be used to request channel playlists.\n";
} else {
INFO "Youth protection pin must consist of 4 numbers - pin disabled.\n";
$pin = "NONE";
}
if( not defined $ssl_mode ) {
$ssl_mode = "1";
} elsif( $ssl_mode eq "0" ) {
WARN "SSL verification disabled!\n";
}
if( not defined $code ) {
$code = "";
} elsif( $code =~ /[\\\/=?\& ]/ ) {
ERROR "API access code must not contain special characters!\n\n";
open my $error_file, ">", "error.txt" or die ERROR "API access code must not contain special characters!\n\n";
print $error_file "API access code must not contain special characters!";
close $error_file;
exit;
} elsif( $code ne '') {
INFO "Server Protection Code enabled!\n"
}
if( $provider ne "wilmaa.com" ) {
if( not defined $user_platform ) {
$user_platform = "undefined";
undef $user_profile;
} elsif( $user_platform eq "hls" ) {
$user_platform = "hls";
undef $user_profile;
} elsif( $user_platform eq "hls5" ) {
$user_platform = "hls5";
} else {
$user_platform = "undefined";
undef $user_profile;
}
} elsif( defined $user_platform) {
$user_platform = "hls5";
} else {
$user_platform = "undefined";
undef $user_profile;
}
if( not defined $user_bandwidth ) {
$user_bandwidth = "undefined";
} elsif( $user_bandwidth eq "8000" ) {
$user_bandwidth = "8000";
} elsif( $user_bandwidth eq "5000" ) {
$user_bandwidth = "5000";
} elsif( $user_bandwidth eq "4999" ) {
$user_bandwidth = "4999";
} elsif( $user_bandwidth eq "3000" ) {
$user_bandwidth = "3000";
} elsif( $user_bandwidth eq "2999" ) {
$user_bandwidth = "2999";
} elsif( $user_bandwidth eq "1500" ) {
$user_bandwidth = "1500";
} else {
$user_bandwidth = "undefined";
}
if( defined $user_profile ) {
if( $user_profile eq "1" ) {
$user_profile = "1";
} elsif( $user_profile eq "2" ) {
$user_profile = "2";
} elsif( $user_profile eq "3" ) {
$user_profile = "3";
} elsif( $user_profile eq "4" ) {
$user_profile = "4";
} else {
$user_profile = "undefined";
}
} elsif( not defined $user_profile ) {
if( defined $user_dolby and $user_platform ne "hls" ) {
if( $user_dolby ne "true" ) {
$user_dolby = "false";
}
} elsif( not defined $user_dolby and $user_platform ne "hls" ) {
$user_dolby = "undefined";
} else {
$user_dolby = "unavailable";
}
if( defined $user_audio2 and $user_platform ne "hls" ) {
if( $user_audio2 ne "true" ) {
$user_audio2 = "false";
}
} elsif( not defined $user_audio2 and $user_platform ne "hls") {
$user_audio2 = "undefined";
} else {
$user_audio2 = "unavailable";
}
}
if( defined $user_loglevel ) {
if( $user_loglevel ne "fatal" ) {
$user_loglevel = "normal";
}
} else {
$user_loglevel = "undefined";
}
if( defined $user_maxrate ) {
if( $user_maxrate ne "true" ) {
$user_maxrate = "false";
}
} else {
$user_maxrate = "undefined";
}
if( defined $user_profile ) {
INFO "YOUR DEFAULT SETTINGS\n\nPLATFORM: $user_platform\nBANDWIDTH: $user_bandwidth\nPROFILE: $user_profile\nLOGLEVEL: $user_loglevel\nIGN_MAX: $user_maxrate\n";
$user_audio2 = "false";
$user_dolby = "false";
} else {
INFO "YOUR DEFAULT SETTINGS\n\nPLATFORM: $user_platform\nBANDWIDTH: $user_bandwidth\nAUDIO2: $user_audio2\nDOLBY: $user_dolby\nLOGLEVEL: $user_loglevel\nIGN_MAX: $user_maxrate\n";
$user_profile = "0";
}
# CHECK PROVIDER
if( $provider eq "www.zattoo.com" ) {
$provider = "zattoo.com";
} elsif( $provider =~ /zattoo.com|wilmaa.com|www.1und1.tv|mobiltv.quickline.com|tvplus.m-net.de|player.waly.tv|www.meinewelt.cc|www.bbv-tv.net|www.vtxtv.ch|www.myvisiontv.ch|iptv.glattvision.ch|www.saktv.ch|nettv.netcologne.de|tvonline.ewe.de|www.quantum-tv.com|tv.salt.ch|tvonline.swb-gruppe.de|tv.wambo.ch|tv.eir.ie/ ) {
print "";
} else {
ERROR "Provider is not supported. Please recheck the domain.\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: Provider is not supported. Please recheck the domain.";
close $error_file;
exit;
}
if( $provider eq "wilmaa.com" ) {
#
# WILMAA
#
# LOOKUP IP ADDRESS VIA CHANNEL M3U UPDATE TIME
# URLs
my $channel_url = "http://geo.wilmaa.com/channels/basic/web_hls_de.json";
# CHANNEL M3U REQUEST
my $channel_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $channel_request = HTTP::Request::Common::GET($channel_url);
my $channel_response = $channel_agent->request($channel_request);
if( $channel_response->is_error ) {
ERROR "IP lookup: Invalid response\n\n";
ERROR "RESPONSE:\n\n" . $channel_response->content . "\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: IP lookup: Invalid response";
close $error_file;
exit;
}
# READ JSON
my $ch_file;
eval{
$ch_file = decode_json($channel_response->content);
};
if( not defined $ch_file ) {
ERROR "Failed to parse JSON file(s) (IP LOOKUP)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: Failed to parse JSON file(s) (IP LOOKUP)";
close $error_file;
exit;
}
my $m3u_date = $ch_file->{"channelList"}{"published_at"};
my $country_code;
my $tv_mode;
if( defined $m3u_date ) {
if( $m3u_date eq "2018-04-05 14:52:02" ) {
$country_code = "DE";
} else {
$country_code = "CH";
}
} else {
$country_code = "DE";
}
if( $country_code ne "CH" and defined $login_mail and defined $login_passwd ) {
INFO "YOUR ACCOUNT TYPE: WILMAA\n";
INFO "COUNTRY: OTHER\n";
INFO "No Swiss IP address detected, Live TV feature is disabled.\n";
$tv_mode = "pvr";
} elsif( $country_code ne "CH" ) {
INFO "YOUR ACCOUNT TYPE: WILMAA (ANONYMOUS)\n";
INFO "COUNTRY: OTHER\n";
INFO "ERROR: No valid service country detected, Wilmaa services can't be used.\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: No valid service country detected, Wilmaa services can't be used.";
close $error_file;
exit;
} elsif( $country_code eq "CH" and defined $login_mail and defined $login_passwd ) {
INFO "YOUR ACCOUNT TYPE: WILMAA\n";
INFO "COUNTRY: SWITZERLAND\n";
$tv_mode = "live";
} else {
INFO "YOUR ACCOUNT TYPE: WILMAA (ANONYMOUS)\n";
INFO "COUNTRY: SWITZERLAND\n";
$tv_mode = "live";
}
if( defined $login_mail and defined $login_passwd ) {
# GET APPTOKEN + SESSION ID
my $main_url = "https://www.wilmaa.com/de/my/headless/login?callback=undefined";
my $main_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $main_request = HTTP::Request::Common::GET($main_url);
my $main_response = $main_agent->request($main_request);
my $session_token = $main_response->header('Set-cookie');
if( defined $session_token ) {
$session_token =~ s/(.*)(wilmaa=)(.*)(; expires.*)/$3/g;
} else {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve Session ID)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve Session ID)";
close $error_file;
exit;
}
my $parser = HTML::Parser->new;
my $main_content = $main_response->content;
if( not defined $main_content) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (empty webpage content)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (empty webpage content)";
close $error_file;
exit;
}
my $wilmaatree = HTML::TreeBuilder->new;
$wilmaatree->parse($main_content);
if( not defined $wilmaatree) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to parse webpage)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to parse webpage)";
close $error_file;
exit;
}
my @scriptvalues = $wilmaatree->look_down('name' => 'csrf_token');
my $apptoken = $scriptvalues[0]->as_HTML;
if( defined $apptoken ) {
$apptoken =~ s/(.*value=")(.*)(".*)/$2/g;
} else {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve appToken)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve appToken)";
close $error_file;
exit;
}
# GET LOGIN COOKIE
my $login_url = "https://www.wilmaa.com/de/my/headless/login?callback=undefined";
my $login_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $cookie_jar = HTTP::Cookies->new;
$cookie_jar->set_cookie(0,'wilmaa',$session_token,'/','.wilmaa.com',443);
$login_agent->cookie_jar($cookie_jar);
my $login_request = HTTP::Request::Common::POST($login_url, ['username' => $login_mail, 'password' => $login_passwd, 'csrf_token' => $apptoken, 'login_form' => 'true' ]);
my $login_response = $login_agent->request($login_request);
my $login_user = $login_response->header('set-cookie');
if( not defined $login_user ) {
ERROR "LOGIN FAILED! (please re-check login data)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "LOGIN FAILED! (please re-check login data)";
close $error_file;
exit;
} else {
INFO "LOGIN OK!\n";
}
$login_user =~ s/(.*)(wilmaa_user_id=)(.*)(; expires.*)(wilmaa_onboarding_user_id.*)/$3/g;
# URLs
my $chconfig_url = "https://resources.wilmaa.com/channelsOverview/channelMappings.json";
# CHANNEL CONFIG REQUEST
my $chconfig_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $chconfig_request = HTTP::Request::Common::GET($chconfig_url);
my $chconfig_response = $chconfig_agent->request($chconfig_request);
if( $chconfig_response->is_error ) {
ERROR "CH CONFIG URL: Invalid response\n";
ERROR "RESPONSE:\n\n" . $chconfig_response->content . "\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: CH CONFIG URL: Invalid response";
close $error_file;
exit;
}
# READ JSON
my $chconfig_file;
eval{
$chconfig_file = decode_json($channel_response->content);
};
if( not defined $chconfig_file ) {
ERROR "Failed to parse JSON file (CH CONFIG)\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "Failed to parse JSON file (CH CONFIG)";
close $error_file;
exit;
}
# SAVE CHANNEL CONFIG
open my $ch_config, ">", "channels.json";
print $ch_config $chconfig_response->content;
close $ch_config;
# CREATE SESSION FILE
open my $session_file, ">", "session.json" or die ERROR "UNABLE TO CREATE SESSION FILE!\n\n";
print $session_file "{\"provider\":\"$provider\",\"tv_mode\":\"$tv_mode\",\"wilmaa_user_id\":\"$login_user\",\"session_token\":\"$session_token\",\"interface\":\"$interface\",\"address\":\"$customip\",\"ssldomain\":\"$ssldomain\",\"server\":\"$zserver\",\"ffmpeg_lib\":\"$ffmpeglib\",\"port\":\"$port\",\"ssl_mode\":\"$ssl_mode\",\"platform\":\"$user_platform\",\"bandwidth\":\"$user_bandwidth\",\"profile\":\"$user_profile\",\"audio2\":\"$user_audio2\",\"dolby\":\"$user_dolby\",\"loglevel\":\"$user_loglevel\",\"ign_max\":\"$user_maxrate\",\"code\":\"$code\"}";
close $session_file;
sleep 86400;
truncate 'log.txt', 0;
INFO "UPDATING SESSION AUTOMATICALLY...\n";
} else {
# URLs
my $chconfig_url = "https://resources.wilmaa.com/channelsOverview/channelMappings.json";
# CHANNEL CONFIG REQUEST
my $chconfig_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $chconfig_request = HTTP::Request::Common::GET($chconfig_url);
my $chconfig_response = $chconfig_agent->request($chconfig_request);
if( $chconfig_response->is_error ) {
ERROR "CH CONFIG URL: Invalid response\n";
ERROR "RESPONSE:\n\n" . $chconfig_response->content . "\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: CH CONFIG URL: Invalid response";
close $error_file;
exit;
}
# READ JSON
my $chconfig_file;
eval{
$chconfig_file = decode_json($channel_response->content);
};
if( not defined $chconfig_file ) {
ERROR "Failed to parse JSON file (CH CONFIG)\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "Failed to parse JSON file (CH CONFIG)";
close $error_file;
exit;
}
# SAVE CHANNEL CONFIG
open my $ch_config, ">", "channels.json";
print $ch_config $chconfig_response->content;
close $ch_config;
# CREATE SESSION FILE
open my $session_file, ">", "session.json" or die ERROR "UNABLE TO CREATE SESSION FILE!\n\n";
print $session_file "{\"provider\":\"$provider\",\"tv_mode\":\"$tv_mode\",\"interface\":\"$interface\",\"address\":\"$customip\",\"ssldomain\":\"$ssldomain\",\"server\":\"$zserver\",\"ffmpeg_lib\":\"$ffmpeglib\",\"port\":\"$port\",\"ssl_mode\":\"$ssl_mode\",\"platform\":\"$user_platform\",\"bandwidth\":\"$user_bandwidth\",\"profile\":\"$user_profile\",\"audio2\":\"$user_audio2\",\"dolby\":\"$user_dolby\",\"loglevel\":\"$user_loglevel\",\"ign_max\":\"$user_maxrate\",\"code\":\"$code\"}";
close $session_file;
sleep 86400;
truncate 'log.txt', 0;
INFO "UPDATING SESSION AUTOMATICALLY...\n";
}
} else {
#
# ZATTOO
#
# DEFINE APPTOKEN
my $apptoken;
# METHOD 1: GET APPTOKEN VIA MAIN URL
my $token_url = "https://$provider/token.json";
my $token_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $token_request = HTTP::Request::Common::GET($token_url);
my $token_response = $token_agent->request($token_request);
if( $token_response->is_success ) {
my $analyse_apptoken_login;
eval{
$analyse_apptoken_login = decode_json($token_response->content);
};
if( not defined $analyse_apptoken_login ) {
INFO "Unable to parse apptoken json data from main resource (trying next apptoken method now...)\n\n";
} else {
if( $analyse_apptoken_login->{"success"} ) {
$apptoken = $analyse_apptoken_login->{"session_token"}
} else {
INFO "Unable to retrieve apptoken from main resource (trying next apptoken method now...)\n\n";
}
}
}
# METHOD 2: GET APPTOKEN VIA APP URL MENTIONED IN HTML
if( not defined $apptoken ) {
# GET LOGIN HTML
my $main_url = "https://$provider/login/";
my $main_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $main_request = HTTP::Request::Common::GET($main_url);
my $main_response = $main_agent->request($main_request);
if( $main_response->is_error ) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)\n\n";
ERROR "RESPONSE:\n\n" . $main_response->content . "\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)";
close $error_file;
exit;
}
my $parser = HTML::Parser->new;
my $main_content = $main_response->content;
if( not defined $main_content) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (empty webpage content)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (empty webpage content)";
close $error_file;
exit;
}
my $zattootree = HTML::TreeBuilder->new;
$zattootree->parse($main_content);
if( not defined $zattootree) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to parse webpage)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to parse webpage)";
close $error_file;
exit;
}
my @scriptvalues = $zattootree->look_down(_tag => 'script');
my $js_link;
foreach my $js_script (@scriptvalues) {
$js_script = $js_script->as_HTML;
if( $js_script =~ m/<script src="\/app-/ ) {
$js_link = $js_script;
}
}
if( defined $js_link ) {
$js_link =~ s/(<script src="\/)(.*)(.js".*)/$2.js/g;
# GET APPTOKEN JSON
my $js_url = "https://$provider/$js_link";
my $js_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $js_request = HTTP::Request::Common::GET($js_url);
my $js_response = $js_agent->request($js_request);
if( $js_response->is_error ) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)\n\n";
ERROR "RESPONSE:\n\n" . $js_response->content . "\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)";
close $error_file;
exit;
}
my $token_url = $js_response->content;
$token_url =~ s/(.*)(token-+(.*?)\.json)(.*)/$2/g;
if( not defined $2 ) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to parse token URL)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to parse token URL)";
close $error_file;
exit;
}
# GET APPTOKEN
my $apptoken_url = "https://$provider/$2";
my $apptoken_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $apptoken_request = HTTP::Request::Common::GET($apptoken_url);
my $apptoken_response = $apptoken_agent->request($apptoken_request);
if( $apptoken_response->is_error ) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to get token json file)\n\n";
ERROR "RESPONSE:\n\n" . $apptoken_response->content . "\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to get token json file)";
close $error_file;
exit;
}
my $analyse_apptoken_login;
eval{
$analyse_apptoken_login = decode_json($apptoken_response->content);
};
if( not defined $analyse_apptoken_login ) {
INFO "Unable to parse apptoken json data (trying old apptoken method now...)\n\n";
} else {
if( $analyse_apptoken_login->{"success"} ) {
$apptoken = $analyse_apptoken_login->{"session_token"}
} else {
ERROR "Unable to parse apptoken from json file\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "ERROR: Unable to parse apptoken from json file";
close $error_file;
exit;
}
}
}
# METHOD 3: GET APPTOKEN VIA HOMEPAGE
if( not defined $apptoken ) {
my $new_main_url = "https://$provider/";
my $new_main_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $new_main_request = HTTP::Request::Common::GET($new_main_url);
my $new_main_response = $new_main_agent->request($new_main_request);
if( $new_main_response->is_error ) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)\n\n";
ERROR "RESPONSE:\n\n" . $new_main_response->content . "\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)";
close $error_file;
exit;
}
my $new_parser = HTML::Parser->new;
my $new_main_content = $new_main_response->content;
foreach my $js_script (@scriptvalues) {
if( $js_script =~ m/<script type="text\/javascript">window.appToken/ ) {
$apptoken = $js_script;
}
}
if( defined $apptoken ) {
$apptoken =~ s/(.*window.appToken = ')(.*)(';.*)/$2/g;
} else {
INFO "Unable to retrieve apptoken (trying another apptoken method now...)\n\n";
}
}
if( not defined $apptoken ) {
my $new_token_url = "https://$provider/token-46a1dfccbd4c3bdaf6182fea8f8aea3f.json";
my $new_token_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $new_token_request = HTTP::Request::Common::GET($new_token_url);
my $new_token_response = $new_token_agent->request($new_token_request);
if( $new_token_response->is_error ) {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)\n\n";
ERROR "RESPONSE:\n\n" . $new_token_response->content . "\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (no internet connection / service unavailable)";
close $error_file;
exit;
}
my $new_token_content = $new_token_response->content;
if( $new_token_content =~ m/{"success": true, "session_token": "/ ) {
$apptoken = $new_token_content;
$apptoken =~ s/(\{"success": true, "session_token": ")(.*)("\})/$2/g;
} else {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve apptoken)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve apptoken)";
close $error_file;
exit;
}
}
}
# GET SESSION ID
my $session_url = "https://$provider/zapi/session/hello";
my $session_agent = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => $ssl_mode,
verify_hostname => $ssl_mode,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
},
agent => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/72.0"
);
my $session_request = HTTP::Request::Common::POST($session_url, ['client_app_token' => uri_escape($apptoken), 'uuid' => uri_escape('d7512e98-38a0-4f01-b820-5a5cf98141fe'), 'lang' => uri_escape('en'), 'format' => uri_escape('json')]);
my $session_response = $session_agent->request($session_request);
my $session_token = $session_response->header('Set-cookie');
if( defined $session_token ) {
$session_token =~ s/(.*)(beaker.session.id=)(.*)(; Path.*)/$3/g;
} else {
ERROR "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve Session ID)\n\n";
open my $error_file, ">", "error.txt" or die ERROR "UNABLE TO CREATE ERROR FILE!\n\n";
print $error_file "UNABLE TO LOGIN TO WEBSERVICE! (unable to retrieve Session ID)";
close $error_file;
exit;
}
if( $session_response->is_error ) {
ERROR "LOGIN FAILED! (invalid response)\n\n";