diff --git a/addon.xml b/addon.xml index da187e5..71af0ad 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/lib/cdm.py b/resources/lib/cdm.py index 4f74266..1caa72b 100644 --- a/resources/lib/cdm.py +++ b/resources/lib/cdm.py @@ -22,11 +22,11 @@ def get_pssh_from_manifest(url): return pssh.group(1) return None -def get_pssh_key(pssh, license_url, platform_id=None): +def get_pssh_key(pssh, license_url): api_base_url = "https://cdm.drmtalks.com/" api_cdm_device = "01JCP8Y4W3PHM7DRQ5HGTME2CQ" - api_headers = {'user-agent': user_agent, 'accept': '*/*'} - session.headers.update(api_headers) + headers = {'user-agent': user_agent, 'accept': '*/*'} + session.headers.update(headers) open_session = session.get(api_base_url + api_cdm_device + '/open').json() #LOG(open_session.content) @@ -41,43 +41,33 @@ def get_pssh_key(pssh, license_url, platform_id=None): #LOG(challenge_b64) challenge_raw = base64.b64decode(challenge_b64) - license_headers = api_headers - if platform_id: - from .signature import Signature - path="/" + license_url.split("://", 1)[1].split("/", 1)[1] - #LOG(path) - sig = Signature(platform_id) - sig_header = sig.calculate_signature('POST', path, {}, challenge_raw) - license_headers.update(sig_header) - #LOG(headers) - - license = requests.post(license_url, data=challenge_raw, headers=license_headers) + license = session.post(license_url, data=challenge_raw) license.raise_for_status() #LOG(license.content) license_b64 = base64.b64encode(license.content).decode() #LOG('license_b64: {}'.format(license_b64)) parse_license_data = {'session_id': session_id , 'license_message': license_b64} - license_api_request = session.post(api_base_url + api_cdm_device + '/parse_license', json=parse_license_data, headers=api_headers).json() + license_api_request = session.post(api_base_url + api_cdm_device + '/parse_license', json=parse_license_data).json() keys_api_data = {'session_id': session_id} - keys_api_request = session.post(api_base_url + api_cdm_device + '/get_keys/CONTENT', json=keys_api_data, headers=api_headers).json() + keys_api_request = session.post(api_base_url + api_cdm_device + '/get_keys/CONTENT', json=keys_api_data).json() keys = keys_api_request['data']['keys'] #LOG('keys: {}'.format(keys)) res = [] for key in keys: res.append('{}:{}'.format(key['key_id'], key['key'])) - close_session = session.get(api_base_url + api_cdm_device + '/close/' + session_id, headers=api_headers).text + close_session = session.get(api_base_url + api_cdm_device + '/close/' + session_id).text return ",".join(res) -def get_cdm_keys(manifest_url, license_url, platform_id=None): +def get_cdm_keys(manifest_url, license_url): pssh = get_pssh_from_manifest(manifest_url) #LOG('pssh: {}'.format(pssh)) d = {} if pssh: try: - key = get_pssh_key(pssh, license_url, platform_id) + key = get_pssh_key(pssh, license_url) d['key'] = key except Exception as e: d['error'] = str(e) diff --git a/resources/lib/plugin.py b/resources/lib/plugin.py index 5d8fdfe..f84c87f 100644 --- a/resources/lib/plugin.py +++ b/resources/lib/plugin.py @@ -119,13 +119,21 @@ def play(params): '/hw8CTCX0hhNaWOMp38Tiuj+mSsUmwkq/71R9VsY0EN+k+BDXpaJHIJO9Dk+mm08P0ILWT7/sMJy' '225r81jyLmvsth4Kw47T4NqkJlP0/Tvs') + + platform_id = addon.getSetting('platform_id').lower() + headers = 'User-Agent='+ user_agent(platform_id) + license_headers = headers + '&Content-Type=application/octet-stream' + play_item = xbmcgui.ListItem(path=url) play_item.setProperty('inputstream.adaptive.manifest_type', 'mpd') if 'license_url' in data: - extra_params = '' - if slug: - extra_params = '&content_id={}&provider_variant_id={}'.format(info['content_id'], info['provider_variant_id']) - license_url = '{}/license?url={}{}||R{{SSM}}|'.format(proxy, quote_plus(data['license_url']), extra_params) + if addon.getSettingBool('use_proxy_for_license'): + extra_params = '' + if slug: + extra_params = '&content_id={}&provider_variant_id={}'.format(info['content_id'], info['provider_variant_id']) + license_url = '{}/license?url={}{}||R{{SSM}}|'.format(proxy, quote_plus(data['license_url']), extra_params) + else: + license_url = '{}|{}|R{{SSM}}|'.format(data['license_url'], license_headers) LOG('license_url: {}'.format(license_url)) key = None @@ -144,7 +152,7 @@ def play(params): play_item.setProperty('inputstream.adaptive.license_key', license_url) play_item.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') - play_item.setProperty('inputstream.adaptive.stream_headers', 'User-Agent=' + chrome_user_agent) + play_item.setProperty('inputstream.adaptive.stream_headers', headers) play_item.setProperty('inputstream.adaptive.server_certificate', certificate) #play_item.setProperty('inputstream.adaptive.license_flags', 'persistent_storage') #play_item.setProperty('inputstream.adaptive.license_flags', 'force_secure_decoder') @@ -155,6 +163,8 @@ def play(params): play_item.setProperty('inputstream', 'inputstream.adaptive') play_item.setMimeType('application/dash+xml') + play_item.setContentLookup(False) + try: play_item.setInfo('video', info['info']) play_item.setArt(info['art']) @@ -229,7 +239,6 @@ def play(params): subpaths.append(filename_srt) play_item.setSubtitles(subpaths) - play_item.setContentLookup(False) xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item) # Control player diff --git a/resources/settings.xml b/resources/settings.xml index 8d510e5..0c98d7b 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -33,5 +33,6 @@ +