Skip to content

Commit

Permalink
[FR - MYCANAL] use get_stream_with_quality (#1188)
Browse files Browse the repository at this point in the history
* [PROJECT] resolver_proxy : allow inputstream adaptive without license type

* [FR - MYCANAL] use get_stream_with_quality
  • Loading branch information
darodi authored Aug 5, 2023
1 parent 6cab990 commit 67e5eb0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
40 changes: 25 additions & 15 deletions resources/lib/channels/fr/mycanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,34 @@ def rnd():
return device_key_id, device_id_full, session_id


def create_item_mpd(certificate_data, item, json_stream_data, secure_gen_hapi_headers):
item.property['inputstream.adaptive.manifest_type'] = 'mpd'
item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
def create_item_mpd(plugin, certificate_data, item, json_stream_data, secure_gen_hapi_headers, subtitles):
headers = secure_gen_hapi_headers.copy()
headers.update({'Content-Type': 'text/plain'})
with xbmcvfs.File('special://userdata/addon_data/plugin.video.catchuptvandmore/headersCanal', 'wb') as f1:
pickle.dump(headers, f1)
# Return HTTP 200 but the response is not correctly interpreted by inputstream
# (https://github.com/peak3d/inputstream.adaptive/issues/267)
licence = "http://127.0.0.1:5057/license=" + SECURE_GEN_HAPI + json_stream_data['@licence']
licence += '?drmConfig=mkpl::true|%s|b{SSM}|B' % urlencode(headers)
item.property['inputstream.adaptive.license_key'] = licence
item.property['inputstream.adaptive.server_certificate'] = certificate_data
license_url = "http://127.0.0.1:5057/license=" + SECURE_GEN_HAPI + json_stream_data['@licence']
license_url += '?drmConfig=mkpl::true|%s|b{SSM}|B' % urlencode(headers)

input_stream_properties = {"server_certificate": certificate_data}

return resolver_proxy.get_stream_with_quality(plugin, video_url=item.path, manifest_type="mpd",
license_url=license_url, headers=headers,
subtitles=subtitles,
input_stream_properties=input_stream_properties)

def set_subtitles(first_stream, item, plugin):

def set_subtitles(plugin, stream, item):
url = ''
if plugin.setting.get_boolean('active_subtitle'):
for file in first_stream["files"]:
for file in stream["files"]:
if 'vtt' in file["mimeType"] or file["type"] == 'subtitle':
url = file['distribURL']
if 'http' in url:
item.subtitles.append(url)
return url
return None


def is_valid_drm(drm_type):
Expand Down Expand Up @@ -607,27 +612,32 @@ def get_video_url(plugin,
item.info.update(get_selected_item_info())
item.property[INPUTSTREAM_PROP] = 'inputstream.adaptive'

set_subtitles(first_stream, item, plugin)
subtitles = set_subtitles(plugin, first_stream, item)

if ".ism" in item.path:
is_helper = inputstreamhelper.Helper('ism')
if not is_helper.check_inputstream():
return False

if drm_type != "UNPROTECTED":
pass # TODO
plugin.notify("INFO", "ism + drm not implemented", Script.NOTIFY_INFO)
return False

video_url = item.path + "/manifest"
input_stream_properties = {"license_type": None}

item.property['inputstream.adaptive.manifest_type'] = 'ism'
item.path += "/manifest"
return item
return resolver_proxy.get_stream_with_quality(plugin, video_url=video_url,
manifest_type="ism",
input_stream_properties=input_stream_properties,
subtitles=subtitles)

if ".mpd" in item.path:

is_helper = inputstreamhelper.Helper('mpd', drm='widevine')
if not is_helper.check_inputstream():
return False

create_item_mpd(certificate_data, item, json_stream_data, secure_gen_hapi_headers)
return create_item_mpd(plugin, certificate_data, item, json_stream_data, secure_gen_hapi_headers, subtitles)

return item

Expand Down
9 changes: 8 additions & 1 deletion resources/lib/resolver_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ def get_stream_with_quality(plugin,
item = Listitem()
item.path = video_url
item.property[INPUTSTREAM_PROP] = "inputstream.adaptive"
item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'

if input_stream_properties is not None and "license_type" in input_stream_properties:
if input_stream_properties["license_type"] is not None:
item.property['inputstream.adaptive.license_type'] = input_stream_properties["license_type"]
else:
pass
else:
item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
item.property["inputstream.adaptive.manifest_type"] = manifest_type
if workaround is not None:
item.property['ResumeTime'] = '43200' # 12 hours buffer, can be changed if not enough
Expand Down

0 comments on commit 67e5eb0

Please sign in to comment.