From 2a8dbe879d8f9733c59a85a7c5d7fbf5ad72a819 Mon Sep 17 00:00:00 2001 From: darodi <4682830+darodi@users.noreply.github.com> Date: Sat, 29 Jul 2023 10:31:41 +0200 Subject: [PATCH] [FR - MYCANAL] new url and APIs --- resources/lib/channels/fr/mycanal.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/resources/lib/channels/fr/mycanal.py b/resources/lib/channels/fr/mycanal.py index feebe03d5..16cdd9a1f 100644 --- a/resources/lib/channels/fr/mycanal.py +++ b/resources/lib/channels/fr/mycanal.py @@ -146,7 +146,7 @@ def list_categories(plugin, item_id, **kwargs): for category in json_react_query_state["queries"][0]["state"]["data"]["strates"]: if category["type"] == "carrousel": title = category['context']['context_page_title'] - key_value = category['reactKey'] + key_value = category['reactKey'] if 'reactKey' in category else None item = Listitem() item.label = title item.set_callback(list_contents, item_id=item_id, key_value=key_value) @@ -160,7 +160,7 @@ def list_categories(plugin, item_id, **kwargs): else: title = category['context']['context_list_id'] continue - key_value = category['reactKey'] + key_value = category['reactKey'] if 'reactKey' in category else None item = Listitem() item.label = title item.set_callback(list_contents, item_id=item_id, key_value=key_value) @@ -175,7 +175,7 @@ def list_contents(plugin, item_id, key_value, **kwargs): json_react_query_state = json.loads(react_query_state) for category in json_react_query_state["queries"][0]["state"]["data"]["strates"]: - if category['reactKey'] != key_value: + if 'reactKey' in category and category['reactKey'] != key_value: continue for content in category["contents"]: @@ -441,7 +441,8 @@ def get_video_url(plugin, 'sessionId': sessionId, } - json_token_parser = session_requests.post(URL_TOKEN, data=payload, headers=headers).json() + resp = session_requests.post(URL_TOKEN, data=payload, headers=headers) + json_token_parser = resp.json() pass_token = json_token_parser["response"]["passToken"] device_id = json_token_parser["response"]["userData"]["deviceId"].split(':')[0] @@ -475,9 +476,7 @@ def get_video_url(plugin, return False for stream_datas in value_datas_jsonparser["available"]: - if stream_datas['drmType'] == "DRM MKPC Widevine DASH" \ - or stream_datas['drmType'] == "Non protégé" \ - or stream_datas['drmType'] == "UNPROTECTED": + if 'drmType' in stream_datas and is_valid_drm(stream_datas['drmType']): payload = { 'comMode': stream_datas['comMode'], 'contentId': stream_datas['contentId'], @@ -495,6 +494,13 @@ def get_video_url(plugin, jsonparser_stream_datas = session_requests.put( URL_STREAM_DATAS, data=payload, headers=secure_gen_hapi_headers).json() + if ('@medias' not in jsonparser_stream_datas + and 'message' in jsonparser_stream_datas + and 'status' in jsonparser_stream_datas + and jsonparser_stream_datas['status'] != 200): + xbmcgui.Dialog().ok('Info', jsonparser_stream_datas['message']) + return False + jsonparser_real_stream_datas = session_requests.get(SECURE_GEN_HAPI + jsonparser_stream_datas['@medias'], headers=secure_gen_hapi_headers).json() @@ -554,6 +560,14 @@ def get_video_url(plugin, return json_parser["detail"]["informations"]["playsets"]["available"][0]["videoURL"] +def is_valid_drm(drm_type): + return (drm_type == "DRM MKPC Widevine DASH" + or drm_type == "Non protégé" + or drm_type == "UNPROTECTED" + or drm_type == 'DRM_MKPC_WIDEVINE_DASH' + or drm_type == 'DRM_WIDEVINE') + + @Resolver.register def get_live_url(plugin, item_id, **kwargs): if xbmcgui.Dialog().select(Script.localize(30174), ["MyCanal", "Dailymotion"]):