From b795c160c25354f9dc73b823cb14a690cdb11e6c Mon Sep 17 00:00:00 2001 From: Mariusz89B Date: Sun, 5 Mar 2023 10:41:04 +0100 Subject: [PATCH] v2.4.3_v3 --- addon.xml | 4 +- changelog.txt | 2 +- resources/lib/addon.py | 14 ++- resources/lib/viaplay.py | 207 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 211 insertions(+), 16 deletions(-) diff --git a/addon.xml b/addon.xml index fd11cc1..b7cd29d 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@  - + @@ -24,7 +24,7 @@ all GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 and MIT LICENSE. https://github.com/Mariusz89B/plugin.video.viaplay - v2.4.3 (2023-02-26) + v2.4.3 (2023-03-05) - Added profile selector. - Added supported countries. diff --git a/changelog.txt b/changelog.txt index 11da5cc..e500d0a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,4 @@ -v2.4.3 (2023-02-26) +v2.4.3 (2023-03-05) - Added profile selector. - Added supported countries. diff --git a/resources/lib/addon.py b/resources/lib/addon.py index df70ace..764ce23 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -222,7 +222,7 @@ def watched(guid, program=False): 'guid': guid, } - response = helper.vp.make_request(url='https://play.viaplay.{0}/api/stream/byguid'.format(helper.vp.country), method='get', params=params) + response = helper.vp.make_request(url=helper.vp.play_api + '/api/stream/byguid', method='get', params=params) params = { 'profileId': response['socket']['userId'], @@ -238,7 +238,7 @@ def watched(guid, program=False): helper.dialog(dialog_type='notification', heading=helper.language(30017), message=message) return - url = 'https://content.viaplay.{0}/pcdash-{0}/deleteAllProgress/default/{1}/{2}'.format(helper.vp.country, program_guid, helper.vp.get_user_id()['id']) + url = helper.vp.base_url + '/deleteAllProgress/default/{0}/{1}'.format(program_guid, helper.vp.get_user_id()['id']) params = { 'profileId': helper.vp.get_setting('profileid'), @@ -305,7 +305,7 @@ def favourite(guid, program=False, remove=False): 'guid': guid, } - response = helper.vp.make_request(url='https://play.viaplay.{0}/api/stream/byguid'.format(helper.vp.country), method='get', params=params) + response = helper.vp.make_request(url=helper.vp.play_api + '/stream/byguid', method='get', params=params) params = { 'profileId': response['socket']['userId'], @@ -327,7 +327,7 @@ def favourite(guid, program=False, remove=False): 'action': 'remove', } - response = helper.vp.make_request(url='https://content.viaplay.{0}/pcdash-{0}/myList'.format(helper.vp.country), method='put', params=params, payload=json_data, status=True) + response = helper.vp.make_request(url=helper.vp.base_url + '/myList', method='put', params=params, payload=json_data, status=True) xbmc.executebuiltin('Container.Refresh') @@ -340,7 +340,7 @@ def favourite(guid, program=False, remove=False): 'action': 'add', } - response = helper.vp.make_request(url='https://content.viaplay.{0}/pcdash-{0}/myList'.format(helper.vp.country), method='put', params=params, payload=json_data, status=True) + response = helper.vp.make_request(url=helper.vp.base_url + '/myList', method='put', params=params, payload=json_data, status=True) message = helper.language(30071) helper.dialog(dialog_type='notification', heading=helper.language(30017), message=message) @@ -361,8 +361,6 @@ def generate_m3u(): data = '#EXTM3U\n' - country_code = helper.get_country_code() - tld = helper.get_tld() country_id = helper.get_setting('site') if country_id == '0': chann = 'kanaler' @@ -375,7 +373,7 @@ def generate_m3u(): elif country_id == '4': chann = 'channels' - url = 'https://content.viaplay.{c1}/xdk-{c2}/{chann}'.format(c1=tld, c2=country_code, chann=chann) + url = helper.vp.base_url + '/{0}'.format(chann) response = helper.vp.make_request(url=url, method='get') channels_block = response['_embedded']['viaplay:blocks'][0]['_embedded']['viaplay:blocks'] diff --git a/resources/lib/viaplay.py b/resources/lib/viaplay.py index 91ce245..f483fed 100644 --- a/resources/lib/viaplay.py +++ b/resources/lib/viaplay.py @@ -55,10 +55,13 @@ def __init__(self, settings_folder, country, debug=False): os.makedirs(self.tempdir) self.deviceid_file = os.path.join(settings_folder, 'deviceId') self.http_session = requests.Session() - self.device_key = 'xdk-%s' % self.country + self.device_key = 'xdk-{0}'.format(self.country) self.profile_url = 'https://viaplay.mtg-api.com' self.base_url = 'https://content.viaplay.{0}/{1}'.format(self.tld, self.device_key) - self.login_api = 'https://login.viaplay.%s/api' % self.tld + self.cronos_url = 'https://cronos-events.viaplay.{0}'.format(self.tld) + self.socket_url = 'https://socket.viaplay.{0}'.format(self.tld) + self.play_api = 'https://play.viaplay.{0}/api'.format(self.tld) + self.login_api = 'https://login.viaplay.{0}/api'.format(self.tld) try: self.cookie_jar.load(ignore_discard=True, ignore_expires=True) @@ -152,13 +155,13 @@ def parse_url(self, url): return url - def make_request(self, url, method, params=None, payload=None, headers=None, status=False): + def make_request(self, url, method, params=None, payload=None, headers=None, profile=True, status=False): """Make an HTTP request. Return the response.""" if not params: params = {} id = self.get_setting('profileid') - if id: + if id and profile: params['profileId'] = id try: @@ -341,7 +344,7 @@ def get_stream(self, guid, pincode=None, tve='false', url=''): 'deviceName': 'web', 'deviceType': 'pc', 'userAgent': 'Kodi', - 'deviceKey': 'chromecast-{cc}'.format(cc=self.country), + 'deviceKey': 'chromecast-{0}'.format(country_code), #'guid': guid 'mediaGuid': guid } @@ -353,6 +356,200 @@ def get_stream(self, guid, pincode=None, tve='false', url=''): data = self.make_request(url=url, method='get', params=params) + print('TEST0') + print(data) + + title = data['product']['content']['title'] + + session_guid = data['cseReporting']['sessionGuid'] + + house_id = data['product']['system']['guid'] + corr_id = data['cseReporting']['data']['correlationId'] + + url = self.cronos_url + '/cronos-events/session/viaplay/xdk/5.54.1' + + response = self.make_request(url=url, method='get', status=True) + + session = response['data']['sessionId'] + + url = self.cronos_url + '/cronos-events/event/viaplay/{0}/5.54.1/11/view_displayed_content'.format(self.device_key) + + params = { + 'sessionId': session, + } + + """ + payload = { + 'contentDataArray': [ + { + 'availability': 'available', + 'context': 'view', + 'creatives': [ + 'no-background-type', + 'no-background', + 'page', + 'x-large' + ], + 'houseId': house_id, + 'position': 2, + 'price': 0, + 'title': title, + 'types': [ + 'SVOD' + ] + } + ], + 'deviceData': { + 'architecture': 'ranchu', + 'category': 'Mobile', + 'country': country_code.upper(), + 'key': self.device_key, + 'manufacturer': 'google', + 'name': 'sdk_gphone_x86', + 'os': 'Android', + 'osVersion': '11', + 'package': 'com.viaplay.android', + 'year': '2020' + }, + 'environmentData': { + 'currency': 'EUR', + 'environment': 'production', + 'language': 'en', + 'market': country_code.upper(), + 'name': 'com.viaplay.android', + 'touchPoint': 'android', + 'variant': 'default', + 'version': '5.54.1' + }, + 'experimentDataArray': [ + 'gradual_rollouts.client_side_logging', + 'kids', + 'start_page' + ], + 'pageData': { + 'title': 'Player', + 'type': 'player' + }, + 'profileData': { + 'id': self.get_setting('profileid'), + 'type': 'adult' + }, + 'sectionData': { + 'id': 'player', + 'name': 'player' + }, + 'stateData': { + 'locale': 'en_US', + 'resolution': '411x659' + }, + 'streamData': { + 'offline': False, + 'progress': 0, + 'sessionGuid': session_guid, + 'startMethod': 'manual', + 'state': 'default' + }, + 'userData': { + 'loggedIn': True, + 'userId': self.get_user_id()['id'] + }, + 'viewData': { + 'title': 'Player', + 'type': 'player', + 'virtual': True + } + } + """ + + payload = { + 'contentDataArray':[ + { + 'availability':'available', + 'context':'view', + 'creatives':[ + 'promo', + 'dynamic-background', + 'page', + 'x-large' + ], + 'houseId':house_id, + 'position':2, + 'price':0, + 'title': title, + 'types':[ + 'SVOD' + ] + } + ], + 'deviceData':{ + 'architecture':'ranchu', + 'category':'Mobile', + 'country': country_code.upper(), + 'key': self.device_key, + 'manufacturer':'google', + 'name':'sdk_gphone_x86', + 'os':'Android', + 'osVersion':'11', + 'package':'com.viaplay.android', + 'year':'2020' + }, + 'environmentData':{ + 'currency':'EUR', + 'environment':'production', + 'language':'en', + 'market': country_code.upper(), + 'name':'com.viaplay.android', + 'touchPoint':'android', + 'variant':'default', + 'version':'5.54.1' + }, + 'experimentDataArray':[ + 'gradual_rollouts.client_side_logging', + 'kids', + 'start_page' + ], + 'pageData':{ + 'title':'Filmy', + 'type':'product' + }, + 'profileData':{ + 'id': self.get_setting('profileid'), + 'type':'adult' + }, + 'sectionData':{ + 'id': corr_id, + 'name':'movie' + }, + 'stateData':{ + 'locale':'en_US', + 'resolution':'411x659' + }, + 'userData':{ + 'loggedIn':True, + 'userId':self.get_user_id()['id'] + }, + 'viewContentData':{ + 'availability':'available', + 'context':'view', + 'creatives':[ + 'promo', + 'dynamic-background', + 'page', + 'x-large' + ], + 'houseId': house_id, + 'position':2, + 'price':0, + 'title': title + } + } + + response = self.make_request(url=url, method='post', payload=payload, params=params, profile=False, status=True) + + print('TEST1') + print(payload) + print(response) + if 'viaplay:media' in data['_links']: mpd_url = data['_links']['viaplay:media']['href'] elif 'viaplay:fallbackMedia' in data['_links']: