def get_live_url(plugin, item_id, video_id, item_dict, **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

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

    resp = urlquick.get(URL_LIVE, max_age=-1)

    token_id = re.compile(r'start\-player\.npo\.nl\/embed\/(.*?)\"').findall(
        resp.text)[0]
    live_id = re.compile(r'\"iframe\-(.*?)\"').findall(resp.text)[0]

    resp2 = urlquick.get(URL_STREAM % (live_id, token_id), max_age=-1)
    json_parser = json.loads(resp2.text)

    if "html" in json_parser and "Deze video mag niet bekeken worden vanaf jouw locatie" in json_parser[
            "html"]:
        plugin.notify('ERROR', plugin.localize(30713))
        return False

    if "html" in json_parser and "Deze video is niet beschikbaar" in json_parser[
            "html"]:
        plugin.notify('ERROR', plugin.localize(30716))
        return False

    licence_url = json_parser["stream"]["keySystemOptions"][0]["options"][
        "licenseUrl"]
    licence_url_header = json_parser["stream"]["keySystemOptions"][0][
        "options"]["httpRequestHeaders"]
    xcdata_value = licence_url_header["x-custom-data"]

    item = Listitem()
    item.path = json_parser["stream"]["src"]
    if item_dict:
        if 'label' in item_dict:
            item.label = item_dict['label']
        if 'info' in item_dict:
            item.info.update(item_dict['info'])
        if 'art' in item_dict:
            item.art.update(item_dict['art'])
    else:
        item.label = LABELS[item_id]
        item.art["thumb"] = ""
        item.art["icon"] = ""
        item.art["fanart"] = ""
        item.info["plot"] = LABELS[item_id]
    if plugin.setting.get_boolean('active_subtitle'):
        item.subtitles.append(URL_SUBTITLE % video_id)
    item.property['inputstreamaddon'] = 'inputstream.adaptive'
    item.property['inputstream.adaptive.manifest_type'] = 'mpd'
    item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
    item.property[
        'inputstream.adaptive.license_key'] = licence_url + '|Content-Type=&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36&x-custom-data=%s|R{SSM}|' % xcdata_value

    return item
示例#2
0
def get_video_url(plugin,
                  item_id,
                  video_id,
                  item_dict,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    resp = urlquick.get(URL_STREAM % video_id, max_age=-1)
    json_parser = json.loads(resp.text)

    if 'error' in json_parser:
        if json_parser["error"] is not None:
            if json_parser["error"]["status"] == '403':
                plugin.notify('ERROR', plugin.localize(30713))
            else:
                plugin.notify('ERROR', plugin.localize(30716))
            return False

    if 'drmToken' in json_parser["playback"]:

        if cqu.get_kodi_version() < 18:
            xbmcgui.Dialog().ok('Info', plugin.localize(30602))
            return False

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

        if download_mode:
            xbmcgui.Dialog().ok('Info', plugin.localize(30603))
            return False

        token = json_parser["playback"]["drmToken"]

        item = Listitem()
        item.path = json_parser["playback"]["streamUrlDash"]
        item.label = item_dict['label']
        item.info.update(item_dict['info'])
        item.art.update(item_dict['art'])
        item.property['inputstreamaddon'] = 'inputstream.adaptive'
        item.property['inputstream.adaptive.manifest_type'] = 'mpd'
        item.property[
            'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
        item.property[
            'inputstream.adaptive.license_key'] = URL_LICENCE_KEY % token

        return item
    else:
        final_video_url = json_parser["playback"]["streamUrlHls"]

        if download_mode:
            return download.download_video(final_video_url, video_label)

        return final_video_url
示例#3
0
def get_sorted_menu(plugin, menu_id):
    # The current menu to build contains
    # all the items present in the 'menu_id'
    # skeleton file
    current_menu = importlib.import_module('resources.lib.skeletons.' +
                                           menu_id).menu

    # Notify user for the new M3U Live TV feature
    if menu_id == "live_tv" and \
            cqu.get_kodi_version() >= 18 and \
            plugin.setting.get_boolean('show_live_tv_m3u_info'):

        r = xbmcgui.Dialog().yesno(plugin.localize(LABELS['Information']),
                                   plugin.localize(30605),
                                   plugin.localize(30606))
        if not r:
            plugin.setting['show_live_tv_m3u_info'] = False

    # Keep in memory the first menu taken
    # in order to provide a prefix when the user
    # add a favourite
    fav.guess_fav_prefix(menu_id)

    # First, we have to sort the current menu items
    # according to each item order and we have
    # to hide each disabled item
    menu = []
    for item_id, item_infos in current_menu.items():

        add_item = True

        # If the item is enable
        if not Script.setting.get_boolean(item_id):
            add_item = False

        # If the desired language is not avaible
        if 'available_languages' in item_infos:
            desired_language = utils.ensure_unicode(
                Script.setting[item_id + '.language'])
            if desired_language not in item_infos['available_languages']:
                add_item = False

        if add_item:
            # Get order value in settings file
            item_order = Script.setting.get_int(item_id + '.order')

            item = (item_order, item_id, item_infos)

            menu.append(item)

    # We sort the menu according to the item_order values
    return sorted(menu, key=lambda x: x[0])
示例#4
0
def get_video_url(plugin,
                  item_id,
                  video_id,
                  item_dict,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

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

    resp = urlquick.get(URL_CLIENT_KEY_VIDEO_JS)
    client_key_value = 'client-key %s' % re.compile(
        r'prod\"\,clientKey\:\"(.*?)\"').findall(resp.text)[0]
    headers = {'Authorization': client_key_value}
    resp2 = urlquick.get(URL_STREAM_REPLAY % video_id,
                         headers=headers,
                         max_age=-1)

    json_parser = json.loads(resp2.text)

    if json_parser["params"] is not None:
        licence_key_drm = ''
        for licence_key_drm_datas in json_parser["params"]:
            if 'widevineLicenseUrl' in licence_key_drm_datas["name"]:
                licence_key_drm = licence_key_drm_datas["value"]
        token_drm = ''
        for token_drm_datas in json_parser["params"]:
            if 'widevineAuthToken' in token_drm_datas["name"]:
                token_drm = token_drm_datas["value"]

        item = Listitem()
        item.path = json_parser["url"].replace('filter=',
                                               'format=mpd-time-csf,filter=')
        item.label = item_dict['label']
        item.info.update(item_dict['info'])
        item.art.update(item_dict['art'])
        item.property['inputstreamaddon'] = 'inputstream.adaptive'
        item.property['inputstream.adaptive.manifest_type'] = 'mpd'
        item.property[
            'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
        item.property[
            'inputstream.adaptive.license_key'] = licence_key_drm + '|Content-Type=&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36&Authorization=%s|R{SSM}|' % token_drm

        return item
    plugin.notify('ERROR', plugin.localize(30713))
    return False
示例#5
0
def get_live_url(plugin, item_id, video_id, item_dict, **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

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

    if item_id == 'questtv':
        resp = urlquick.get(URL_LIVE % 'quest', max_age=-1)
    elif item_id == 'questred':
        resp = urlquick.get(URL_LIVE % 'quest-red', max_age=-1)

    if len(re.compile(r'drmToken\"\:\"(.*?)\"').findall(resp.text)) > 0:
        token = re.compile(r'drmToken\"\:\"(.*?)\"').findall(resp.text)[0]
        if len(re.compile(r'streamUrlDash\"\:\"(.*?)\"').findall(
                resp.text)) > 0:
            live_url = re.compile(r'streamUrlDash\"\:\"(.*?)\"').findall(
                resp.text)[0]

            item = Listitem()
            item.path = live_url
            if item_dict:
                if 'label' in item_dict:
                    item.label = item_dict['label']
                if 'info' in item_dict:
                    item.info.update(item_dict['info'])
                if 'art' in item_dict:
                    item.art.update(item_dict['art'])
            else:
                item.label = LABELS[item_id]
                item.art["thumb"] = ""
                item.art["icon"] = ""
                item.art["fanart"] = ""
                item.info["plot"] = LABELS[item_id]
            item.property['inputstreamaddon'] = 'inputstream.adaptive'
            item.property['inputstream.adaptive.manifest_type'] = 'mpd'
            item.property[
                'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
            item.property[
                'inputstream.adaptive.license_key'] = URL_LICENCE_KEY % token
            return item
    plugin.notify('ERROR', plugin.localize(30713))
    return False
示例#6
0
def list_videos(plugin, item_id, program_id, sub_category_id, **kwargs):

    url = ''
    if sub_category_id is None:
        url = URL_VIDEOS2 % program_id
    else:
        url = URL_VIDEOS % (program_id, sub_category_id)
    resp = urlquick.get(url)
    json_parser = json.loads(resp.text)

    if not json_parser:
        plugin.notify(plugin.localize(LABELS['No videos found']), '')
        yield False

    for video in json_parser:

        video_id = str(video['id'])

        item = Listitem()
        item.label = video['title']

        is_downloadable = False
        if cqu.get_kodi_version() < 18:
            is_downloadable = True

        if 'type' in video and video['type'] == 'playlist':
            populate_item(item, video)
            item.set_callback(get_playlist_urls,
                              item_id=item_id,
                              video_id=video_id,
                              url=url)
        else:
            populate_item(item, video['clips'][0])
            item.set_callback(get_video_url,
                              item_id=item_id,
                              video_id=video_id,
                              video_label=LABELS[item_id] + ' - ' + item.label,
                              item_dict=item2dict(item))
        item_post_treatment(item,
                            is_playable=True,
                            is_downloadable=is_downloadable)
        yield item
def get_live_url(plugin, item_id, video_id, item_dict, **kwargs):

    resp = urlquick.get(URL_LIVE_JSON % item_id[:3])
    json_parser = json.loads(resp.text)
    live_id = ''
    for live_datas in json_parser["teaser"]:
        if live_datas["channelName"] in LIVE_LIVE_CHANNEL_NAME[item_id]:
            live_id = live_datas["id"]
    if live_id is None:
        # Add Notification
        return False
    resp2 = urlquick.get(URL_INFO_VIDEO % (item_id[:3], live_id))
    json_parser2 = json.loads(resp2.text)

    # build stream_url
    stream_url = ''
    is_drm = False
    for stream_datas in json_parser2["chapterList"]:
        if live_id in stream_datas["id"]:
            for stream_datas_url in stream_datas["resourceList"]:
                if 'drmList' in stream_datas_url:
                    is_drm = True

    if is_drm:
        if cqu.get_kodi_version() < 18:
            xbmcgui.Dialog().ok('Info', plugin.localize(30602))
            return False

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

        licence_drm_url = ''
        for stream_datas in json_parser2["chapterList"]:
            if live_id in stream_datas["id"]:
                for stream_datas_url in stream_datas["resourceList"]:
                    stream_url = stream_datas_url["url"]
                    for licence_drm_datas in stream_datas_url["drmList"]:
                        if 'WIDEVINE' in licence_drm_datas["type"]:
                            licence_drm_url = licence_drm_datas["licenseUrl"]

        item = Listitem()
        item.path = stream_url
        item.property['inputstreamaddon'] = 'inputstream.adaptive'
        item.property['inputstream.adaptive.manifest_type'] = 'mpd'
        item.property[
            'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
        item.property[
            'inputstream.adaptive.license_key'] = licence_drm_url + '|Content-Type=&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36&Host=srg.live.ott.irdeto.com|R{SSM}|'

        if item_dict:
            if 'label' in item_dict:
                item.label = item_dict['label']
            if 'info' in item_dict:
                item.info.update(item_dict['info'])
            if 'art' in item_dict:
                item.art.update(item_dict['art'])
        else:
            item.label = LABELS[item_id]
            item.art["thumb"] = ""
            item.art["icon"] = ""
            item.art["fanart"] = ""
            item.info["plot"] = LABELS[item_id]
        return item

    else:
        for stream_datas in json_parser2["chapterList"]:
            if live_id in stream_datas["id"]:
                for stream_datas_url in stream_datas["resourceList"]:
                    if 'HD' in stream_datas_url["quality"] and \
                            'mpegURL' in stream_datas_url["mimeType"]:
                        stream_url = stream_datas_url["url"]
                        break
                    else:
                        if 'mpegURL' in stream_datas_url["mimeType"]:
                            stream_url = stream_datas_url["url"]

        acl_value = '/i/%s/*' % (
            re.compile(r'\/i\/(.*?)\/').findall(stream_url)[0])
        token_datas = urlquick.get(URL_TOKEN % acl_value, max_age=-1)
        token_jsonparser = json.loads(token_datas.text)
        token = token_jsonparser["token"]["authparams"]
        if '?' in stream_url:
            final_video_url = stream_url + '&' + token
        else:
            final_video_url = stream_url + '?' + token
        return final_video_url
示例#8
0
def get_live_url(plugin, item_id, video_id, item_dict, **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

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

    headers = {'X-Requested-With': 'XMLHttpRequest'}

    resp_token = urlquick.get(URL_TOKEN_API, headers=headers, max_age=-1)
    session_token = resp_token.cookies['npo_session']

    json_parser_token = json.loads(resp_token.text)
    api_token = json_parser_token['token']

    resp = urlquick.get(URL_LIVE_ID % item_id, max_age=-1)

    video_id = re.compile(r'\"iframe\-(.*?)\"').findall(resp.text)[0]

    # Build PAYLOAD
    payload = {"_token": api_token}

    cookies = {"npo_session": session_token}

    resp2 = urlquick.post(URL_TOKEN_ID % video_id,
                          cookies=cookies,
                          data=payload,
                          max_age=-1)
    json_parser = json.loads(resp2.text)
    token_id = json_parser['token']

    resp3 = urlquick.get(URL_STREAM % (video_id, token_id), max_age=-1)
    json_parser2 = json.loads(resp3.text)

    if "html" in json_parser2 and "Vanwege uitzendrechten is het niet mogelijk om deze uitzending buiten Nederland te bekijken." in json_parser2[
            "html"]:
        plugin.notify('ERROR', plugin.localize(30713))
        return False

    licence_url = json_parser2["stream"]["keySystemOptions"][0]["options"][
        "licenseUrl"]
    licence_url_header = json_parser2["stream"]["keySystemOptions"][0][
        "options"]["httpRequestHeaders"]
    xcdata_value = licence_url_header["x-custom-data"]

    item = Listitem()
    item.path = json_parser2["stream"]["src"]
    if item_dict:
        if 'label' in item_dict:
            item.label = item_dict['label']
        if 'info' in item_dict:
            item.info.update(item_dict['info'])
        if 'art' in item_dict:
            item.art.update(item_dict['art'])
    else:
        item.label = LABELS[item_id]
        item.art["thumb"] = ""
        item.art["icon"] = ""
        item.art["fanart"] = ""
        item.info["plot"] = LABELS[item_id]
    if plugin.setting.get_boolean('active_subtitle'):
        item.subtitles.append(URL_SUBTITLE % video_id)
    item.property['inputstreamaddon'] = 'inputstream.adaptive'
    item.property['inputstream.adaptive.manifest_type'] = 'mpd'
    item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
    item.property[
        'inputstream.adaptive.license_key'] = licence_url + '|Content-Type=&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36&x-custom-data=%s|R{SSM}|' % xcdata_value

    return item
示例#9
0
def get_video_url(plugin,
                  item_id,
                  video_id,
                  item_dict,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

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

    headers = {'X-Requested-With': 'XMLHttpRequest'}

    resp_token = urlquick.get(URL_TOKEN_API, headers=headers, max_age=-1)
    session_token = resp_token.cookies['npo_session']

    json_parser_token = json.loads(resp_token.text)
    api_token = json_parser_token['token']

    # Build PAYLOAD
    payload = {"_token": api_token}

    cookies = {"npo_session": session_token}

    resp2 = urlquick.post(URL_TOKEN_ID % video_id,
                          cookies=cookies,
                          data=payload,
                          max_age=-1)
    json_parser = json.loads(resp2.text)
    token_id = json_parser['token']

    resp3 = urlquick.get(URL_STREAM % (video_id, token_id), max_age=-1)
    json_parser2 = json.loads(resp3.text)

    if "html" in json_parser2 and "Dit programma mag niet bekeken worden vanaf jouw locatie (33)." in json_parser2[
            "html"]:
        plugin.notify('ERROR', plugin.localize(30713))
        return False
    elif "html" in json_parser2 and "Dit programma is niet (meer) beschikbaar (15)." in json_parser2[
            "html"]:
        plugin.notify('ERROR', plugin.localize(30710))
        return False

    licence_url = json_parser2["stream"]["keySystemOptions"][0]["options"][
        "licenseUrl"]
    licence_url_header = json_parser2["stream"]["keySystemOptions"][0][
        "options"]["httpRequestHeaders"]
    xcdata_value = licence_url_header["x-custom-data"]

    item = Listitem()
    item.path = json_parser2["stream"]["src"]
    item.label = item_dict['label']
    item.info.update(item_dict['info'])
    item.art.update(item_dict['art'])
    if plugin.setting.get_boolean('active_subtitle'):
        item.subtitles.append(URL_SUBTITLE % video_id)
    item.property['inputstreamaddon'] = 'inputstream.adaptive'
    item.property['inputstream.adaptive.manifest_type'] = 'mpd'
    item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
    item.property[
        'inputstream.adaptive.license_key'] = licence_url + '|Content-Type=&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36&x-custom-data=%s|R{SSM}|' % xcdata_value

    return item
def get_live_url(plugin, item_id, video_id, item_dict, **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

    resp_js_id = urlquick.get(URL_GET_JS_ID_API_KEY)
    js_id = re.compile(r'client\-(.*?)\.bundle\.js').findall(
        resp_js_id.text)[0]
    resp = urlquick.get(URL_API_KEY % js_id)

    api_key = re.compile(
        r'\"sso-login.rtl.be\"\,cdn\:\"eu1.gigya.com\"\,key\:\"(.*?)\"'
    ).findall(resp.text)[0]

    if plugin.setting.get_string('rtlplaybe.login') == '' or\
            plugin.setting.get_string('rtlplaybe.password') == '':
        xbmcgui.Dialog().ok(
            'Info',
            plugin.localize(30604) %
            ('RTLPlay (BE)', 'https://www.rtlplay.be'))
        return False

    # Build PAYLOAD
    payload = {
        "loginID": plugin.setting.get_string('rtlplaybe.login'),
        "password": plugin.setting.get_string('rtlplaybe.password'),
        "apiKey": api_key,
        "format": "jsonp",
        "callback": "jsonp_3bbusffr388pem4"
    }
    # LOGIN
    resp2 = urlquick.post(URL_COMPTE_LOGIN,
                          data=payload,
                          headers={
                              'User-Agent': web_utils.get_random_ua,
                              'referer': 'https://www.rtlplay.be/connexion'
                          })
    json_parser = json.loads(
        resp2.text.replace('jsonp_3bbusffr388pem4(', '').replace(');', ''))

    if "UID" not in json_parser:
        plugin.notify('ERROR', 'RTLPlay (BE) : ' + plugin.localize(30711))
        return False
    account_id = json_parser["UID"]
    account_timestamp = json_parser["signatureTimestamp"]
    account_signature = json_parser["UIDSignature"]

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

    # Build PAYLOAD headers
    payload_headers = {
        'x-auth-gigya-signature': account_signature,
        'x-auth-gigya-signature-timestamp': account_timestamp,
        'x-auth-gigya-uid': account_id,
        'User-Agent': web_utils.get_random_ua,
        'x-customer-name': 'rtlbe'
    }
    channel = 'rtlbe_' + item_id
    token_json = urlquick.get(URL_TOKEN_DRM % (account_id, 'dashcenc_%s' %
                                               (channel)),
                              headers=payload_headers,
                              max_age=-1)
    token_jsonparser = json.loads(token_json.text)
    token = token_jsonparser["token"]

    video_json = urlquick.get(URL_LIVE_JSON % (channel),
                              headers={
                                  'User-Agent': web_utils.get_random_ua,
                                  'x-customer-name': 'rtlbe'
                              },
                              max_age=-1)
    json_parser = json.loads(video_json.text)
    if not json_parser[channel]:
        plugin.notify('ERROR', plugin.localize(30712))
        return False

    video_assets = json_parser[channel][0]['live']['assets']

    if not video_assets:
        plugin.notify('INFO', plugin.localize(30716))
        return False

    subtitle_url = ''
    if plugin.setting.get_boolean('active_subtitle'):
        for asset in video_assets:
            if 'subtitle_vtt' in asset["type"]:
                subtitle_url = asset['full_physical_path']

    for asset in video_assets:
        if 'delta_dashcenc_h264' in asset["type"]:
            item = Listitem()
            item.path = asset['full_physical_path']
            if 'http' in subtitle_url:
                item.subtitles.append(subtitle_url)
            item.property['inputstreamaddon'] = 'inputstream.adaptive'
            item.property['inputstream.adaptive.manifest_type'] = 'mpd'
            item.property[
                'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
            item.property[
                'inputstream.adaptive.license_key'] = URL_LICENCE_KEY % token

            if item_dict:
                if 'label' in item_dict:
                    item.label = item_dict['label']
                if 'info' in item_dict:
                    item.info.update(item_dict['info'])
                if 'art' in item_dict:
                    item.art.update(item_dict['art'])
            else:
                item.label = LABELS[item_id]
                item.art["thumb"] = ""
                item.art["icon"] = ""
                item.art["fanart"] = ""
                item.info["plot"] = LABELS[item_id]
            return item
    return False
def get_video_url(plugin,
                  item_id,
                  video_id,
                  item_dict=None,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    video_format = 'hls'
    url_json = URL_VIDEO_STREAM % (video_id, video_format)
    htlm_json = urlquick.get(url_json,
                             headers={'User-Agent': web_utils.get_random_ua()},
                             max_age=-1)
    json_parser = json.loads(htlm_json.text)

    if json_parser['code'] >= 400:
        plugin.notify('ERROR', plugin.localize(30716))
        return False

    # Check DRM in the m3u8 file
    manifest = urlquick.get(json_parser["url"],
                            headers={
                                'User-Agent': web_utils.get_random_ua()
                            },
                            max_age=-1).text
    if 'drm' in manifest:

        if cqu.get_kodi_version() < 18:
            xbmcgui.Dialog().ok('Info', plugin.localize(30602))
            return False
        else:
            video_format = 'dash'

    if video_format == 'hls':

        final_video_url = json_parser["url"].replace('2800000', '4000000')
        if download_mode:
            return download.download_video(final_video_url, video_label)
        return final_video_url

    else:
        if download_mode:
            xbmcgui.Dialog().ok('Info', plugin.localize(30603))
            return False

        url_json = URL_VIDEO_STREAM % (video_id, video_format)
        htlm_json = urlquick.get(
            url_json,
            headers={'User-Agent': web_utils.get_random_ua()},
            max_age=-1)
        json_parser = json.loads(htlm_json.text)

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

        item = Listitem()
        item.path = json_parser["url"]
        item.label = item_dict['label']
        item.info.update(item_dict['info'])
        item.art.update(item_dict['art'])
        item.property['inputstreamaddon'] = 'inputstream.adaptive'
        item.property['inputstream.adaptive.manifest_type'] = 'mpd'
        item.property[
            'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
        item.property[
            'inputstream.adaptive.license_key'] = URL_LICENCE_KEY % video_id

        return item
def list_videos(plugin, item_id, program_id, sub_category_id, **kwargs):

    url = ''
    if sub_category_id is None:
        url = URL_VIDEOS2 % program_id
    else:
        url = URL_VIDEOS % (program_id, sub_category_id)
    resp = urlquick.get(url,
                        headers={
                            'User-Agent': web_utils.get_random_ua,
                            'x-customer-name': 'rtlbe'
                        })
    json_parser = json.loads(resp.text)

    # TO DO Playlist More one 'clips'
    at_least_one_item = False
    for video in json_parser:
        video_id = str(video['id'])

        title = video['title']
        duration = video['clips'][0]['duration']
        description = ''
        if 'description' in video:
            description = video['description']
        try:
            aired = video['clips'][0]['product']['last_diffusion']
            aired = aired
            aired = aired[:10]
            # year = aired[:4]
            # date : string (%d.%m.%Y / 01.01.2009)
            # aired : string (2008-12-07)
            # day = aired.split('-')[2]
            # mounth = aired.split('-')[1]
            # year = aired.split('-')[0]
            # date = '.'.join((day, mounth, year))

        except Exception:
            aired = ''
            # year = ''
            # date = ''
        img = ''

        program_imgs = video['clips'][0]['images']
        program_img = ''
        for img in program_imgs:
            if img['role'] == 'vignette':
                external_key = img['external_key']
                program_img = URL_IMG % (external_key)

        item = Listitem()
        at_least_one_item = True
        item.label = title
        item.info['plot'] = description
        item.info['duration'] = duration
        item.art["thumb"] = program_img
        item.art["fanart"] = program_img
        try:
            item.info.date(aired, '%Y-%m-%d')
        except Exception:
            pass

        is_downloadable = False
        if cqu.get_kodi_version() < 18:
            is_downloadable = True

        item.set_callback(get_video_url,
                          item_id=item_id,
                          video_id=video_id,
                          video_label=LABELS[item_id] + ' - ' + item.label,
                          item_dict=item2dict(item))
        item_post_treatment(item,
                            is_playable=True,
                            is_downloadable=is_downloadable)
        yield item

    if not at_least_one_item:
        plugin.notify(plugin.localize(LABELS['No videos found']), '')
        yield False
def get_video_url(plugin,
                  item_id,
                  video_id,
                  item_dict=None,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    video_format = 'hls'
    url_json = URL_VIDEO_STREAM % (video_id, video_format)
    htlm_json = urlquick.get(url_json,
                             headers={'User-Agent': web_utils.get_random_ua},
                             max_age=-1)
    json_parser = json.loads(htlm_json.text)

    if json_parser['code'] >= 400:
        plugin.notify('ERROR', plugin.localize(30716))
        return False

    # Check DRM in the m3u8 file
    manifest = urlquick.get(json_parser["url"],
                            headers={
                                'User-Agent': web_utils.get_random_ua},
                            max_age=-1).text
    if 'drm' in manifest:

        if cqu.get_kodi_version() < 18:
            xbmcgui.Dialog().ok('Info', plugin.localize(30602))
            return False
        else:
            video_format = 'dash'

    if video_format == 'hls':

        root = os.path.dirname(json_parser["url"])

        url_without_max_bitrate_list = json_parser["url"].split(
            '&max_bitrate=')
        if '&' in url_without_max_bitrate_list[1]:
            url_without_max_bitrate = url_without_max_bitrate_list[
                0] + '&' + url_without_max_bitrate_list[1].split('&')[1]
        else:
            url_without_max_bitrate = url_without_max_bitrate_list[0]
        manifest = urlquick.get(
            url_without_max_bitrate,
            headers={'User-Agent': web_utils.get_random_ua},
            max_age=-1)

        lines = manifest.text.splitlines()
        final_video_url = ''
        all_datas_videos_quality = []
        all_datas_videos_path = []
        for k in range(0, len(lines) - 1):
            if 'RESOLUTION=' in lines[k]:
                all_datas_videos_quality.append(
                    re.compile(r'RESOLUTION=(.*?),').findall(lines[k])[0])
                all_datas_videos_path.append(root + '/' + lines[k + 1])
        if DESIRED_QUALITY == "DIALOG":
            seleted_item = xbmcgui.Dialog().select(
                plugin.localize(LABELS['choose_video_quality']),
                all_datas_videos_quality)

            if seleted_item == -1:
                return False

            final_video_url = all_datas_videos_path[seleted_item]
        elif DESIRED_QUALITY == 'BEST':
            # Last video in the Best
            for k in all_datas_videos_path:
                url = k
            final_video_url = url
        else:
            final_video_url = all_datas_videos_path[0]

        if download_mode:
            return download.download_video(final_video_url, video_label)
        return final_video_url

    else:
        if download_mode:
            xbmcgui.Dialog().ok('Info', plugin.localize(30603))
            return False

        url_json = URL_VIDEO_STREAM % (video_id, video_format)
        htlm_json = urlquick.get(
            url_json,
            headers={'User-Agent': web_utils.get_random_ua},
            max_age=-1)
        json_parser = json.loads(htlm_json.text)

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

        item = Listitem()
        item.path = json_parser["url"]
        item.label = item_dict['label']
        item.info.update(item_dict['info'])
        item.art.update(item_dict['art'])
        item.property['inputstreamaddon'] = 'inputstream.adaptive'
        item.property['inputstream.adaptive.manifest_type'] = 'mpd'
        item.property[
            'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
        item.property[
            'inputstream.adaptive.license_key'] = URL_LICENCE_KEY % video_id

        return item
示例#14
0
def get_video_url(plugin,
                  item_id,
                  video_url,
                  item_dict=None,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    resp = urlquick.get(video_url,
                        headers={'User-Agent': web_utils.get_random_ua()},
                        max_age=-1)
    if len(
            re.compile(r'www.wat.tv/embedframe/(.*?)[\"\?]').findall(
                resp.text)) > 0:
        video_id = re.compile(r'www.wat.tv/embedframe/(.*?)[\"\?]').findall(
            resp.text)[0]
        url_wat_embed = URL_WAT_BY_ID % video_id
        wat_embed_html = urlquick.get(
            url_wat_embed,
            headers={'User-Agent': web_utils.get_random_ua()},
            max_age=-1)
        stream_id = re.compile('UVID=(.*?)&').findall(wat_embed_html.text)[0]
        url_json = URL_VIDEO_STREAM_WAT % stream_id
        htlm_json = urlquick.get(
            url_json,
            headers={'User-Agent': web_utils.get_random_ua()},
            max_age=-1)
        json_parser = json.loads(htlm_json.text)

        # Check DRM in the m3u8 file
        manifest = urlquick.get(
            json_parser["hls"],
            headers={'User-Agent': web_utils.get_random_ua()},
            max_age=-1)
        if 'drm' in manifest:
            Script.notify("TEST", plugin.localize(LABELS['drm_notification']),
                          Script.NOTIFY_INFO)
            return False

        root = os.path.dirname(json_parser["hls"])

        manifest = urlquick.get(
            json_parser["hls"].split('&max_bitrate=')[0],
            headers={'User-Agent': web_utils.get_random_ua()},
            max_age=-1)

        lines = manifest.text.splitlines()
        final_video_url = ''
        all_datas_videos_quality = []
        all_datas_videos_path = []
        for k in range(0, len(lines) - 1):
            if 'RESOLUTION=' in lines[k]:
                all_datas_videos_quality.append(
                    re.compile(r'RESOLUTION=(.*?)$').findall(
                        lines[k])[0].split(',')[0])
                all_datas_videos_path.append(root + '/' + lines[k + 1])
        if DESIRED_QUALITY == "DIALOG":
            seleted_item = xbmcgui.Dialog().select(
                plugin.localize(LABELS['choose_video_quality']),
                all_datas_videos_quality)
            final_video_url = all_datas_videos_path[seleted_item]
        elif DESIRED_QUALITY == 'BEST':
            # Last video in the Best
            for k in all_datas_videos_path:
                url = k
            final_video_url = url
        else:
            final_video_url = all_datas_videos_path[0]

        if download_mode:
            return download.download_video(final_video_url, video_label)
        return final_video_url

    else:
        video_id = re.compile(r'tf1.fr/embedplayer/(.*?)[\"\?]').findall(
            resp.text)[0]
        video_format = 'hls'
        url_json = URL_VIDEO_STREAM % (video_id, video_format)
        htlm_json = urlquick.get(
            url_json,
            headers={'User-Agent': web_utils.get_random_ua()},
            max_age=-1)
        json_parser = json.loads(htlm_json.text)

        if json_parser['code'] >= 400:
            plugin.notify('ERROR', plugin.localize(30716))
            return False

        # Check DRM in the m3u8 file
        manifest = urlquick.get(json_parser["url"],
                                headers={
                                    'User-Agent': web_utils.get_random_ua()
                                },
                                max_age=-1).text
        if 'drm' in manifest:

            if cqu.get_kodi_version() < 18:
                xbmcgui.Dialog().ok('Info', plugin.localize(30602))
                return False
            else:
                video_format = 'dash'

        if video_format == 'hls':

            final_video_url = json_parser["url"].replace('2800000', '4000000')
            if download_mode:
                return download.download_video(final_video_url, video_label)
            return final_video_url

        else:
            if download_mode:
                xbmcgui.Dialog().ok('Info', plugin.localize(30603))
                return False

            url_json = URL_VIDEO_STREAM % (video_id, video_format)
            htlm_json = urlquick.get(
                url_json,
                headers={'User-Agent': web_utils.get_random_ua()},
                max_age=-1)
            json_parser = json.loads(htlm_json.text)

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

            item = Listitem()
            item.path = json_parser["url"]
            item.label = item_dict['label']
            item.info.update(item_dict['info'])
            item.art.update(item_dict['art'])
            item.property['inputstreamaddon'] = 'inputstream.adaptive'
            item.property['inputstream.adaptive.manifest_type'] = 'mpd'
            item.property[
                'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
            item.property[
                'inputstream.adaptive.license_key'] = URL_LICENCE_KEY % video_id

            return item
def get_video_url(plugin,
                  item_id,
                  next_url,
                  item_dict=None,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    resp = urlquick.get(
        next_url, headers={'User-Agent': web_utils.get_random_ua()}, max_age=-1)
    json_parser = json.loads(resp.text)

    if json_parser["detail"]["informations"]['consumptionPlatform'] == 'HAPI':

        # Get DeviceId
        header_device_id = {
            'referer':
            'https://secure-player.canal-plus.com/one/prod/v2/',
        }
        resp_device_id = urlquick.get(URL_DEVICE_ID, headers=header_device_id, max_age=-1)
        device_id = re.compile(
            r'deviceId\"\:\"(.*?)\"').findall(resp_device_id.text)[0]

        if xbmc.getCondVisibility('system.platform.android'):

            if cqu.get_kodi_version() < 18:
                xbmcgui.Dialog().ok('Info', plugin.localize(30602))
                return False

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

            if download_mode:
                xbmcgui.Dialog().ok('Info', plugin.localize(30603))
                return False

            Script.notify("INFO", plugin.localize(LABELS['drm_notification']),
                          Script.NOTIFY_INFO)
            return False

            # Get Portail Id
            session_requests = requests.session()
            resp_app_config = session_requests.get(URL_REPLAY % item_id)
            json_app_config = re.compile('window.app_config=(.*?)};').findall(
                resp_app_config.text)[0]
            json_app_config_parser = json.loads(json_app_config + ('}'))
            portail_id = json_app_config_parser["api"]["pass"][
                "portailIdEncrypted"]

            # Get PassToken
            payload = {
                'deviceId': 'unknown',
                'vect': 'INTERNET',
                'media': 'PC',
                'portailId': portail_id
            }
            resp_token_mycanal = session_requests.post(URL_TOKEN, data=payload)
            json_token_parser = json.loads(resp_token_mycanal.text)
            pass_token = json_token_parser["response"]["passToken"]

            # Get stream Id
            for stream_datas in json_parser["detail"]["informations"]["videoURLs"]:
                if stream_datas["drmType"] == "DRM PlayReady":
                    payload = {
                        'comMode': stream_datas['comMode'],
                        'contentId': stream_datas['contentId'],
                        'distMode': stream_datas['distMode'],
                        'distTechnology': stream_datas['distTechnology'],
                        'drmType': stream_datas['drmType'],
                        'functionalType': stream_datas['functionalType'],
                        'hash': stream_datas['hash'],
                        'idKey': stream_datas['idKey'],
                        'quality': stream_datas['quality']
                    }
                    payload = json.dumps(payload)
                    headers = {
                        'Accept':
                        'application/json, text/plain, */*',
                        'Authorization':
                        'PASS Token="%s"' % pass_token,
                        'Content-Type':
                        'application/json; charset=UTF-8',
                        'XX-DEVICE':
                        'pc %s' % device_id,
                        'XX-DOMAIN':
                        'cpfra',
                        'XX-OPERATOR':
                        'pc',
                        'XX-Profile-Id':
                        '0',
                        'XX-SERVICE':
                        'mycanal',
                        'User-Agent':
                        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36'
                    }
                    resp_stream_datas = session_requests.put(
                        URL_STREAM_DATAS, data=payload, headers=headers)
                    jsonparser_stream_datas = json.loads(resp_stream_datas.text)

                    resp_real_stream_datas = session_requests.get(
                        jsonparser_stream_datas['@medias'], headers=headers)
                    jsonparser_real_stream_datas = json.loads(
                        resp_real_stream_datas.text)

                    item = Listitem()
                    item.path = jsonparser_real_stream_datas["VF"][0]["media"][0]["distribURL"] + '/manifest'
                    item.label = item_dict['label']
                    item.info.update(item_dict['info'])
                    item.art.update(item_dict['art'])
                    item.property['inputstreamaddon'] = 'inputstream.adaptive'
                    item.property['inputstream.adaptive.manifest_type'] = 'ism'
                    item.property[
                        'inputstream.adaptive.license_type'] = 'com.microsoft.playready'
                    return item
        else:
            if cqu.get_kodi_version() < 18:
                xbmcgui.Dialog().ok('Info', plugin.localize(30602))
                return False

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

            if download_mode:
                xbmcgui.Dialog().ok('Info', plugin.localize(30603))
                return False

            Script.notify("INFO", plugin.localize(LABELS['drm_notification']),
                          Script.NOTIFY_INFO)
            return False

            # Get Portail Id
            session_requests = requests.session()
            resp_app_config = session_requests.get(URL_REPLAY % item_id)
            json_app_config = re.compile('window.app_config=(.*?)};').findall(
                resp_app_config.text)[0]
            json_app_config_parser = json.loads(json_app_config + ('}'))
            portail_id = json_app_config_parser["api"]["pass"][
                "portailIdEncrypted"]

            # Get PassToken
            payload = {
                'deviceId': 'unknown',
                'vect': 'INTERNET',
                'media': 'PC',
                'portailId': portail_id
            }
            resp_token_mycanal = session_requests.post(URL_TOKEN, data=payload)
            json_token_parser = json.loads(resp_token_mycanal.text)
            pass_token = json_token_parser["response"]["passToken"]

            # Get stream Id
            for stream_datas in json_parser["detail"]["informations"]["videoURLs"]:
                if 'Widevine' in stream_datas["drmType"]:
                    payload = {
                        'comMode': stream_datas['comMode'],
                        'contentId': stream_datas['contentId'],
                        'distMode': stream_datas['distMode'],
                        'distTechnology': stream_datas['distTechnology'],
                        'drmType': stream_datas['drmType'],
                        'functionalType': stream_datas['functionalType'],
                        'hash': stream_datas['hash'],
                        'idKey': stream_datas['idKey'],
                        'quality': stream_datas['quality']
                    }
                    payload = json.dumps(payload)
                    headers = {
                        'Accept':
                        'application/json, text/plain, */*',
                        'Authorization':
                        'PASS Token="%s"' % pass_token,
                        'Content-Type':
                        'application/json; charset=UTF-8',
                        'XX-DEVICE':
                        'pc %s' % device_id,
                        'XX-DOMAIN':
                        'cpfra',
                        'XX-OPERATOR':
                        'pc',
                        'XX-Profile-Id':
                        '0',
                        'XX-SERVICE':
                        'mycanal',
                        'User-Agent':
                        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36'
                    }
                    resp_stream_datas = session_requests.put(
                        URL_STREAM_DATAS, data=payload, headers=headers)
                    jsonparser_stream_datas = json.loads(resp_stream_datas.text)

                    resp_real_stream_datas = session_requests.get(
                        jsonparser_stream_datas['@medias'], headers=headers)
                    jsonparser_real_stream_datas = json.loads(
                        resp_real_stream_datas.text)

                    item = Listitem()
                    item.path = jsonparser_real_stream_datas["VF"][0]["media"][0]["distribURL"] + '/manifest'
                    item.label = item_dict['label']
                    item.info.update(item_dict['info'])
                    item.art.update(item_dict['art'])
                    item.property['inputstreamaddon'] = 'inputstream.adaptive'
                    item.property['inputstream.adaptive.manifest_type'] = 'ism'
                    item.property[
                        'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
                    value_pass_token = 'PASS Token="%s"' % pass_token
                    headers2 = {
                        'Accept':
                        'application/json, text/plain, */*',
                        'Authorization':
                        value_pass_token,
                        'Content-Type':
                        'text/plain',
                        'User-Agent':
                        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36',
                        'Origin':
                        'https://www.mycanal.fr',
                        'XX-DEVICE':
                        'pc %s' % device_id,
                        'XX-DOMAIN':
                        'cpfra',
                        'XX-OPERATOR':
                        'pc',
                        'XX-Profile-Id':
                        '0',
                        'XX-SERVICE':
                        'mycanal',
                    }
                    # Return HTTP 200 but the response is not correctly interpreted by inputstream (https://github.com/peak3d/inputstream.adaptive/issues/267)
                    item.property['inputstream.adaptive.license_key'] = jsonparser_stream_datas['@licence'] + '?drmType=DRM%20Widevine' + '|%s|b{SSM}|' % urlencode(headers2)
                    return item

    stream_url = ''
    for stream_datas in json_parser["detail"]["informations"]["videoURLs"]:
        if stream_datas["encryption"] == 'clear':
            stream_url = stream_datas["videoURL"]

    if download_mode:
        return download.download_video(stream_url, video_label)
    return stream_url
示例#16
0
def get_video_url(plugin, item_id, data_video_id, item_dict, **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

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

    # create session request
    session_requests = requests.session()

    # Get data_account / data_player
    resp = session_requests.get(URL_ROOT)
    js_id_all = re.compile(r'uktv\-static\/prod\/play\/(.*?)\.js').findall(
        resp.text)
    for js_id in js_id_all:
        resp2 = session_requests.get(URL_BRIGHTCOVE_DATAS % js_id)
        if len(
                re.compile(r'VUE_APP_BRIGHTCOVE_ACCOUNT\:\"(.*?)\"').findall(
                    resp2.text)) > 0:
            data_account = re.compile(
                r'VUE_APP_BRIGHTCOVE_ACCOUNT\:\"(.*?)\"').findall(
                    resp2.text)[0]
            data_player = re.compile(
                r'VUE_APP_BRIGHTCOVE_PLAYER\:\"(.*?)\"').findall(resp2.text)[0]
            break

    # Method to get JSON from 'edge.api.brightcove.com'
    resp3 = session_requests.get(
        URL_BRIGHTCOVE_VIDEO_JSON % (data_account, data_video_id),
        headers={
            'User-Agent':
            'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36',
            'Accept':
            'application/json;pk=%s' %
            (get_brightcove_policy_key(data_account, data_player))
        })

    json_parser = json.loads(resp3.text)

    video_url = ''
    licence_key = ''
    if 'sources' in json_parser:
        for url in json_parser["sources"]:
            if 'src' in url:
                if 'com.widevine.alpha' in url["key_systems"]:
                    video_url = url["src"]
                    licence_key = url["key_systems"]['com.widevine.alpha'][
                        'license_url']

    item = Listitem()
    item.path = video_url
    item.label = item_dict['label']
    item.info.update(item_dict['info'])
    item.art.update(item_dict['art'])
    item.property['inputstreamaddon'] = 'inputstream.adaptive'
    item.property['inputstream.adaptive.manifest_type'] = 'mpd'
    item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
    item.property[
        'inputstream.adaptive.license_key'] = licence_key + '|Content-Type=&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36&Host=manifest.prod.boltdns.net|R{SSM}|'

    return item
示例#17
0
def get_live_url(plugin, item_id, video_id, item_dict, **kwargs):

    if cqu.get_kodi_version() < 18:
        xbmcgui.Dialog().ok('Info', plugin.localize(30602))
        return False

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

    # create session request
    session_requests = requests.session()
    session_requests.get(URL_LOGIN_MODAL)

    resptokenid = session_requests.get(URL_LOGIN_TOKEN)
    token_id = re.compile(r'tokenId: \'(.*?)\'').findall(resptokenid.text)[2]

    if plugin.setting.get_string(
            'uktvplay.login') == '' or plugin.setting.get_string(
                'uktvplay.password') == '':
        xbmcgui.Dialog().ok('Info',
                            plugin.localize(30604) %
                            ('UKTVPlay', 'https://uktvplay.uktv.co.uk'))
        return False

    # Build PAYLOAD
    payload = {
        'email': plugin.setting.get_string('uktvplay.login'),
        'password': plugin.setting.get_string('uktvplay.password')
    }
    payload = json.dumps(payload)

    # LOGIN
    # KO - resp2 = session_urlquick.post(
    #     URL_COMPTE_LOGIN, data=payload,
    #     headers={'User-Agent': web_utils.get_ua, 'referer': URL_COMPTE_LOGIN})
    resplogin = session_requests.post(
        URL_COMPTE_LOGIN, data=payload, headers={
            'Accept': 'application/json, text/plain, */*',
            'Content-Type': 'application/json;charset=UTF-8',
            'Origin': 'https://uktvplay.uktv.co.uk',
            'Referer': 'https://uktvplay.uktv.co.uk/account/',
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36',
            'X-TokenId': token_id,
            'X-Version': '9.0.0'
        })
    if resplogin.status_code >= 400:
        plugin.notify('ERROR', 'UKTVPlay : ' + plugin.localize(30711))
        return False
    json_parser_resplogin = json.loads(resplogin.content)

    if 'home_uktvplay' in item_id:
        channel_uktvplay_id = 'home'
    else:
        channel_uktvplay_id = item_id

    respdatachannel = session_requests.get(URL_LIVE % channel_uktvplay_id)
    data_channel = re.compile(r'data\-channel\=\"(.*?)\"').findall(
        respdatachannel.text)[0]

    respkey = session_requests.get(URL_LIVE_KEY)
    app_key = re.compile(r'app\_key"\ \: \"(.*?)\"').findall(respkey.text)[0]

    resptoken = session_requests.get(URL_LIVE_TOKEN % data_channel)
    json_parser_resptoken = json.loads(resptoken.text)

    respstreamdatas = session_requests.post(
        URL_STREAM_LIVE % (data_channel, app_key,
                           str(json_parser_resplogin["accountId"])),
        headers={
            'Token-Expiry': json_parser_resptoken["expiry"],
            'Token': json_parser_resptoken["token"],
            'Uvid': data_channel,
            'Userid': str(json_parser_resplogin["accountId"])
        })
    json_parser = json.loads(respstreamdatas.text)

    item = Listitem()
    item.path = json_parser["response"]["drm"]["widevine"]["stream"]
    if item_dict:
        if 'label' in item_dict:
            item.label = item_dict['label']
        if 'info' in item_dict:
            item.info.update(item_dict['info'])
        if 'art' in item_dict:
            item.art.update(item_dict['art'])
    else:
        item.label = LABELS[channel_uktvplay_id]
        item.art["thumb"] = ""
        item.art["icon"] = ""
        item.art["fanart"] = ""
        item.info["plot"] = LABELS[channel_uktvplay_id]
    item.property['inputstreamaddon'] = 'inputstream.adaptive'
    item.property['inputstream.adaptive.manifest_type'] = 'mpd'
    item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
    item.property[
        'inputstream.adaptive.license_key'] = json_parser["response"]["drm"]["widevine"]["licenseAcquisitionUrl"] + '|Content-Type=&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36|R{SSM}|'

    return item
def get_video_url(plugin,
                  item_id,
                  video_id,
                  item_dict=None,
                  download_mode=False,
                  video_label=None,
                  **kwargs):

    if cqu.get_kodi_version() < 18:
        video_json = urlquick.get(URL_JSON_VIDEO % video_id,
                                  headers={
                                      'User-Agent': web_utils.get_random_ua,
                                      'x-customer-name': 'rtlbe'
                                  },
                                  max_age=-1)
        json_parser = json.loads(video_json.text)

        video_assets = json_parser['clips'][0]['assets']
        if video_assets is None:
            plugin.notify('ERROR', plugin.localize(30721))
            return False

        final_video_url = ''
        all_datas_videos_quality = []
        all_datas_videos_path = []
        for asset in video_assets:
            if 'http_h264' in asset["type"]:
                all_datas_videos_quality.append(asset["video_quality"])
                all_datas_videos_path.append(asset['full_physical_path'])
            elif 'h264' in asset["type"]:
                manifest = urlquick.get(
                    asset['full_physical_path'],
                    headers={'User-Agent': web_utils.get_random_ua},
                    max_age=-1)
                if 'drm' not in manifest.text:
                    all_datas_videos_quality.append(asset["video_quality"])
                    all_datas_videos_path.append(asset['full_physical_path'])

        if len(all_datas_videos_quality) == 0:
            xbmcgui.Dialog().ok('Info', plugin.localize(30602))
            return False
        elif len(all_datas_videos_quality) == 1:
            final_video_url = all_datas_videos_path[0]
        else:
            if DESIRED_QUALITY == "DIALOG":
                seleted_item = xbmcgui.Dialog().select(
                    plugin.localize(LABELS['choose_video_quality']),
                    all_datas_videos_quality)
                if seleted_item == -1:
                    return False
                final_video_url = all_datas_videos_path[seleted_item]
            elif DESIRED_QUALITY == "BEST":
                url_best = ''
                i = 0
                for data_video in all_datas_videos_quality:
                    if 'lq' not in data_video:
                        url_best = all_datas_videos_path[i]
                    i = i + 1
                final_video_url = url_best
            else:
                final_video_url = all_datas_videos_path[0]

        if download_mode:
            return download.download_video(final_video_url, video_label)
        return final_video_url

    else:
        video_json = urlquick.get(URL_JSON_VIDEO % video_id,
                                  headers={
                                      'User-Agent': web_utils.get_random_ua,
                                      'x-customer-name': 'rtlbe'
                                  },
                                  max_age=-1)
        json_parser = json.loads(video_json.text)

        video_assets = json_parser['clips'][0]['assets']
        if video_assets is None:
            plugin.notify('ERROR', plugin.localize(30721))
            return None

        resp_js_id = urlquick.get(URL_GET_JS_ID_API_KEY)
        js_id = re.compile(r'client\-(.*?)\.bundle\.js').findall(
            resp_js_id.text)[0]
        resp = urlquick.get(URL_API_KEY % js_id)

        api_key = re.compile(
            r'\"sso-login.rtl.be\"\,cdn\:\"eu1.gigya.com\"\,key\:\"(.*?)\"'
        ).findall(resp.text)[0]

        if plugin.setting.get_string('rtlplaybe.login') == '' or\
                plugin.setting.get_string('rtlplaybe.password') == '':
            xbmcgui.Dialog().ok(
                'Info',
                plugin.localize(30604) %
                ('RTLPlay (BE)', 'https://www.rtlplay.be'))
            return False

        # Build PAYLOAD
        payload = {
            "loginID": plugin.setting.get_string('rtlplaybe.login'),
            "password": plugin.setting.get_string('rtlplaybe.password'),
            "apiKey": api_key,
            "format": "jsonp",
            "callback": "jsonp_3bbusffr388pem4"
        }
        # LOGIN
        resp2 = urlquick.post(URL_COMPTE_LOGIN,
                              data=payload,
                              headers={
                                  'User-Agent': web_utils.get_random_ua,
                                  'referer': 'https://www.rtlplay.be/connexion'
                              })
        json_parser = json.loads(
            resp2.text.replace('jsonp_3bbusffr388pem4(', '').replace(');', ''))
        if "UID" not in json_parser:
            plugin.notify('ERROR', 'RTLPlay (BE) : ' + plugin.localize(30711))
            return None
        account_id = json_parser["UID"]
        account_timestamp = json_parser["signatureTimestamp"]
        account_signature = json_parser["UIDSignature"]

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

        # Build PAYLOAD headers
        payload_headers = {
            'x-auth-gigya-signature': account_signature,
            'x-auth-gigya-signature-timestamp': account_timestamp,
            'x-auth-gigya-uid': account_id,
            'User-Agent': web_utils.get_random_ua,
            'x-customer-name': 'rtlbe'
        }
        token_json = urlquick.get(URL_TOKEN_DRM % (account_id, video_id),
                                  headers=payload_headers,
                                  max_age=-1)
        token_jsonparser = json.loads(token_json.text)
        token = token_jsonparser["token"]

        subtitle_url = ''
        if plugin.setting.get_boolean('active_subtitle'):
            for asset in video_assets:
                if 'subtitle_vtt' in asset["type"]:
                    subtitle_url = asset['full_physical_path']

        for asset in video_assets:
            if 'usp_dashcenc_h264' in asset["type"]:
                item = Listitem()
                item.path = asset['full_physical_path']
                if 'http' in subtitle_url:
                    item.subtitles.append(subtitle_url)
                item.label = item_dict['label']
                item.info.update(item_dict['info'])
                item.art.update(item_dict['art'])
                item.property['inputstreamaddon'] = 'inputstream.adaptive'
                item.property['inputstream.adaptive.manifest_type'] = 'mpd'
                item.property[
                    'inputstream.adaptive.license_type'] = 'com.widevine.alpha'
                item.property[
                    'inputstream.adaptive.license_key'] = URL_LICENCE_KEY % token
                return item
        for asset in video_assets:
            if 'http_h264' in asset["type"]:
                if "hd" in asset["video_quality"]:
                    item = Listitem()
                    item.path = asset['full_physical_path']
                    if 'http' in subtitle_url:
                        item.subtitles.append(subtitle_url)
                    item.label = item_dict['label']
                    item.info.update(item_dict['info'])
                    item.art.update(item_dict['art'])
                    return item
        return False