-
Notifications
You must be signed in to change notification settings - Fork 1
/
addon.py
2744 lines (2135 loc) · 197 KB
/
addon.py
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/env python
# -*- coding: utf-8 -*-
# GNU General Public License
# Telia Play KODI Addon
# Copyright (C) 2022 Mariusz89B
# 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 https://www.gnu.org/licenses.
# MIT License
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Disclaimer
# This add-on is unoffical and is not endorsed or supported by Telia Company AB in any way. Any trademarks used belong to their owning companies and organisations.
import sys
import os
import xbmc
import xbmcaddon
import xbmcgui
import xbmcplugin
import xbmcvfs
import urllib.parse as urlparse
from urllib.parse import urlencode, quote_plus, quote, unquote
from datetime import *
import requests
from requests.exceptions import HTTPError, ConnectionError, Timeout, RequestException
import iso8601
import re
import six
import time
import uuid
from ext import c_ext_info
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
params = dict(urlparse.parse_qsl(sys.argv[2][1:]))
addon = xbmcaddon.Addon(id='plugin.video.teliaplay')
exlink = params.get('url', '')
extitle = params.get('title', '')
exid = params.get('media_id', '')
excatchup = params.get('catchup', '')
exstart = params.get('start', '')
exend = params.get('end', '')
exlabels = params.get('info_labels', '')
profile_path = xbmcvfs.translatePath(addon.getAddonInfo('profile'))
localized = xbmcaddon.Addon().getLocalizedString
x_localized = xbmc.getLocalizedString
path = addon.getAddonInfo('path')
resources = os.path.join(path, 'resources')
icons = os.path.join(resources, 'icons')
thumb = os.path.join(path, 'icon.png')
poster = os.path.join(path, 'icon.png')
banner = os.path.join(resources, 'banner.jpg')
clearlogo = os.path.join(resources, 'clearlogo.png')
fanart = os.path.join(resources, 'fanart.jpg')
icon = os.path.join(path, 'icon.png')
live_icon = os.path.join(icons, 'live.png')
tv_icon = os.path.join(icons, 'tv.png')
vod_icon = os.path.join(icons, 'vod.png')
sport_icon = os.path.join(icons, 'sport.png')
kids_icon = os.path.join(icons, 'kids.png')
fav_icon = os.path.join(icons, 'fav.png')
search_icon = os.path.join(icons, 'search.png')
lock_icon = os.path.join(icons, 'lock.png')
settings_icon = os.path.join(icons, 'settings.png')
catchup_msg = addon.getSetting('teliaplay_play_beginning')
if catchup_msg == 'true':
play_beginning = True
else:
play_beginning = False
login = addon.getSetting('teliaplay_username').strip()
password = addon.getSetting('teliaplay_password').strip()
country = int(addon.getSetting('teliaplay_locale'))
base = ['https://teliatv.dk', 'https://www.teliaplay.se']
referer = ['https://teliatv.dk/', 'https://www.teliaplay.se/']
host = ['www.teliatv.dk', 'www.teliaplay.se']
cc = ['dk', 'se']
ca = ['DK', 'SE']
sess = requests.Session()
timeouts = (5, 5)
UA = xbmc.getUserAgent()
class proxydt(datetime):
@staticmethod
def strptime(date_string, format):
import time
try:
res = datetime.strptime(date_string, format)
except:
res = datetime(*(time.strptime(date_string, format)[0:6]))
return res
proxydt = proxydt
def build_url(query):
query = {k: v for k, v in query.items() if v != ''}
return base_url + '?' + urlencode(query)
def add_item(label, url, mode, folder, playable, media_id='', catchup='', start='', end='', plot='', thumb=None, poster=None, banner=None, clearlogo=None, icon=None, fanart=None, context_menu=None, item_count=None, info_labels=False, page=0):
if not info_labels:
info_labels = {'title': label}
title = info_labels.get('title')
list_item = xbmcgui.ListItem(label=title)
if playable:
list_item.setProperty('IsPlayable', 'true')
if context_menu:
info = x_localized(19047)
context_menu.insert(0, (info, 'Action(Info)'))
else:
list_item.setProperty('IsPlayable', 'false')
if context_menu:
list_item.addContextMenuItems(context_menu, replaceItems=True)
list_item.setInfo(type='Video', infoLabels=info_labels)
thumb = thumb if thumb else icon
poster = poster if poster else icon
banner = banner if banner else icon
clearlogo = clearlogo if clearlogo else icon
fanart = fanart if fanart else icon
if not icon:
icon = ''
list_item.setArt({'thumb': thumb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'clearlogo': clearlogo})
xbmcplugin.addDirectoryItem(
handle=addon_handle,
url=build_url({'title': title, 'mode': mode, 'url': url, 'media_id': media_id, 'catchup': catchup, 'start': start, 'end': end, 'info_labels': info_labels}),
listitem=list_item,
isFolder=folder)
def send_req(url, post=False, json=None, headers=None, data=None, params=None, cookies=None, verify=True, allow_redirects=False, timeout=None):
try:
if post:
response = sess.post(url, headers=headers, json=json, data=data, params=params, cookies=cookies, verify=verify, allow_redirects=allow_redirects, timeout=timeout)
else:
response = sess.get(url, headers=headers, json=json, data=data, params=params, cookies=cookies, verify=verify, allow_redirects=allow_redirects, timeout=timeout)
except HTTPError as e:
print('HTTPError: {}'.format(str(e)))
response = False
except ConnectionError as e:
print('ConnectionError: {}'.format(str(e)))
response = False
except Timeout as e:
print('Timeout: {}'.format(str(e)))
response = False
except RequestException as e:
print('RequestException: {}'.format(str(e)))
response = False
except:
xbmcgui.Dialog().notification(localized(30012), localized(30006))
response = False
return response
def create_data():
dashjs = str(uuid.uuid4())
addon.setSetting('teliaplay_devush', 'WEB-' + str(dashjs))
tv_client_boot_id = str(uuid.uuid4())
addon.setSetting('teliaplay_tv_client_boot_id', str(tv_client_boot_id))
timestamp = int(time.time())*1000
addon.setSetting('teliaplay_timestamp', str(timestamp))
sessionid = six.text_type(uuid.uuid4())
addon.setSetting('teliaplay_sess_id', str(sessionid))
return dashjs, tv_client_boot_id, timestamp, sessionid
def check_login():
login = True
valid_to = addon.getSetting('teliaplay_validto')
beartoken = addon.getSetting('teliaplay_beartoken')
refrtoken = addon.getSetting('teliaplay_refrtoken')
cookies = addon.getSetting('teliaplay_cookies')
refresh = refresh_timedelta(valid_to)
if not beartoken or refresh < timedelta(minutes=1):
login = login_data(reconnect=False)
return login
def refresh_timedelta(valid_to):
result = None
if 'Z' in str(valid_to):
valid_to = iso8601.parse_date(valid_to)
elif valid_to:
if 'T' in str(valid_to):
try:
date_time_format = '%Y-%m-%dT%H:%M:%S.%f+' + valid_to.split('+')[1]
except:
date_time_format = '%Y-%m-%dT%H:%M:%S.%f+' + valid_to.split('+')[0]
valid_to = datetime(*(time.strptime(valid_to, date_time_format)[0:6]))
timestamp = int(time.mktime(valid_to.timetuple()))
token_valid_to = datetime.fromtimestamp(int(timestamp))
else:
token_valid_to = valid_to
else:
token_valid_to = datetime.now()
result = token_valid_to - datetime.now()
return result
def login_service():
try:
login = False
dashjs = addon.getSetting('teliaplay_devush')
valid_to = addon.getSetting('teliaplay_validto')
if (dashjs == '' or valid_to == ''):
try:
msg = localized(30000)
xbmcgui.Dialog().ok(localized(30012), str(msg))
except:
pass
create_data()
login = login_data(reconnect=False)
else:
login = check_login()
return login
except Exception as ex:
print('login_service exception: {}'.format(ex))
addon.setSetting('teliaplay_devush', '')
xbmcgui.Dialog().notification(localized(30012), localized(30006))
return False
def login_data(reconnect, retry=0):
dashjs, tv_client_boot_id, timestamp, sessionid = create_data()
try:
url = 'https://log.tvoip.telia.com:6003/logstash'
headers = {
'host': 'log.tvoip.telia.com:6003',
'user-agent': UA,
'content-type': 'text/plain;charset=UTF-8',
'accept': '*/*',
'origin': base[country],
'referer': referer[country],
'accept-language': 'en-US,en;q=0.9',
}
data = {
'bootId': tv_client_boot_id,
'networkType': 'UNKNOWN',
'deviceId': dashjs,
'deviceType': 'WEB',
'model': 'unknown_model',
'productName': 'Microsoft Edge 101.0.1210.32',
'platformName': 'Windows',
'platformVersion': 'NT 10.0',
'nativeVersion': 'unknown_platformVersion',
'uiName': 'one-web-login',
'client': 'WEB',
'uiVersion': '1.35.0',
'environment': 'PROD',
'country': ca[country],
'brand': 'TELIA',
'logType': 'STATISTICS_HTTP',
'payloads': [{
'sequence': 1,
'timestamp': timestamp,
'level': 'ERROR',
'loggerId': 'telia-data-backend/System',
'message': 'Failed to get service status due to timeout after 1000 ms'
}]
}
response = send_req(url, post=True, headers=headers, json=data, verify=True, timeout=timeouts)
url = 'https://logingateway-telia.clientapi-prod.live.tv.telia.net/logingateway/rest/v1/authenticate'
headers = {
'accept': '*/*',
'accept-language': 'sv,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,pl;q=0.6,fr;q=0.5',
'dnt': '1',
'origin': 'https://login.teliaplay.{cc}'.format(cc=cc[country]),
'referer': 'https://login.teliaplay.{cc}/'.format(cc=cc[country]),
'user-agent': UA,
'x-country': ca[country],
}
params = {
'redirectUri': 'https://www.teliaplay.{cc}/'.format(cc=cc[country]),
}
data = {
'deviceId': dashjs,
'deviceType': 'WEB',
'password': password,
'username': login,
'whiteLabelBrand': 'TELIA',
}
response = send_req(url, post=True, headers=headers, json=data, params=params, verify=True, timeout=timeouts)
code = ''
if not response:
xbmcgui.Dialog().notification(localized(30012), localized(30006))
return False
j_response = response.json()
code = j_response['redirectUri'].replace('https://www.teliaplay.{cc}/?code='.format(cc=cc[country]), '')
url = 'https://logingateway-telia.clientapi-prod.live.tv.telia.net/logingateway/rest/v1/oauth/token'
headers = {
'accept-language': 'sv,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,pl;q=0.6,fr;q=0.5',
'dnt': '1',
'origin': base[country],
'referer': referer[country],
'user-agent': UA,
'x-country': ca[country],
'accept': 'application/json',
'tv-client-boot-id': tv_client_boot_id,
'tv-client-name': 'web',
}
params = {
'code': code,
}
response = send_req(url, post=True, params=params, headers=headers, timeout=timeouts)
if not response:
if reconnect and retry < 3:
retry += 1
login_data(reconnect=True, retry=retry)
else:
xbmcgui.Dialog().notification(localized(30012), localized(30007))
return False
j_response = response.json()
try:
if 'Username/password was incorrect' in j_response['errorMessage']:
xbmcgui.Dialog().notification(localized(30012), localized(30007))
return False
except:
pass
validTo = j_response.get('validTo', '')
addon.setSetting('teliaplay_validto', str(validTo))
beartoken = j_response.get('accessToken', '')
addon.setSetting('teliaplay_beartoken', str(beartoken))
refrtoken = j_response.get('refreshToken', '')
addon.setSetting('teliaplay_refrtoken', str(refrtoken))
url = 'https://ottapi.prod.telia.net/web/{cc}/tvclientgateway/rest/secure/v1/provision'.format(cc=cc[country])
headers = {
'host': 'ottapi.prod.telia.net',
'authorization': 'Bearer ' + beartoken,
'if-modified-since': '0',
'user-agent': UA,
'tv-client-boot-id': tv_client_boot_id,
'content-type': 'application/json',
'accept': '*/*',
'sec-GPC': '1',
'origin': base[country],
'referer': referer[country],
'accept-language': 'en-US,en;q=0.9',
}
data = {
'deviceId': dashjs,
'drmType': 'WIDEVINE',
'uiName': 'one-web',
'uiVersion': '1.43.0',
'nativeVersion': 'NT 10.0',
'model': 'windows_desktop',
'networkType': 'unknown',
'productName': 'Microsoft Edge 101.0.1210.32',
'platformName': 'Windows',
'platformVersion': 'NT 10.0',
}
response = send_req(url, post=True, headers=headers, json=data, verify=True, timeout=timeouts)
try:
response = response.json()
if response['errorCode'] == 61004:
print('errorCode 61004')
xbmcgui.Dialog().notification(localized(30012), localized(30013))
addon.setSetting('teliaplay_sess_id', '')
addon.setSetting('teliaplay_devush', '')
if reconnect and retry < 1:
retry += 1
login_data(reconnect=True, retry=retry)
else:
return False
elif response['errorCode'] == 9030:
print('errorCode 9030')
if not reconnect:
xbmcgui.Dialog().notification(localized(30012), localized(30006))
addon.setSetting('teliaplay_sess_id', '')
addon.setSetting('teliaplay_devush', '')
if reconnect and retry < 1:
retry += 1
login_data(reconnect=True, retry=retry)
else:
return False
elif response['errorCode'] == 61002:
print('errorCode 61002')
if not reconnect:
xbmcgui.Dialog().notification(localized(30012), localized(30006))
tv_client_boot_id = str(uuid.uuid4())
addon.setSetting('teliaplay_tv_client_boot_id', str(tv_client_boot_id))
if reconnect and retry < 1:
retry += 1
login_data(reconnect=True, retry=retry)
else:
return False
except:
pass
cookies = {}
cookies = sess.cookies
addon.setSetting('teliaplay_cookies', str(cookies))
url = 'https://ottapi.prod.telia.net/web/{cc}/tvclientgateway/rest/secure/v1/pubsub'.format(cc=cc[country])
headers = {
'user-agent': UA,
'accept': '*/*',
'accept-language': "sv,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,pl;q=0.6",
'authorization': 'Bearer ' + beartoken,
'tv-client-boot-id': tv_client_boot_id,
}
response = send_req(url, headers=headers, cookies=sess.cookies, allow_redirects=False, timeout=timeouts)
if not response:
if reconnect and retry < 3:
retry += 1
login_data(reconnect=True, retry=retry)
else:
return False
response = response.json()
usern = response['channels']['engagement']
addon.setSetting('teliaplay_usern', str(usern))
subtoken = response['config']['subscriberToken']
addon.setSetting('teliaplay_subtoken', str(subtoken))
return True
except Exception as ex:
print('login_data exception: {}'.format(ex))
return False
def video_on_demand():
login = check_login()
if not login:
login_data(reconnect=False)
add_item(label=localized(30030), url='', mode='vod_genre_movies', icon=icon, fanart=fanart, folder=True, playable=False)
add_item(label=localized(30031), url='', mode='vod_genre_series', icon=icon, fanart=fanart, folder=True, playable=False)
xbmcplugin.endOfDirectory(addon_handle)
def vod_genre(genre):
beartoken = addon.getSetting('teliaplay_beartoken')
tv_client_boot_id = addon.getSetting('teliaplay_tv_client_boot_id')
genres = []
url = 'https://graphql-telia.t6a.net/'
headers = {
'authorization': 'Bearer ' + beartoken,
'tv-client-name': 'androidmob',
'tv-client-version': '4.7.0',
'tv-client-boot-id': tv_client_boot_id,
'x-country': ca[country],
'content-type': 'application/json',
'accept-encoding': 'gzip',
'user-agent': 'okhttp/4.9.3',
}
json = {
'operationName': 'getCommonBrowsePage',
'variables': {
'mediaContentLimit': 60,
'pageId': genre
},
'query': 'query getCommonBrowsePage($pageId: String!, $mediaContentLimit: Int!) { page(id: $pageId) { id pagePanels { items { __typename title id ...MobileShowcasePanel ...MobileMediaPanel ...MobileSelectionMediaPanel ...MobileSingleFeaturePanel ...MobileStoresPanel } } } } fragment PlaybackSpec on PlaybackSpec { accessControl videoId videoIdType watchMode } fragment Vod on Vod { audioLang { name code } playbackSpec { __typename ...PlaybackSpec } price { readable } validFrom { timestamp readableDistance(type: FUZZY) } validTo { timestamp } } fragment Linear on PlaybackPlayLinear { item { startover { playbackSpec { __typename ...PlaybackSpec } } playbackSpec { __typename ...PlaybackSpec } startTime { timestamp readableDistance(type: FUZZY) } endTime { timestamp } } } fragment Rental on PlaybackPlayVodRental { item { __typename ...Vod } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) msTo } } } fragment Recording on PlaybackPlayRecording { item { playbackSpec { __typename ...PlaybackSpec } audioLang { name code } validFrom { timestamp } validTo { timestamp } } startover { playbackSpec { __typename ...PlaybackSpec } } } fragment SubscriptionProductStandard on SubscriptionProductStandard { id price { readable } } fragment SubscriptionProductDualEntry on SubscriptionProductDualEntry { id } fragment SubscriptionProductTVE on SubscriptionProductTVE { id } fragment SubscriptionProductFallback on SubscriptionProductFallback { id } fragment Playback on Playback { play { subscription { item { __typename ...Vod } } linear { __typename ...Linear } rental { __typename ...Rental } npvr { __typename ...Recording } } buy { subscriptions { item { __typename id name ...SubscriptionProductStandard ...SubscriptionProductDualEntry ...SubscriptionProductTVE ...SubscriptionProductFallback } } rental { item { price { readable } validFrom { timestamp } validTo { timestamp } } } npvr { __typename } } } fragment Store on Store { name icons { dark { sourceNonEncoded } } } fragment MobileShowcaseMovie on Movie { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } store { __typename ...Store } } fragment MobileShowcaseEpisode on Episode { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } series { id } store { __typename ...Store } } fragment MobileShowcaseSeries on Series { id title userData { favorite } images { backdrop16x9 { sourceNonEncoded } } webview { url } suggestedEpisode { id playback { __typename ...Playback } } store { __typename ...Store } } fragment MobileShowcaseSportEvent on SportEvent { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } store { __typename ...Store } } fragment ChannelPlayback on ChannelPlayback { play { playbackSpec { __typename ...PlaybackSpec } } buy { subscriptions { item { id } } } } fragment MobileShowcaseChannel on Channel { channelPlayback: playback { __typename ...ChannelPlayback } } fragment MobileShowcasePanel on ShowcasePanel { id title showcaseContent { items { id showcaseTitle { text } kicker images { showcase16x9 { sourceNonEncoded } showcase16x7 { sourceNonEncoded } showcase7x10 { sourceNonEncoded } showcase2x3 { sourceNonEncoded } } promotion { link { id type } content { __typename ...MobileShowcaseMovie ...MobileShowcaseEpisode ...MobileShowcaseSeries ...MobileShowcaseSportEvent ...MobileShowcaseChannel } } } } } fragment MobilePageMovie on Movie { id title playback { __typename ...Playback } images { backdrop16x9 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } } descriptionLong price { readable } genre yearProduction { number } ageRating { number } duration { readableShort } ratings { imdb { readableScore } } productionCountries userData { progress { percent position } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } store { name } availability { from { text } } availableNow labels { premiereAnnouncement { text } } } fragment MobilePageSeries on Series { id title images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } } description genre ageRating { number } ratings { imdb { readableScore } } label webview { url } isRentalSeries } fragment MobilePageEpisode on Episode { id title images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } screenshot16x9 { sourceNonEncoded } } descriptionLong price { readable } genre yearProduction { number } episodeNumber { number readable } seasonNumber { number readable } playback { __typename ...Playback } series { id title } ageRating { number } duration { readableShort } userData { progress { percent position } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } store { name } } fragment MobilePageSportEvent on SportEvent { id title playback { __typename ...Playback } images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } } availability { from { text timestamp } } descriptionLong genre badges { uhd { text } } productionCountries ageRating { number } duration { readableShort } store { name } league labels { airtime { text } } yearProduction { number } userData { progress { percent position } } venue } fragment MobilePageMediaPanelContent on MediaPanelItemContent { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } ... on Episode { __typename ...MobilePageEpisode } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileMediaPanel on MediaPanel { id title kicker displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } mediaContent(limit: $mediaContentLimit) { pageInfo { hasNextPage } items { media { __typename ...MobilePageMediaPanelContent } } } } fragment MobileSelectionMediaPanel on SelectionMediaPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } selectionMediaContent(config: { limit: $mediaContentLimit } ) { pageInfo { hasNextPage } items { media { __typename ...MobilePageMediaPanelContent } } } link { id type } } fragment MobileSingleFeaturePanelMedia on SingleFeaturePanelMedia { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileSingleFeaturePanel on SingleFeaturePanel { id title subtitle images { __typename ... on SingleFeaturePanelImages { promo16x9 { sourceNonEncoded } } } media { __typename ...MobileSingleFeaturePanelMedia } } fragment MobilePageStore on Store { id __typename name icons { light { sourceNonEncoded } dark { sourceNonEncoded } } } fragment MobileStoresPanel on StoresPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } storesContent(limit: $mediaContentLimit) { pageInfo { hasNextPage } items { __typename ...MobilePageStore } } }'
}
response = send_req(url, post=True, json=json, headers=headers)
if response:
j_response = response.json()
data = j_response['data']['page']['pagePanels']['items']
key = -1
for item in data:
key += 1
items = None
title = item['title']
selection = item.get('selectionMediaContent')
media = item.get('mediaContent')
stores = item.get('storesContent')
showcase = item.get('showcaseContent')
if selection:
items = selection.get('items')
elif media:
items = media.get('items')
elif showcase:
items = showcase.get('items')
if not title:
title = localized(30066)
elif stores:
items = stores.get('items')
if items:
genres.append((key, title))
for gen in genres:
add_item(label=gen[1], url=str(gen[0])+'|'+genre, mode='vod', icon=icon, fanart=fanart, folder=True, playable=False)
xbmcplugin.endOfDirectory(addon_handle)
def store(store_id):
idx = int(store_id.split('|')[0])
store = store_id.split('|')[-1]
beartoken = addon.getSetting('teliaplay_beartoken')
tv_client_boot_id = addon.getSetting('teliaplay_tv_client_boot_id')
url = 'https://graphql-telia.t6a.net/'
headers = {
'authorization': 'Bearer ' + beartoken,
'tv-client-name': 'androidmob',
'tv-client-version': '4.7.0',
'tv-client-boot-id': tv_client_boot_id,
'x-country': ca[country],
'content-type': 'application/json',
'accept-encoding': 'gzip',
'user-agent': 'okhttp/4.9.3',
}
json = {
'operationName': 'getMobileStore',
'variables': {
'mediaContentLimit': 60,
'id': store
},
'query': 'query getMobileStore($id: String!, $mediaContentLimit: Int!, $offset: Int) { store(id: $id) { id name pagePanels { items { __typename title id ...MobileSelectionMediaPanel ...MobileMediaPanel ...MobileStoresPanel ...MobileRentalsPanel ...MobileTimelinePanel ...MobileShowcasePanel ...MobileContinueWatchingPanel ...MobileMyListPanel ...MobilePageLinkPanel ...MobileSingleFeaturePanel } } } } fragment PlaybackSpec on PlaybackSpec { accessControl videoId videoIdType watchMode } fragment Vod on Vod { audioLang { name code } playbackSpec { __typename ...PlaybackSpec } price { readable } validFrom { timestamp readableDistance(type: FUZZY) } validTo { timestamp } } fragment Linear on PlaybackPlayLinear { item { startover { playbackSpec { __typename ...PlaybackSpec } } playbackSpec { __typename ...PlaybackSpec } startTime { timestamp readableDistance(type: FUZZY) } endTime { timestamp } } } fragment Rental on PlaybackPlayVodRental { item { __typename ...Vod } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) sTo } } } fragment Recording on PlaybackPlayRecording { item { playbackSpec { __typename ...PlaybackSpec } audioLang { name code } validFrom { timestamp } validTo { timestamp } } startover { playbackSpec { __typename ...PlaybackSpec } } } fragment DeepLink on DeepLink { uri serviceName googlePlayStoreId validFrom { timestamp } validTo { timestamp } } fragment SubscriptionProductStandard on SubscriptionProductStandard { id price { readable } } fragment SubscriptionProductDualEntry on SubscriptionProductDualEntry { id } fragment SubscriptionProductTVE on SubscriptionProductTVE { id } fragment SubscriptionProductFallback on SubscriptionProductFallback { id } fragment Playback on Playback { play { subscription { item { __typename ...Vod } } linear { __typename ...Linear } rental { __typename ...Rental } npvr { __typename ...Recording } deepLinks { item { __typename ...DeepLink } } } buy { subscriptions { item { __typename id name ...SubscriptionProductStandard ...SubscriptionProductDualEntry ...SubscriptionProductTVE ...SubscriptionProductFallback } } rental { item { price { readable } validFrom { timestamp } validTo { timestamp } } } npvr { item { playbackSpec { __typename ...PlaybackSpec } } } deepLinks { item { __typename ...DeepLink } } } } fragment MobilePageMovie on Movie { id title playback { __typename ...Playback } images { backdrop16x9 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } } descriptionLong price { readable } genre yearProduction { number } ageRating { readable } duration { readableShort } ratings { imdb { readableScore } } productionCountries userData { progress { percent position } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } store { name } availability { from { text } } availableNow labels { premiereAnnouncement { text } } } fragment MobilePageSeries on Series { id title images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } } description genre ageRating { readable } ratings { imdb { readableScore } } label webview { url } isRentalSeries } fragment MobilePageEpisode on Episode { id title images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } screenshot16x9 { sourceNonEncoded } } descriptionLong price { readable } genre yearProduction { number } episodeNumber { number readable } seasonNumber { number readable } playback { __typename ...Playback } series { id title } ageRating { readable } duration { readableShort } userData { progress { percent position } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } store { name } } fragment MobilePageSportEvent on SportEvent { id title playback { __typename ...Playback } images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } } availability { from { text timestamp } } descriptionLong genre badges { uhd { text } } productionCountries ageRating { readable } duration { readableShort } store { name } league labels { airtime { text } } yearProduction { number } userData { progress { percent position } } venue } fragment MobilePageMediaPanelContent on MediaPanelItemContent { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } ... on Episode { __typename ...MobilePageEpisode } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileSelectionMediaPanel on SelectionMediaPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } ... on DisplayHintList { listSubType } ... on DisplayHintGrid { gridSubType } } selectionMediaContent(config: { limit: $mediaContentLimit offset: $offset } ) { pageInfo { hasNextPage nextPageOffset } items { media { __typename ...MobilePageMediaPanelContent } } } link { id type } } fragment MobileMediaPanel on MediaPanel { id title kicker displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } ... on DisplayHintList { listSubType } ... on DisplayHintGrid { gridSubType } } mediaContent(limit: $mediaContentLimit, offset: $offset) { pageInfo { hasNextPage nextPageOffset } items { media { __typename ...MobilePageMediaPanelContent } } } } fragment MobilePageStore on Store { id __typename name icons { light { sourceNonEncoded } dark { sourceNonEncoded } } } fragment MobileStoresPanel on StoresPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } ... on DisplayHintGrid { gridSubType } ... on DisplayHintList { listSubType } } storesContent(limit: $mediaContentLimit, offset: $offset) { pageInfo { hasNextPage nextPageOffset } items { __typename ...MobilePageStore } } } fragment MobileRentalsPanelItemContent on RentalsPanelItemContent { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } } fragment MobileRentalsPanel on RentalsPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } rentalsContent(limit: $mediaContentLimit, offset: $offset) { pageInfo { hasNextPage nextPageOffset } items { media { __typename ...MobileRentalsPanelItemContent } } } } fragment MobileTimeLinePanelItemContent on TimelinePanelItemContent { __typename ... on Movie { __typename ...MobilePageMovie } ... on Episode { __typename ...MobilePageEpisode } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileTimelinePanel on TimelinePanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } timelineContent(limit: $mediaContentLimit, offset: $offset) { pageInfo { hasNextPage nextPageOffset } items { media { __typename ...MobileTimeLinePanelItemContent } startTime { timestamp isoString } endTime { timestamp isoString } } } } fragment Store on Store { name icons { dark { sourceNonEncoded } } } fragment MobileShowcaseMovie on Movie { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } store { __typename ...Store } } fragment MobileShowcaseEpisode on Episode { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } series { id } store { __typename ...Store } } fragment MobileShowcaseSeries on Series { id title userData { favorite } images { backdrop16x9 { sourceNonEncoded } } webview { url } suggestedEpisode { id playback { __typename ...Playback } } store { __typename ...Store } } fragment MobileShowcaseSportEvent on SportEvent { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } store { __typename ...Store } } fragment ChannelPlayback on ChannelPlayback { play { playbackSpec { __typename ...PlaybackSpec } } buy { subscriptions { item { id } } } } fragment MobileShowcaseChannel on Channel { channelPlayback: playback { __typename ...ChannelPlayback } } fragment MobileShowcasePanel on ShowcasePanel { id title showcaseContent { items { id showcaseTitle { text } kicker images { showcase16x9 { sourceNonEncoded } showcase16x7 { sourceNonEncoded } showcase7x10 { sourceNonEncoded } showcase2x3 { sourceNonEncoded } } promotion { link { id type } content { __typename ...MobileShowcaseMovie ...MobileShowcaseEpisode ...MobileShowcaseSeries ...MobileShowcaseSportEvent ...MobileShowcaseChannel } } } } } fragment MobileContinueWatchingPanelItemContent on ContinueWatchingPanelItemContent { __typename ... on Movie { __typename ...MobilePageMovie } ... on Episode { __typename ...MobilePageEpisode } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileContinueWatchingPanel on ContinueWatchingPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } continueWatchingContent { items { media { __typename ...MobileContinueWatchingPanelItemContent } } } } fragment MobileMyListPanelItemContent on MyListPanelItemContent { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileMyListPanel on MyListPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } myListContent(limit: $mediaContentLimit) { pageInfo { hasNextPage nextPageOffset } items { media { __typename ...MobileMyListPanelItemContent } } } } fragment MobilePageLinkPanel on PageLinkPanel { id title pageLinkContent { items { id name description type images { icon1x1 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } } } } } fragment MobileSingleFeaturePanelMedia on SingleFeaturePanelMedia { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileSingleFeaturePanel on SingleFeaturePanel { id title subtitle images { __typename ... on SingleFeaturePanelImages { promo16x9 { sourceNonEncoded } } } media { __typename ...MobileSingleFeaturePanelMedia } }'
}
response = send_req(url, post=True, json=json, headers=headers)
if response:
j_response = response.json()
try:
data = j_response['data']['store']['pagePanels']['items'][idx]
items = None
selection = data.get('selectionMediaContent')
media = data.get('mediaContent')
stores = data.get('storesContent')
showcase = data.get('showcaseContent')
if selection:
items = selection.get('items')
elif media:
items = media.get('items')
elif showcase:
items = showcase.get('items')
elif stores:
items = stores.get('items')
if not items:
xbmcgui.Dialog().notification(localized(30012), localized(30048))
return
get_items(items)
except Exception as ex:
print('vod Exception: {}'.format(ex))
xbmcgui.Dialog().notification(localized(30012), localized(30048))
return
def vod(genre_id):
idx = int(genre_id.split('|')[0])
genre = genre_id.split('|')[-1]
beartoken = addon.getSetting('teliaplay_beartoken')
tv_client_boot_id = addon.getSetting('teliaplay_tv_client_boot_id')
url = 'https://graphql-telia.t6a.net/'
headers = {
'authorization': 'Bearer ' + beartoken,
'tv-client-name': 'androidmob',
'tv-client-version': '4.7.0',
'tv-client-boot-id': tv_client_boot_id,
'x-country': ca[country],
'content-type': 'application/json',
'accept-encoding': 'gzip',
'user-agent': 'okhttp/4.9.3',
}
json = {
'operationName': 'getCommonBrowsePage',
'variables': {
'mediaContentLimit': 60,
'pageId': genre
},
'query': 'query getCommonBrowsePage($pageId: String!, $mediaContentLimit: Int!) { page(id: $pageId) { id pagePanels { items { __typename title id ...MobileShowcasePanel ...MobileMediaPanel ...MobileSelectionMediaPanel ...MobileSingleFeaturePanel ...MobileStoresPanel } } } } fragment PlaybackSpec on PlaybackSpec { accessControl videoId videoIdType watchMode } fragment Vod on Vod { audioLang { name code } playbackSpec { __typename ...PlaybackSpec } price { readable } validFrom { timestamp readableDistance(type: FUZZY) } validTo { timestamp } } fragment Linear on PlaybackPlayLinear { item { startover { playbackSpec { __typename ...PlaybackSpec } } playbackSpec { __typename ...PlaybackSpec } startTime { timestamp readableDistance(type: FUZZY) } endTime { timestamp } } } fragment Rental on PlaybackPlayVodRental { item { __typename ...Vod } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) msTo } } } fragment Recording on PlaybackPlayRecording { item { playbackSpec { __typename ...PlaybackSpec } audioLang { name code } validFrom { timestamp } validTo { timestamp } } startover { playbackSpec { __typename ...PlaybackSpec } } } fragment SubscriptionProductStandard on SubscriptionProductStandard { id price { readable } } fragment SubscriptionProductDualEntry on SubscriptionProductDualEntry { id } fragment SubscriptionProductTVE on SubscriptionProductTVE { id } fragment SubscriptionProductFallback on SubscriptionProductFallback { id } fragment Playback on Playback { play { subscription { item { __typename ...Vod } } linear { __typename ...Linear } rental { __typename ...Rental } npvr { __typename ...Recording } } buy { subscriptions { item { __typename id name ...SubscriptionProductStandard ...SubscriptionProductDualEntry ...SubscriptionProductTVE ...SubscriptionProductFallback } } rental { item { price { readable } validFrom { timestamp } validTo { timestamp } } } npvr { __typename } } } fragment Store on Store { name icons { dark { sourceNonEncoded } } } fragment MobileShowcaseMovie on Movie { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } store { __typename ...Store } } fragment MobileShowcaseEpisode on Episode { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } series { id } store { __typename ...Store } } fragment MobileShowcaseSeries on Series { id title userData { favorite } images { backdrop16x9 { sourceNonEncoded } } webview { url } suggestedEpisode { id playback { __typename ...Playback } } store { __typename ...Store } } fragment MobileShowcaseSportEvent on SportEvent { id title userData { progress { position } favorite } images { backdrop16x9 { sourceNonEncoded } } playback { __typename ...Playback } store { __typename ...Store } } fragment ChannelPlayback on ChannelPlayback { play { playbackSpec { __typename ...PlaybackSpec } } buy { subscriptions { item { id } } } } fragment MobileShowcaseChannel on Channel { channelPlayback: playback { __typename ...ChannelPlayback } } fragment MobileShowcasePanel on ShowcasePanel { id title showcaseContent { items { id showcaseTitle { text } kicker images { showcase16x9 { sourceNonEncoded } showcase16x7 { sourceNonEncoded } showcase7x10 { sourceNonEncoded } showcase2x3 { sourceNonEncoded } } promotion { link { id type } content { __typename ...MobileShowcaseMovie ...MobileShowcaseEpisode ...MobileShowcaseSeries ...MobileShowcaseSportEvent ...MobileShowcaseChannel } } } } } fragment MobilePageMovie on Movie { id title playback { __typename ...Playback } images { backdrop16x9 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } } descriptionLong price { readable } genre yearProduction { number } ageRating { number } duration { readableShort } ratings { imdb { readableScore } } productionCountries userData { progress { percent position } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } store { name } availability { from { text } } availableNow labels { premiereAnnouncement { text } } } fragment MobilePageSeries on Series { id title images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } } description genre ageRating { number } ratings { imdb { readableScore } } label webview { url } isRentalSeries } fragment MobilePageEpisode on Episode { id title images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } screenshot16x9 { sourceNonEncoded } } descriptionLong price { readable } genre yearProduction { number } episodeNumber { number readable } seasonNumber { number readable } playback { __typename ...Playback } series { id title } ageRating { number } duration { readableShort } userData { progress { percent position } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } store { name } } fragment MobilePageSportEvent on SportEvent { id title playback { __typename ...Playback } images { backdrop16x9 { sourceNonEncoded } showcard2x3 { sourceNonEncoded } showcard16x9 { sourceNonEncoded } } availability { from { text timestamp } } descriptionLong genre badges { uhd { text } } productionCountries ageRating { number } duration { readableShort } store { name } league labels { airtime { text } } yearProduction { number } userData { progress { percent position } } venue } fragment MobilePageMediaPanelContent on MediaPanelItemContent { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } ... on Episode { __typename ...MobilePageEpisode } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileMediaPanel on MediaPanel { id title kicker displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } mediaContent(limit: $mediaContentLimit) { pageInfo { hasNextPage } items { media { __typename ...MobilePageMediaPanelContent } } } } fragment MobileSelectionMediaPanel on SelectionMediaPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } selectionMediaContent(config: { limit: $mediaContentLimit } ) { pageInfo { hasNextPage } items { media { __typename ...MobilePageMediaPanelContent } } } link { id type } } fragment MobileSingleFeaturePanelMedia on SingleFeaturePanelMedia { __typename ... on Movie { __typename ...MobilePageMovie } ... on Series { __typename ...MobilePageSeries } ... on SportEvent { __typename ...MobilePageSportEvent } } fragment MobileSingleFeaturePanel on SingleFeaturePanel { id title subtitle images { __typename ... on SingleFeaturePanelImages { promo16x9 { sourceNonEncoded } } } media { __typename ...MobileSingleFeaturePanelMedia } } fragment MobilePageStore on Store { id __typename name icons { light { sourceNonEncoded } dark { sourceNonEncoded } } } fragment MobileStoresPanel on StoresPanel { id title displayHint { __typename ... on DisplayHintSwimlane { swimlaneSubType } } storesContent(limit: $mediaContentLimit) { pageInfo { hasNextPage } items { __typename ...MobilePageStore } } }'
}
response = send_req(url, post=True, json=json, headers=headers)
if response:
j_response = response.json()
try:
data = j_response['data']['page']['pagePanels']['items'][idx]
items = None
selection = data.get('selectionMediaContent')
media = data.get('mediaContent')
stores = data.get('storesContent')
showcase = data.get('showcaseContent')
if selection:
items = selection.get('items')
elif media:
items = media.get('items')
elif showcase:
items = showcase.get('items')
elif stores:
items = stores.get('items')
if not items:
xbmcgui.Dialog().notification(localized(30012), localized(30048))
return
get_items(items)
except Exception as ex:
print('vod Exception: {}'.format(ex))
xbmcgui.Dialog().notification(localized(30012), localized(30048))
return
def get_items(data, mode=None, thumb=thumb, poster=poster, banner=banner, clearlogo=clearlogo, icon=icon, fanart=fanart):
titles = set()
count = 0
for item in data:
media = item.get('media')
if not media:
media = item
if media:
media_id = None
typename = media.get('__typename')
promo = media.get('promotion')
if promo:
content = promo.get('content')
if content:
media_id = content.get('id')
typename = content.get('__typename')
type_ = media.get('type')
url = 'vod'
if typename == 'Movie':
mode = 'play'
folder = False
playable = True
elif typename == 'Series':
mode = 'seasons'
folder = True
playable = False
elif typename == 'SportEvent':
mode = 'play'
folder = False
playable = True
elif typename == 'Store':
mode = 'vod_store'
folder = True
playable = False
else:
folder = True
playable = False
if not mode:
mode = 'play'
folder = False
playable = True
label = media.get('title')
if not label:
label = media.get('name')
if not label:
showcase_title = media.get('showcaseTitle')
if showcase_title:
label = showcase_title.get('text')
genre = media.get('genre')
title = label
timestamp = None
start = item.get('startTime')
if start:
timestamp = start.get('timestamp')
else:
availability = media.get('availability')
if availability:
start = availability
if start:
fr = start.get('from')
if fr:
timestamp = fr.get('timestamp')
if isinstance(timestamp, int):
start_time = timestamp // 1000
dt_start = datetime.fromtimestamp(start_time)
if os.name == 'nt':
da_start = dt_start.strftime('%A %#d/%#m %H:%M')
else:
da_start = dt_start.strftime('%A %-d/%-m %H:%M')
if da_start != '00:00':
title = label + ' [COLOR grey]({0})[/COLOR]'.format(da_start)
outline = media.get('description')
plot = media.get('descriptionLong')
if not plot:
plot = outline
date = ''
year = media.get('yearProduction')
if year:
date = year.get('readable')
age = ''
age_rating = media.get('ageRating')
if age_rating:
age = age_rating.get('readable')
rating = ''
ratings = media.get('ratings')
if ratings:
imdb = ratings.get('imdb')
if imdb:
rating = imdb.get('readableScore')
duration = ''
d = media.get('duration')
if d:
duration = d.get('seconds')
if not media_id:
media_id = media.get('id')
playback = media.get('playback')
if playback:
play = playback.get('play')
linear = play.get('linear')
if linear:
item = linear.get('item')
media_id = item['playbackSpec']['videoId']
rental = play.get('rental')
if rental:
for item in rental:
media_id = item['item']['playbackSpec']['videoId']
subscription = play.get('subscription')
if subscription:
for item in subscription:
media_id = item['item']['playbackSpec']['videoId']
images = media.get('images')
if images:
card_1x1 = images.get('icon1x1') if images.get('icon1x1') else images.get('icon1x1')
if card_1x1:
src = card_1x1.get('sourceNonEncoded')
if not src:
src = card_1x1.get('source')
if src:
poster = unquote(src)
else:
poster = fanart
card_2x3 = images.get('showcard2x3') if images.get('showcard2x3') else images.get('showcase2x3')
if card_2x3:
src = card_2x3.get('sourceNonEncoded')
if not src:
src = card_2x3.get('source')
if src:
poster = unquote(src)
else:
poster = fanart
card_16x9 = images.get('showcard16x9') if images.get('showcard16x9') else images.get('showcase16x9')
if card_16x9:
src = card_16x9.get('sourceNonEncoded')
if not src:
src = card_16x9.get('source')
if src:
poster = unquote(src)
else:
poster = fanart
else:
icons = media.get('icons')
if icons:
poster = icons.get('dark').get('sourceNonEncoded')
plot = typename
else:
poster = fanart
ext = localized(30027)
context_menu = [('{0}'.format(ext), 'RunScript(plugin.video.teliaplay,0,?mode=ext,label={0})'.format(title))]
#xbmcplugin.addSortMethod(addon_handle, sortMethod=xbmcplugin.SORT_METHOD_TITLE, label2Mask = "%R, %Y, %P")
if title not in titles:
count += 1
add_item(label=label, url=url, mode=mode, media_id=media_id, folder=folder, playable=playable, info_labels={'title': title, 'sorttitle': title, 'originaltitle': title, 'plot': plot, 'plotoutline': outline, 'aired': date, 'dateadded': date, 'duration': duration, 'genre': genre, 'userrating': rating, 'mpaa': age}, icon=icon, poster=poster, fanart=fanart, context_menu=context_menu, item_count=count)
titles.add(title)
xbmcplugin.setContent(addon_handle, 'sets')
xbmcplugin.endOfDirectory(addon_handle)
def vod_seasons(media_id):
beartoken = addon.getSetting('teliaplay_beartoken')
tv_client_boot_id = addon.getSetting('teliaplay_tv_client_boot_id')
url = 'https://graphql-telia.t6a.net/'
headers = {
'authorization': 'Bearer ' + beartoken,
'tv-client-name': 'androidmob',
'tv-client-version': '4.7.0',
'tv-client-boot-id': tv_client_boot_id,
'x-country': ca[country],
'content-type': 'application/json',
'accept-encoding': 'gzip',
'user-agent': 'okhttp/4.9.3',
}
json = {
'operationName': 'getMobileSeries',
'variables': {
'id': media_id
},
'query': 'query getMobileSeries($id: String!) { series(id: $id) { __typename ...MobileSeriesDetailsItem } } fragment PlaybackSpec on PlaybackSpec { accessControl videoId videoIdType watchMode } fragment Vod on Vod { audioLang { name code } playbackSpec { __typename ...PlaybackSpec } price { readable } validFrom { timestamp readableDistance(type: FUZZY) } validTo { timestamp } } fragment Linear on PlaybackPlayLinear { item { startover { playbackSpec { __typename ...PlaybackSpec } } playbackSpec { __typename ...PlaybackSpec } startTime { timestamp readableDistance(type: FUZZY) } endTime { timestamp } } } fragment Rental on PlaybackPlayVodRental { item { __typename ...Vod } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) msTo } } } fragment Recording on PlaybackPlayRecording { item { playbackSpec { __typename ...PlaybackSpec } audioLang { name code } validFrom { timestamp } validTo { timestamp } } startover { playbackSpec { __typename ...PlaybackSpec } } } fragment SubscriptionProductStandard on SubscriptionProductStandard { id price { readable } } fragment SubscriptionProductDualEntry on SubscriptionProductDualEntry { id } fragment SubscriptionProductTVE on SubscriptionProductTVE { id } fragment SubscriptionProductFallback on SubscriptionProductFallback { id } fragment Playback on Playback { play { subscription { item { __typename ...Vod } } linear { __typename ...Linear } rental { __typename ...Rental } npvr { __typename ...Recording } } buy { subscriptions { item { __typename id name ...SubscriptionProductStandard ...SubscriptionProductDualEntry ...SubscriptionProductTVE ...SubscriptionProductFallback } } rental { item { price { readable } validFrom { timestamp } validTo { timestamp } } } npvr { __typename } } } fragment MobileSuggestedEpisode on Episode { id title descriptionLong seasonNumber { number } availability { to { text } } directors actors vignette { hero16x9 { mpeg4 { url } webm { url } } } episodeNumber { number } playback { __typename ...Playback } userData { progress { position percent } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } duration { readableShort } price { readable } images { showcard2x3 { sourceNonEncoded } screenshot16x9 { sourceNonEncoded } } } fragment MobileUpcomingEpisode on UpcomingEpisode { id title episodeNumber { number } seasonNumber { readable } availability { from { text } } availability { from { text } } images { backdrop16x9 { sourceNonEncoded } } duration { readableShort } } fragment MobileSeriesDetailsItem on Series { id title images { backdrop16x9 { sourceNonEncoded } } genre ageRating { readable number } ratings { imdb { readableScore url } } description actors userData { favorite } suggestedEpisode { __typename ...MobileSuggestedEpisode } label numberOfEpisodes { number } numberOfSeasons { number } vignette { hero16x9 { mpeg4 { url } webm { url } } } store { name } seasonLinks { items { id numberOfEpisodes { number readable } seasonNumber { number readable } } } upcomingEpisode { __typename ...MobileUpcomingEpisode } isRentalSeries }'
}
response = send_req(url, post=True, json=json, headers=headers)
if response:
j_response = response.json()
try:
seasons = j_response['data']['series']['seasonLinks']['items']
except Exception as ex:
print('vod seasons Exception: {}'.format(ex))
xbmcgui.Dialog().notification(localized(30012), localized(30048))
return
for item in seasons:
season_id = item['id']
json = {
'operationName': 'GetMobileSeason',
'variables': {
'id': season_id,
'limit': 300,
'offset': 0
},
'query': 'query GetMobileSeason($id: String!, $limit: Int!, $offset: Int!) { season(seasonId: $id) { seasonNumber { readable number } id episodes(limit: $limit, offset: $offset) { __typename ...MobileSeasonEpisode } } } fragment PlaybackSpec on PlaybackSpec { accessControl videoId videoIdType watchMode } fragment Vod on Vod { audioLang { name code } playbackSpec { __typename ...PlaybackSpec } price { readable } validFrom { timestamp readableDistance(type: FUZZY) } validTo { timestamp } } fragment Linear on PlaybackPlayLinear { item { startover { playbackSpec { __typename ...PlaybackSpec } } playbackSpec { __typename ...PlaybackSpec } startTime { timestamp readableDistance(type: FUZZY) } endTime { timestamp } } } fragment Rental on PlaybackPlayVodRental { item { __typename ...Vod } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) msTo } } } fragment Recording on PlaybackPlayRecording { item { playbackSpec { __typename ...PlaybackSpec } audioLang { name code } validFrom { timestamp } validTo { timestamp } } startover { playbackSpec { __typename ...PlaybackSpec } } } fragment SubscriptionProductStandard on SubscriptionProductStandard { id price { readable } } fragment SubscriptionProductDualEntry on SubscriptionProductDualEntry { id } fragment SubscriptionProductTVE on SubscriptionProductTVE { id } fragment SubscriptionProductFallback on SubscriptionProductFallback { id } fragment Playback on Playback { play { subscription { item { __typename ...Vod } } linear { __typename ...Linear } rental { __typename ...Rental } npvr { __typename ...Recording } } buy { subscriptions { item { __typename id name ...SubscriptionProductStandard ...SubscriptionProductDualEntry ...SubscriptionProductTVE ...SubscriptionProductFallback } } rental { item { price { readable } validFrom { timestamp } validTo { timestamp } } } npvr { __typename } } } fragment MobileSeasonEpisode on Episodes { episodeItems { id title descriptionLong genre duration { seconds readableShort } images { showcard2x3 { sourceNonEncoded } screenshot16x9 { sourceNonEncoded } } availability { from { text timestamp } to { text } } downloadAvailable seasonNumber { number } episodeNumber { number readable } price { readable } playback { __typename ...Playback } userData { progress { position percent } rentalInfo { endTime { readableDistance(type: HOURS_OR_MINUTES) } } } } }'
}
response = send_req(url, post=True, json=json, headers=headers)
if response:
j_response = response.json()
season = j_response['data']['season']['seasonNumber']['number']
label = localized(30033) + ' ' + str(season)
add_item(label=label, url=season, mode='episodes', media_id=season_id, playable=False, folder=True, icon=icon, fanart=fanart)
xbmcplugin.endOfDirectory(addon_handle)
def vod_episodes(season, season_id):
beartoken = addon.getSetting('teliaplay_beartoken')
tv_client_boot_id = addon.getSetting('teliaplay_tv_client_boot_id')