Ejemplo n.º 1
0
def get_video_url(params):
    """Get video URL and start video player"""
    stream_html = ''
    if params.next == 'play_l':
        stream_html = utils.get_webcontent(URL_LIVE_ID)
    elif params.next == 'play_r' or params.next == 'download':
        stream_html = utils.get_webcontent(params.url)
    stream_id_list = re.compile('video-asset-id="(.*?)"').findall(stream_html)
    if len(stream_id_list) > 0:
        stream_pcode = utils.get_webcontent(URL_GET_JS_PCODE)
        pcode = re.compile('ooyalaPCode\:"(.*?)"').findall(stream_pcode)[0]
        stream_json = utils.get_webcontent(URL_VIDEO_VOD %
                                           (pcode, stream_id_list[0]))
        stream_jsonparser = json.loads(stream_json)
        # Get Value url encodebase64
        if 'streams' in stream_jsonparser["authorization_data"][
                stream_id_list[0]]:
            for stream in stream_jsonparser["authorization_data"][
                    stream_id_list[0]]["streams"]:
                if stream["delivery_type"] == 'hls':
                    url_base64 = stream["url"]["data"]
            return base64.standard_b64decode(url_base64)
        else:
            # TODO catch the error (geo-blocked, deleted, etc ...)
            utils.send_notification(common.ADDON.get_localized_string(30716))
    return None
Ejemplo n.º 2
0
def get_video_url(params):
    """Get video URL and start video player"""
    if params.next == 'play_l':
        return params.url_live
    elif params.next == 'play_r' or params.next == 'download_video':

        session_requests = requests.session()

        # Build PAYLOAD
        payload = {
            'loginID':
            common.PLUGIN.get_setting(
                params.channel_id.rsplit('.', 1)[0] + '.login'),
            'password':
            common.PLUGIN.get_setting(
                params.channel_id.rsplit('.', 1)[0] + '.password'),
            'targetEnv':
            'jssdk',
            'APIKey':
            get_api_key(),
            'includeSSOToken':
            'true',
            'authMode':
            'cookie'
        }
        result = session_requests.post(URL_LOGIN, data=payload)
        result_jsonpaser = json.loads(result.text)
        if result_jsonpaser['statusCode'] != 200:
            utils.send_notification(common.ADDON.get_localized_string(30113))
            return None

        headers = {
            'Content-Type': 'application/json',
            'Referer': URL_ROOT + '/vrtnu/'
        }
        data = '{"uid": "%s", ' \
            '"uidsig": "%s", ' \
            '"ts": "%s", ' \
            '"email": "%s"}' % (
            result_jsonpaser['UID'],
            result_jsonpaser['UIDSignature'],
            result_jsonpaser['signatureTimestamp'],
            common.PLUGIN.get_setting(
                params.channel_id.rsplit('.', 1)[0] + '.login'))
        result_2 = session_requests.post(URL_TOKEN, data=data, headers=headers)

        build_url = params.video_url[:-1] + '.mssecurevideo.json'
        result_3 = session_requests.get(build_url)
        video_id_json = json.loads(result_3.text)
        video_id = ''
        for key in video_id_json.iteritems():
            video_id = video_id_json[key[0]]['videoid']

        result_4 = session_requests.get(URL_STREAM_JSON % video_id)
        streams_json = json.loads(result_4.text)
        url = ''
        for stream in streams_json['targetUrls']:
            if 'HLS' in stream['type']:
                url = stream['url']
        return url
def ytdl_resolver(url_stream):

    YDStreamExtractor = __import__('YDStreamExtractor')

    quality = 0
    if DESIRED_QUALITY == "DIALOG":
        all_quality = ['SD', '720p', '1080p', 'Highest available']
        seleted_item = common.sp.xbmcgui.Dialog().select(
            common.GETTEXT('Choose video quality'), all_quality)

        if seleted_item > -1:
            selected_quality_string = all_quality[seleted_item]
            quality_string = {
                'SD': 0,
                '720p': 1,
                '1080p': 2,
                'Highest available': 3
            }
            quality = quality_string[selected_quality_string]
        else:
            return None
    elif DESIRED_QUALITY == "BEST":
        quality = 3

    vid = YDStreamExtractor.getVideoInfo(url_stream,
                                         quality=quality,
                                         resolve_redirects=True)
    if vid is None:
        # TODO catch the error (geo-blocked, deleted, etc ...)
        utils.send_notification(common.ADDON.get_localized_string(30716))
        return None
    else:
        return vid.streamURL()
Ejemplo n.º 4
0
def get_video_url(params):
    """Get video URL and start video player"""
    video_json = utils.get_webcontent(URL_JSON_VIDEO % (params.video_id),
                                      random_ua=True)
    json_parser = json.loads(video_json)

    print 'COUCOU'
    print '\n\n' + video_json + '\n\n'

    video_assets = json_parser['clips'][0]['assets']
    if video_assets is None:
        utils.send_notification(common.ADDON.get_localized_string(30712))
        return ''

    # "type":"primetime_phls_h264" => Video protected by DRM (m3u8)
    # "type":"usp_hls_h264" => Video not protected by DRM (m3u8)
    # "type":"usp_dashcenc_h264" => No supported by Kodi (MDP)
    # "type":"usp_hlsfp_h264" => Video protected by DRM (m3u8)
    # "type":"http_h264" => Video not proted by DRM (mp4) (Quality SD "video_quality":"sd", HD "video_quality":"hq", HD "video_quality":"hd", HD "video_quality":"lq", 3G)
    # "type":"http_subtitle_vtt_sm" => Subtitle (in English TVShows)

    desired_quality = common.PLUGIN.get_setting('quality')
    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'].encode('utf-8'))
        elif 'h264' in asset["type"]:
            manifest = utils.get_webcontent(
                asset['full_physical_path'].encode('utf-8'), random_ua=True)
            if 'drm' not in manifest:
                all_datas_videos_quality.append(asset["video_quality"])
                all_datas_videos_path.append(
                    asset['full_physical_path'].encode('utf-8'))

    if len(all_datas_videos_quality) == 0:
        utils.send_notification(common.ADDON.get_localized_string(30702))
        return ''
    elif len(all_datas_videos_quality) == 1:
        return all_datas_videos_path[0]
    else:
        if desired_quality == "DIALOG":
            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)
            if seleted_item == -1:
                return ''
            return 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
            return url_best
        else:
            return all_datas_videos_path[0]
def get_brightcove_video_json(data_account, data_player, data_video_id):

    # Method to get JSON from 'edge.api.brightcove.com'
    file_json = utils.download_catalog(
        URL_BRIGHTCOVE_VIDEO_JSON % (data_account, data_video_id),
        '%s_%s_replay.json' % (data_account, data_video_id),
        force_dl=False,
        request_type='get',
        post_dic={},
        random_ua=False,
        specific_headers={
            'Accept':
            'application/json;pk=%s' %
            (get_brightcove_policy_key(data_account, data_player))
        },
        params={})
    video_json = open(file_json).read()
    json_parser = json.loads(video_json)

    video_url = ''
    if 'sources' in json_parser:
        for url in json_parser["sources"]:
            if 'src' in url:
                if 'm3u8' in url["src"]:
                    video_url = url["src"]
    else:
        if json_parser[0]['error_code'] == "ACCESS_DENIED":
            utils.send_notification(common.ADDON.get_localized_string(30713))
            return None
    return video_url
Ejemplo n.º 6
0
def get_video_url(params):
    """Get video URL and start video player"""
    video_json = utils.get_webcontent(
        URL_JSON_VIDEO % (params.video_id),
        random_ua=True)
    json_parser = json.loads(video_json)

    video_assets = json_parser['clips'][0]['assets']
    if video_assets is None:
        utils.send_notification(common.ADDON.get_localized_string(30712))
        return ''

    # "type":"primetime_phls_h264" => Video protected by DRM (m3u8)
    # "type":"usp_hls_h264" => Video not protected by DRM (m3u8)
    # "type":"usp_dashcenc_h264" => No supported by Kodi (MDP)
    # "type":"usp_hlsfp_h264" => Video protected by DRM (m3u8)
    # "type":"http_h264" => Video not proted by DRM (mp4) (Quality SD "video_quality":"sd", HD "video_quality":"hq", HD "video_quality":"hd", HD "video_quality":"lq", 3G) 
    # "type":"http_subtitle_vtt_sm" => Subtitle (in English TVShows)

    desired_quality = common.PLUGIN.get_setting('quality')
    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'].encode('utf-8'))
        elif 'h264' in asset["type"]:
            manifest = utils.get_webcontent(
                asset['full_physical_path'].encode('utf-8'),
                random_ua=True)
            if 'drm' not in manifest:
                all_datas_videos_quality.append(asset["video_quality"])
                all_datas_videos_path.append(
                    asset['full_physical_path'].encode('utf-8'))

    if len(all_datas_videos_quality) == 0:
        utils.send_notification(common.ADDON.get_localized_string(30702))
        return ''
    elif len(all_datas_videos_quality) == 1:
        return all_datas_videos_path[0]
    else:
        if desired_quality == "DIALOG":
            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)
            if seleted_item == -1:
                return ''
            return 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
            return url_best
        else:
            return all_datas_videos_path[0]
Ejemplo n.º 7
0
def get_video_url(params):
    """Get video URL and start video player"""

    if params.next == 'play_r' or params.next == 'download_video':
        video_html = utils.get_webcontent(params.video_url)
        video_id = re.compile(r'www.wat.tv/embedframe/(.*?)[\"\?]').findall(
            video_html)[0]
        url_wat_embed = URL_WAT_BY_ID % video_id
        wat_embed_html = utils.get_webcontent(url_wat_embed)

        stream_id = re.compile('UVID=(.*?)&').findall(wat_embed_html)[0]
        url_json = URL_VIDEO_STREAM % stream_id
        htlm_json = utils.get_webcontent(url_json, random_ua=True)
        json_parser = json.loads(htlm_json)

        # Check DRM in the m3u8 file
        manifest = utils.get_webcontent(json_parser["hls"], random_ua=True)
        if 'drm' in manifest:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return ''

        root = os.path.dirname(json_parser["hls"])
        manifest = utils.get_webcontent(
            json_parser["hls"].split('&max_bitrate=')[0])

        lines = manifest.splitlines()
        if DESIRED_QUALITY == "DIALOG":
            all_datas_videos_quality = []
            all_datas_videos_path = []
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    if len(re.compile(r'RESOLUTION=(.*?),').findall(
                            lines[k])) > 0:
                        all_datas_videos_quality.append(
                            re.compile(r'RESOLUTION=(.*?),').findall(
                                lines[k])[0])
                    else:
                        all_datas_videos_quality.append(
                            lines[k].split('RESOLUTION=')[1])
                    all_datas_videos_path.append(root + '/' + lines[k + 1])
            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)
            if seleted_item > -1:
                return all_datas_videos_path[seleted_item].encode('utf-8')
            else:
                return None
        elif DESIRED_QUALITY == 'BEST':
            # Last video in the Best
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    url = root + '/' + lines[k + 1]
            return url
        else:
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    url = root + '/' + lines[k + 1]
                break
            return url
Ejemplo n.º 8
0
def get_video_url(params):
    """Get video URL and start video player"""
    if params.next == 'play_r' or params.next == 'download_video':
        # Just One format of each video (no need of QUALITY)
        stream_html = utils.get_webcontent(params.video_url)
        stream_soup = bs(stream_html, 'html.parser')
        stream_datas = stream_soup.find(
            'div', class_='nrjVideo-player').find_all('meta')
        stream_url = ''
        for stream in stream_datas:
            if 'mp4' in stream.get('content'):
                stream_url = stream.get('content')
        return stream_url
    elif params.next == 'play_l':
        url_live = ''

        session_requests = requests.session()
        result = session_requests.get(URL_COMPTE_LOGIN)

        token_form_login = re.compile(
            r'name=\"login_form\[_token\]\" value=\"(.*?)\"').findall(
                result.text)[0]

        module_name = eval(params.module_path)[-1]

        # Build PAYLOAD
        payload = {
            "login_form[email]":
            common.PLUGIN.get_setting(module_name + '.login'),
            "login_form[password]":
            common.PLUGIN.get_setting(module_name + '.password'),
            "login_form[_token]":
            token_form_login
        }

        # LOGIN
        result_2 = session_requests.post(
            URL_COMPTE_LOGIN,
            data=payload,
            headers=dict(referer=URL_COMPTE_LOGIN))
        if 'adresse e-mail ou le mot de passe est invalide.' \
                in result_2.text.encode('utf-8'):
            utils.send_notification(params.channel_name + ' : ' +
                                    common.ADDON.get_localized_string(30711))
            return None

        # GET page with url_live with the session logged
        result_3 = session_requests.get(
            URL_LIVE_WITH_TOKEN % (params.channel_name),
            headers=dict(referer=URL_LIVE_WITH_TOKEN % (params.channel_name)))

        root_soup = bs(result_3.text, 'html.parser')
        live_soup = root_soup.find('div', class_="player")

        url_live_json = live_soup.get('data-options')
        url_live_json_jsonparser = json.loads(url_live_json)

        return url_live_json_jsonparser["file"]
def get_video_url(params):
    """Get video URL and start video player"""

    desired_quality = common.PLUGIN.get_setting('quality')

    file_prgm = utils.get_webcontent(SHOW_INFO % (params.id_diffusion))
    json_parser = json.loads(file_prgm)

    url_selected = ''

    if desired_quality == "DIALOG":
        all_datas_videos_quality = []
        all_datas_videos_path = []

        for video in json_parser['videos']:
            if 'hls' in video['format']:
                if video['format'] == 'hls_v5_os':
                    all_datas_videos_quality.append("HD")
                else:
                    all_datas_videos_quality.append("SD")
                all_datas_videos_path.append(
                    (video['url'], video['drm']))

        seleted_item = common.sp.xbmcgui.Dialog().select(
            common.GETTEXT('Choose video quality'),
            all_datas_videos_quality)

        if seleted_item == -1:
            return None

        url_selected = all_datas_videos_path[seleted_item][0]
        drm = all_datas_videos_path[seleted_item][1]

    elif desired_quality == "BEST":
        for video in json_parser['videos']:
            if video['format'] == 'hls_v5_os':
                url_selected = video['url']
                drm = video['drm']
            else:
                url_selected = video['url']
                drm = video['drm']
    else:
        for video in json_parser['videos']:
            if video['format'] == 'm3u8-download':
                url_selected = video['url']
                drm = video['drm']
            else:
                url_selected = video['url']
                drm = video['drm']

    if drm:
        utils.send_notification(
            common.ADDON.get_localized_string(30702))
        return None
    else:
        return url_selected
Ejemplo n.º 10
0
def connect_openvpn(config, restart=False, sudopassword=None):
    storage = common.sp.MemStorage('vpn')
    common.PLUGIN.log_debug('Connecting OpenVPN configuration: [%s]' % config)

    if common.PLUGIN.get_setting('vpn.sudo') and \
            common.PLUGIN.get_setting('vpn.sudopsw') and sudopassword is None:

        keyboard = common.sp.xbmc.Keyboard(
            default='',
            heading=common.GETTEXT('Enter your sudo password'),
            hidden=True)
        keyboard.doModal()
        if keyboard.isConfirmed():
            sudopassword = keyboard.getText()

    openvpn = vpnlib.OpenVPN(common.PLUGIN.get_setting('vpn.openvpnfilepath'),
                             config,
                             ip=ip,
                             port=port,
                             args=common.PLUGIN.get_setting('vpn.args'),
                             sudo=common.PLUGIN.get_setting('vpn.sudo'),
                             sudopwd=sudopassword,
                             debug=True)

    try:
        if restart:
            openvpn.disconnect()
            storage['status'] = "disconnected"
        openvpn.connect()
        utils.send_notification(common.GETTEXT('Started VPN connection'),
                                title="OpenVPN",
                                time=3000)

        storage['status'] = "connected"
    except vpnlib.OpenVPNError as exception:
        if exception.errno == 1:
            storage['status'] = "connected"

            if common.sp.xbmcgui.Dialog().yesno(
                    'OpenVPN',
                    common.GETTEXT(
                        'An existing OpenVPN instance appears to be running.'),
                    common.GETTEXT('Disconnect it?')):

                common.PLUGIN.log_debug('User has decided to restart OpenVPN')
                connect_openvpn(config, True, sudopassword)
            else:
                common.PLUGIN.log_debug(
                    'User has decided not to restart OpenVPN')
        else:
            common.sp.xbmcgui.Dialog().ok(
                'OpenVPN',
                common.GETTEXT(
                    'An error has occurred whilst trying to connect OpenVPN'))
            storage['status'] = "failed"
Ejemplo n.º 11
0
def get_video_url(params):
    """Get video URL and start video player"""
    if params.next == 'play_r' or params.next == 'download_video':
        list_stream_json = utils.get_webcontent(URL_STREAM % params.video_id)
        list_stream_jsonparser = json.loads(list_stream_json)

        if 'errors' in list_stream_jsonparser:
            if list_stream_jsonparser["errors"][0]["status"] == '403':
                utils.send_notification(
                    common.ADDON.get_localized_string(30713))
            else:
                utils.send_notification(
                    common.ADDON.get_localized_string(30716))
            return None
        return list_stream_jsonparser["playback"]["streamUrlHls"]
def start_live_tv_stream(params):
    url_live = ''

    session_requests = requests.session()
    result = session_requests.get(URL_COMPTE_LOGIN)

    token_form_login = re.compile(
        r'name=\"login_form\[_token\]\" value=\"(.*?)\"').findall(
            result.text)[0]

    module_name = eval(params.module_path)[-1]

    # Build PAYLOAD
    payload = {
        "login_form[email]":
        common.PLUGIN.get_setting(module_name + '.login'),
        "login_form[password]":
        common.PLUGIN.get_setting(module_name + '.password'),
        "login_form[_token]":
        token_form_login
    }

    # LOGIN
    result_2 = session_requests.post(URL_COMPTE_LOGIN,
                                     data=payload,
                                     headers=dict(referer=URL_COMPTE_LOGIN))
    if 'adresse e-mail ou le mot de passe est invalide.' \
            in result_2.text.encode('utf-8'):
        utils.send_notification(params.channel_name + ' : ' +
                                common.ADDON.get_localized_string(30711))
        return None

    # GET page with url_live with the session logged
    result_3 = session_requests.get(
        URL_LIVE_WITH_TOKEN % (params.channel_name),
        headers=dict(referer=URL_LIVE_WITH_TOKEN % (params.channel_name)))

    root_soup = bs(result_3.text, 'html.parser')
    live_soup = root_soup.find('div', class_="player")

    url_live_json = live_soup.get('data-options')
    url_live_json_jsonparser = json.loads(url_live_json)

    url_live = url_live_json_jsonparser["file"]

    params['url_live'] = url_live
    params['next'] = 'play_l'
    return get_video_url(params)
def get_video_url(params):
    """Get video URL and start video player"""
    if params.next == 'play_l':
        file_path = utils.get_webcontent(URL_ROOT)
        lives_json = re.compile(r'window.__ENV__ = (.*?)\;').findall(
            file_path)[0]
        lives_jsonparser = json.loads(lives_json)
        live_stream_json = file_path = utils.get_webcontent(
            URL_LIVE_STREAM %
            lives_jsonparser[LIVE_ATRES_PLAYER[params.channel_name]])
        live_stream_jsonparser = json.loads(live_stream_json)
        if "sources" in live_stream_jsonparser:
            return live_stream_jsonparser["sources"][0]["src"]
        else:
            utils.send_notification(common.ADDON.get_localized_string(30713))
            return None
Ejemplo n.º 14
0
def start_live_tv_stream(params):
    url_live = ''

    session_requests = requests.session()
    result = session_requests.get(URL_COMPTE_LOGIN)

    token_form_login = re.compile(
        r'name=\"login_form\[_token\]\" value=\"(.*?)\"'
    ).findall(result.text)[0]

    module_name = eval(params.module_path)[-1]

    # Build PAYLOAD
    payload = {
        "login_form[email]": common.PLUGIN.get_setting(
            module_name + '.login'),
        "login_form[password]": common.PLUGIN.get_setting(
            module_name + '.password'),
        "login_form[_token]": token_form_login
    }

    # LOGIN
    result_2 = session_requests.post(
        URL_COMPTE_LOGIN, data=payload, headers=dict(referer=URL_COMPTE_LOGIN))
    if 'adresse e-mail ou le mot de passe est invalide.' \
            in result_2.text.encode('utf-8'):
        utils.send_notification(
            params.channel_name + ' : ' + common.ADDON.get_localized_string(30711))
        return None

    # GET page with url_live with the session logged
    result_3 = session_requests.get(
        URL_LIVE_WITH_TOKEN % (params.channel_name),
        headers=dict(
            referer=URL_LIVE_WITH_TOKEN % (params.channel_name)))

    root_soup = bs(result_3.text, 'html.parser')
    live_soup = root_soup.find('div', class_="player")

    url_live_json = live_soup.get('data-options')
    url_live_json_jsonparser = json.loads(url_live_json)

    url_live = url_live_json_jsonparser["file"]

    params['url_live'] = url_live
    params['next'] = 'play_l'
    return get_video_url(params)
Ejemplo n.º 15
0
def get_video_url(params):
    """Get video URL and start video player"""
    if params.next == 'play_l':
        return params.url_live
    elif params.next == 'play_r_categorie':
        file_path = utils.get_webcontent(URL_VIDEO_BY_ID % params.video_id)
        data_stream = re.compile('data-media=\"(.*?)\"').findall(file_path)[0]
        data_stream = data_stream.replace('"', '"')
        data_stream_json = json.loads(data_stream)
        if 'drm' in data_stream_json["urlHls"]:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return ''
        return data_stream_json["urlHls"]
    elif params.next == 'play_r':
        if 'drm' in params.url_video:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return ''
        return params.url_video
Ejemplo n.º 16
0
def disconnect_openvpn():
    storage = common.sp.MemStorage('vpn')
    common.PLUGIN.log_debug('Disconnecting OpenVPN')
    try:
        storage['status'] = "disconnecting"
        response = vpnlib.is_running(ip, port)
        if response[0]:
            vpnlib.disconnect(ip, port)
            if response[1] is not None:
                utils.send_notification(_('Stopped VPN connection'),
                                        title="OpenVPN",
                                        time=3000)
        storage['status'] = "disconnected"
        common.PLUGIN.log_debug('Disconnect OpenVPN successful')
    except vpnlib.OpenVPNError as exception:
        common.sp.xbmcgui.Dialog().ok(
            'OpenVPN',
            _('An error has occurred whilst trying to connect OpenVPN'))

        storage['status'] = "failed"
Ejemplo n.º 17
0
def get_video_url(params):
    """Get video URL and start video player"""
    if params.next == 'play_l':
        
        session_requests = requests.session()

        lives_datas_json = session_requests.get(URL_LIVE_DATAS % params.channel_name)
        lives_datas_jsonparser = json.loads(lives_datas_json.text)

        root = ''

        if lives_datas_jsonparser["locations"][0]["ask"] is not None:
            lives_stream_json = session_requests.post(
                URL_LIVE_STREAM % lives_datas_jsonparser["locations"][0]["ask"])
            lives_stream_jsonparser = json.loads(lives_stream_json.text)

            url_stream_without_hash = lives_stream_jsonparser["stream_manifest"]

            lives_hash_json = session_requests.post(
                URL_LIVE_HASH,
                data='{"gcp": "%s"}' % (lives_datas_jsonparser["locations"][0]["gcp"]),
                headers={'Connection': 'keep-alive', 'Content-type': 'application/json'})
            lives_hash_jsonparser = json.loads(lives_hash_json.text)

            if 'message' in lives_hash_jsonparser:
                if 'geoblocked' in lives_hash_jsonparser['message']:
                    utils.send_notification(
                        common.ADDON.get_localized_string(30713))
                return None

            m3u8_video_auto = session_requests.get(url_stream_without_hash + '&' + lives_hash_jsonparser["suffix"])
        else:
            lives_stream_json = session_requests.post(
                URL_LIVE_HASH,
                data='{"gcp": "%s"}' % (lives_datas_jsonparser["locations"][0]["gcp"]),
                headers={'Connection': 'keep-alive', 'Content-type': 'application/json'})
            lives_stream_jsonparser = json.loads(lives_stream_json.text)

            if 'message' in lives_stream_jsonparser:
                if 'geoblocked' in lives_stream_jsonparser['message']:
                    utils.send_notification(
                        common.ADDON.get_localized_string(30713))
                return None

            m3u8_video_auto = session_requests.get(lives_stream_jsonparser["stream"])
            root = lives_stream_jsonparser["stream"].split('master.m3u8')[0]

        lines = m3u8_video_auto.text.splitlines()
        if DESIRED_QUALITY == "DIALOG":
            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(
                        lines[k].split('RESOLUTION=')[1])
                    if 'http' in lines[k + 1]:
                        all_datas_videos_path.append(
                            lines[k + 1])
                    else:
                        all_datas_videos_path.append(
                            root + '/' + lines[k + 1])
            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                    all_datas_videos_quality)
            if seleted_item > -1:
                return all_datas_videos_path[seleted_item].encode(
                    'utf-8')
            else:
                return None
        elif DESIRED_QUALITY == 'BEST':
            # Last video in the Best
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    if 'http' in lines[k + 1]:
                        url = lines[k + 1]
                    else:
                        url = root + '/' + lines[k + 1]
            return url
        else:
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    if 'http' in lines[k + 1]:
                        url = lines[k + 1]
                    else:
                        url = root + '/' + lines[k + 1]
                break
            return url
Ejemplo n.º 18
0
def get_video_url(params):
    """Get video URL and start video player"""
    video_json = utils.get_webcontent(
        URL_API_MEDIA % (params.video_id, PARTNER))
    video_json_parser = json.loads(video_json)

    desired_quality = common.PLUGIN.get_setting('quality')

    url = ''
    if 'rendition' in video_json_parser["media"]:
        # (Video Hosted By Allocine)
        if desired_quality == "DIALOG":
            all_datas_videos_quality = []
            all_datas_videos_path = []
            for media in video_json_parser["media"]["rendition"]:
                all_datas_videos_quality.append(
                    media["bandwidth"]["$"])
                all_datas_videos_path.append(media["href"])
            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)
            if seleted_item == -1:
                return None
            url = all_datas_videos_path[seleted_item]
        elif desired_quality == "BEST":
            for media in video_json_parser["media"]["rendition"]:
                url = media["href"]
        else:
            for media in video_json_parser["media"]["rendition"][0]:
                url = media["href"]
        if requests.get(url, stream=True).status_code == 404:
            utils.send_notification(
                common.ADDON.get_localized_string(30710))
            return ''
        return url
    else:
        # (Video Not Hosted By Allocine)
        url_video_embeded = re.compile(
            'src=\'(.*?)\''
            ).findall(video_json_parser["media"]["trailerEmbed"])[0]
        if 'allocine' in url_video_embeded:
            url_video_embeded_html = utils.get_webcontent(url_video_embeded)
            url_video_resolver = re.compile(
                'data-model="(.*?)"'
            ).findall(url_video_embeded_html)[0]
            url_video_resolver = url_video_resolver.replace('"', '"')
            url_video_resolver = url_video_resolver.replace('\\','')
            url_video_resolver = url_video_resolver.replace('&','&')
            url_video_resolver = url_video_resolver.replace('%2F','/')
            # Case Youtube
            if 'youtube' in url_video_resolver:
                video_id = re.compile(
                    'www.youtube.com/embed/(.*?)[\?\"\&]').findall(
                    url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_youtube(
                        video_id, True)
                else:
                    return resolver.get_stream_youtube(
                        video_id, False)
            # Case DailyMotion
            elif 'dailymotion' in url_video_resolver:
                video_id = re.compile(
                    r'embed/video/(.*?)[\"\?]').findall(
                    url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_dailymotion(
                        video_id, True)
                else:
                    return resolver.get_stream_dailymotion(
                        video_id, False)
            # Case Facebook
            elif 'facebook' in url_video_resolver:
                video_id = re.compile(
                    'www.facebook.com/allocine/videos/(.*?)/').findall(
                    url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_facebook(
                        video_id, True)
                else:
                    return resolver.get_stream_facebook(
                        video_id, False)
            # Case Vimeo
            elif 'vimeo' in url_video_resolver:
                video_id = re.compile('player.vimeo.com/video/(.*?)"').findall(
                    url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_vimeo(
                        video_id, True)
                else:
                    return resolver.get_stream_vimeo(
                        video_id, False)
            else:
                return ''
        else:
            # Case Youtube
            if 'youtube' in url_video_embeded:
                video_id = re.compile(
                    'www.youtube.com/embed/(.*?)[\?\"\&]').findall(
                    url_video_embeded)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_youtube(
                        video_id, True)
                else:
                    return resolver.get_stream_youtube(
                        video_id, False)
            else:
                return ''
Ejemplo n.º 19
0
def get_video_url(params):
    """Get video URL and start video player"""

    if params.next == 'play_r' or params.next == 'download_video':

        if 'www.wat.tv/embedframe' in params.program_id:
            url = 'http:' + params.program_id
        elif "http" not in params.program_id:
            if params.program_id[0] == '/':
                params.program_id = params.program_id[1:]
            url = URL_ROOT + params.program_id
        else:
            url = params.program_id
        video_html = utils.get_webcontent(url)

        if 'www.wat.tv/embedframe' in params.program_id:
            video_id = re.compile('UVID=(.*?)&').findall(video_html)[0]
        else:
            video_html_soup = bs(video_html, 'html.parser')
            iframe_player_soup = video_html_soup.find(
                'div',
                class_='iframe_player')
            video_id = iframe_player_soup['data-watid'].encode('utf-8')

        url_json = URL_VIDEO_STREAM % video_id
        htlm_json = utils.get_webcontent(url_json, random_ua=True)
        json_parser = json.loads(htlm_json)

        # Check DRM in the m3u8 file
        manifest = utils.get_webcontent(
            json_parser["hls"],
            random_ua=True)
        if 'drm' in manifest:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return ''

        root = os.path.dirname(json_parser["hls"])
        manifest = utils.get_webcontent(
            json_parser["hls"].split('&max_bitrate=')[0])

        lines = manifest.splitlines()
        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 = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)
            return all_datas_videos_path[seleted_item].encode(
                'utf-8')
        elif DESIRED_QUALITY == 'BEST':
            # Last video in the Best
            for k in all_datas_videos_path:
                url = k
            return url
        else:
            return all_datas_videos_path[0]

    elif params.next == 'play_l':

        # Video_ID 'L_%CHANNEL_NAME%'
        video_id = 'L_%s' % params.channel_name.upper()

        timeserver = str(utils.get_webcontent(URL_TIME))

        auth_key = '%s-%s-%s-%s-%s' % (
            video_id,
            SECRET_KEY,
            APP_NAME,
            SECRET_KEY,
            timeserver
        )

        auth_key = common.sp.md5(auth_key).hexdigest()
        auth_key = auth_key + '/' + timeserver

        post_data = {
            'appName': APP_NAME,
            'method': 'getUrl',
            'mediaId': video_id,
            'authKey': auth_key,
            'version': VERSION,
            'hostingApplicationName': HOSTING_APPLICATION_NAME,
            'hostingApplicationVersion': HOSTING_APPLICATION_VERSION
        }

        url_video = utils.get_webcontent(
            url=URL_TOKEN,
            request_type='post',
            post_dic=post_data)
        url_video = json.loads(url_video)
        url_video = url_video['message'].replace('\\', '')

        return url_video.split('&b=')[0]
Ejemplo n.º 20
0
def build_live_tv_menu(params):
    """
    build_live_tv_menu asks each channel for current live TV
    information and display the concatenation of this to Kodi
    """
    folder_path = eval(params.item_path)

    country = folder_path[-1]
    if country == "fr":
        return live_tv_fr.build_live_tv_menu(params)

    else:

        # First we sort channels
        menu = []
        for channel in eval(params.item_skeleton):
            channel_name = channel[0]
            # If channel isn't disable
            if common.PLUGIN.get_setting(channel_name):
                # Get order value in settings file
                channel_order = common.PLUGIN.get_setting(
                    channel_name + '.order')
                channel_path = list(folder_path)
                channel_path.append(skeleton.CHANNELS[channel_name])

                item = (channel_order, channel_name, channel_path)
                menu.append(item)

        menu = sorted(menu, key=lambda x: x[0])

        listing = []
        for index, (channel_order, channel_name, channel_path) in \
                enumerate(menu):
            params['module_path'] = str(channel_path)
            params['module_name'] = channel_name
            params['channel_label'] = skeleton.LABELS[channel_name]

            channel = utils.get_module(params)

            # Legacy fix (il faudrait remplacer channel_name par
            # module_name dans tous les .py des chaines)
            params['channel_name'] = params.module_name

            item = {}
            # Build context menu (Move up, move down, ...)
            context_menu = []

            item_down = (
                common.GETTEXT('Move down'),
                'XBMC.RunPlugin(' + common.PLUGIN.get_url(
                    action='move',
                    direction='down',
                    item_id_order=channel_name + '.order',
                    displayed_items=menu) + ')'
            )
            item_up = (
                common.GETTEXT('Move up'),
                'XBMC.RunPlugin(' + common.PLUGIN.get_url(
                    action='move',
                    direction='up',
                    item_id_order=channel_name + '.order',
                    displayed_items=menu) + ')'
            )

            if index == 0:
                context_menu.append(item_down)
            elif index == len(menu) - 1:
                context_menu.append(item_up)
            else:
                context_menu.append(item_up)
                context_menu.append(item_down)

            hide = (
                common.GETTEXT('Hide'),
                'XBMC.RunPlugin(' + common.PLUGIN.get_url(
                    action='hide',
                    item_id=channel_name) + ')'
            )
            context_menu.append(hide)

            try:
                item = channel.get_live_item(params)
                if item is not None:
                    if type(item) is dict:
                        item['context_menu'] = context_menu
                        listing.append(item)
                    elif type(item) is list:
                        for subitem in item:
                            subitem['context_menu'] = context_menu
                            listing.append(subitem)
            except Exception:
                title = params['channel_label'] + ' broken'
                utils.send_notification(
                    '', title=title, time=2000)

        return common.PLUGIN.create_listing(
            listing,
            sort_methods=(
                common.sp.xbmcplugin.SORT_METHOD_UNSORTED,
                common.sp.xbmcplugin.SORT_METHOD_LABEL
            ),
            category=common.get_window_title()
        )
def get_video_url(params):
    """Get video URL and start video player"""

    desired_quality = common.PLUGIN.get_setting('quality')

    if params.next == 'play_r' or params.next == 'download_video':

        json_parser = json.loads(
            utils.get_webcontent(SHOW_INFO % (params.id_diffusion)))

        url_selected = ''

        if 'videos' not in json_parser:
            utils.send_notification(common.ADDON.get_localized_string(30710))
            return ''

        if desired_quality == "DIALOG":
            all_datas_videos_quality = []
            all_datas_videos_path = []

            for video in json_parser['videos']:
                if video['format'] == 'hls_v5_os' or \
                        video['format'] == 'm3u8-download':
                    if video['format'] == 'hls_v5_os':
                        all_datas_videos_quality.append("HD")
                    else:
                        all_datas_videos_quality.append("SD")
                    all_datas_videos_path.append((video['url'], video['drm']))

            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)

            if seleted_item == -1:
                return None

            url_selected = all_datas_videos_path[seleted_item][0]
            drm = all_datas_videos_path[seleted_item][1]

        elif desired_quality == "BEST":
            for video in json_parser['videos']:
                if video['format'] == 'hls_v5_os':
                    url_selected = video['url']
                    drm = video['drm']
        else:
            for video in json_parser['videos']:
                if video['format'] == 'm3u8-download':
                    url_selected = video['url']
                    drm = video['drm']

        if drm:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return None
        else:
            return url_selected

    elif params.next == 'play_l':

        list_livesid_json = utils.get_webcontent(URL_LIVES_JSON)
        list_livesid_jsonparser = json.loads(list_livesid_json)

        id_sivideo = list_livesid_jsonparser[params.region]["id_sivideo"]

        live_infos_json = utils.get_webcontent(SHOW_INFO %
                                               id_sivideo.split('@')[0])
        live_infos_jsonparser = json.loads(live_infos_json)

        final_url = ''
        for live_infos in live_infos_jsonparser["videos"]:
            if live_infos["format"] == 'hls':
                final_url = live_infos["url"]

        file_prgm2 = utils.get_webcontent(HDFAUTH_URL % (final_url))
        json_parser2 = json.loads(file_prgm2)

        return json_parser2['url']
def get_video_url(params):
    """Get video URL and start video player"""

    desired_quality = common.PLUGIN.get_setting('quality')

    if params.next == 'play_r' or params.next == 'download_video':
        stream_infos = json.loads(utils.get_webcontent(params.url))

        method = None
        id_diffusion = ''
        urls = []
        for media in stream_infos['content']['medias']:
            if 'catchupId' in media:
                method = 'id_diffusion'
                id_diffusion = media['catchupId']
                break
            elif 'streams' in media:
                method = 'stream_videos'
                for stream in media['streams']:
                    urls.append((stream['format'], stream['url']))
                break
            elif 'sourceUrl' in media:
                return media['sourceUrl']

        if method == 'id_diffusion':
            json_parser = json.loads(
                utils.get_webcontent(URL_INFO_OEUVRE % id_diffusion))

            url_selected = ''

            if desired_quality == "DIALOG":
                all_datas_videos_quality = []
                all_datas_videos_path = []

                for video in json_parser['videos']:
                    if video['format'] == 'hls_v5_os' or \
                            video['format'] == 'm3u8-download':
                        if video['format'] == 'hls_v5_os':
                            all_datas_videos_quality.append("HD")
                        else:
                            all_datas_videos_quality.append("SD")
                        all_datas_videos_path.append(
                            (video['url'], video['drm']))

                seleted_item = common.sp.xbmcgui.Dialog().select(
                    common.GETTEXT('Choose video quality'),
                    all_datas_videos_quality)

                if seleted_item == -1:
                    return None

                url_selected = all_datas_videos_path[seleted_item][0]
                drm = all_datas_videos_path[seleted_item][1]

            elif desired_quality == "BEST":
                for video in json_parser['videos']:
                    if video['format'] == 'hls_v5_os':
                        url_selected = video['url']
                        drm = video['drm']
            else:
                for video in json_parser['videos']:
                    if video['format'] == 'm3u8-download':
                        url_selected = video['url']
                        drm = video['drm']

            if drm:
                utils.send_notification(
                    common.ADDON.get_localized_string(30702))
                return None
            else:
                return url_selected

        elif method == 'stream_videos':
            url_hd = ''
            url_default = ''
            for url in urls:
                if 'hd' in url[0]:
                    url_hd = url[1]
                url_default = url[1]

            if desired_quality == "DIALOG":
                items = []
                for url in urls:
                    items.append(url[0])

                seleted_item = common.sp.xbmcgui.Dialog().select(
                    common.GETTEXT('Choose video quality'),
                    items)

                if seleted_item == -1:
                    return None

                url_selected = items[seleted_item][1]

                if url_hd != '':
                    url_selected = url_hd
                else:
                    url_selected = url_default

            else:
                if url_hd != '':
                    url_selected = url_hd
                else:
                    url_selected = url_default

            return url_selected

        else:
            return None

    elif params.next == 'play_l':

        json_parser = json.loads(utils.get_webcontent(
            LIVE_INFO % (params.channel_name)))

        url_hls_v1 = ''
        url_hls_v5 = ''
        url_hls = ''

        for video in json_parser['videos']:
            if 'format' in video:
                if 'hls_v1_os' in video['format'] and \
                        video['geoblocage'] is not None:
                    url_hls_v1 = video['url']
                if 'hls_v5_os' in video['format'] and \
                        video['geoblocage'] is not None:
                    url_hls_v5 = video['url']
                if 'hls' in video['format']:
                    url_hls = video['url']

        final_url = ''

        # Case France 3 Région
        if url_hls_v1 == '' and url_hls_v5 == '':
            final_url = url_hls
        # Case Jarvis
        if common.sp.xbmc.__version__ == '2.24.0' \
                and url_hls_v1 != '':
            final_url = url_hls_v1
        # Case Krypton, Leia, ...
        if final_url == '' and url_hls_v5 != '':
            final_url = url_hls_v5
        elif final_url == '':
            final_url = url_hls_v1

        file_prgm2 = utils.get_webcontent(HDFAUTH_URL % (final_url))
        json_parser2 = json.loads(file_prgm2)

        return json_parser2['url']
Ejemplo n.º 23
0
def get_video_url(params):
    """Get video URL and start video player"""

    if params.next == 'play_r' or params.next == 'download_video':
        video_html = utils.get_webcontent(params.video_url)
        video_id = re.compile(
            r'www.wat.tv/embedframe/(.*?)[\"\?]').findall(
            video_html)[0]
        url_wat_embed = URL_WAT_BY_ID % video_id
        wat_embed_html = utils.get_webcontent(url_wat_embed)

        stream_id = re.compile('UVID=(.*?)&').findall(wat_embed_html)[0]
        url_json = URL_VIDEO_STREAM % stream_id
        htlm_json = utils.get_webcontent(url_json, random_ua=True)
        json_parser = json.loads(htlm_json)

        # Check DRM in the m3u8 file
        manifest = utils.get_webcontent(
            json_parser["hls"],
            random_ua=True)
        if 'drm' in manifest:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return ''

        root = os.path.dirname(json_parser["hls"])
        manifest = utils.get_webcontent(
            json_parser["hls"].split('&max_bitrate=')[0])

        lines = manifest.splitlines()
        if DESIRED_QUALITY == "DIALOG":
            all_datas_videos_quality = []
            all_datas_videos_path = []
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    if len(re.compile(
                        r'RESOLUTION=(.*?),').findall(
                        lines[k])) > 0:
                        all_datas_videos_quality.append(
                            re.compile(
                            r'RESOLUTION=(.*?),').findall(
                            lines[k])[0])
                    else:
                        all_datas_videos_quality.append(
                            lines[k].split('RESOLUTION=')[1])
                    all_datas_videos_path.append(
                        root + '/' + lines[k + 1])
            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)
            return all_datas_videos_path[seleted_item].encode(
                'utf-8')
        elif DESIRED_QUALITY == 'BEST':
            # Last video in the Best
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    url = root + '/' + lines[k + 1]
            return url
        else:
            for k in range(0, len(lines) - 1):
                if 'RESOLUTION=' in lines[k]:
                    url = root + '/' + lines[k + 1]
                break
            return url
Ejemplo n.º 24
0
def get_video_url(params):
    """Get video URL and start video player"""

    if params.next == 'play_r' or params.next == 'download_video':

        if 'www.wat.tv/embedframe' in params.program_id:
            url = 'http:' + params.program_id
        elif "http" not in params.program_id:
            if params.program_id[0] == '/':
                params.program_id = params.program_id[1:]
            url = URL_ROOT + params.program_id
        else:
            url = params.program_id
        video_html = utils.get_webcontent(url)

        if 'www.wat.tv/embedframe' in params.program_id:
            video_id = re.compile('UVID=(.*?)&').findall(video_html)[0]
        else:
            video_html_soup = bs(video_html, 'html.parser')
            iframe_player_soup = video_html_soup.find(
                'div',
                class_='iframe_player')
            video_id = iframe_player_soup['data-watid'].encode('utf-8')

        url_json = URL_VIDEO_STREAM % video_id
        htlm_json = utils.get_webcontent(url_json, random_ua=True)
        json_parser = json.loads(htlm_json)

        # Check DRM in the m3u8 file
        manifest = utils.get_webcontent(
            json_parser["hls"],
            random_ua=True)
        if 'drm' in manifest:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return ''

        root = os.path.dirname(json_parser["hls"])
        manifest = utils.get_webcontent(
            json_parser["hls"].split('&max_bitrate=')[0])

        lines = manifest.splitlines()
        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 = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)
            return all_datas_videos_path[seleted_item].encode(
                'utf-8')
        elif DESIRED_QUALITY == 'BEST':
            # Last video in the Best
            for k in all_datas_videos_path:
                url = k
            return url
        else:
            return all_datas_videos_path[0]

    elif params.next == 'play_l':

        # Video_ID 'L_%CHANNEL_NAME%'
        video_id = 'L_%s' % params.channel_name.upper()

        timeserver = str(utils.get_webcontent(URL_TIME))

        auth_key = '%s-%s-%s-%s-%s' % (
            video_id,
            SECRET_KEY,
            APP_NAME,
            SECRET_KEY,
            timeserver
        )

        auth_key = common.sp.md5(auth_key).hexdigest()
        auth_key = auth_key + '/' + timeserver

        post_data = {
            'appName': APP_NAME,
            'method': 'getUrl',
            'mediaId': video_id,
            'authKey': auth_key,
            'version': VERSION,
            'hostingApplicationName': HOSTING_APPLICATION_NAME,
            'hostingApplicationVersion': HOSTING_APPLICATION_VERSION
        }

        url_video = utils.get_webcontent(
            url=URL_TOKEN,
            request_type='post',
            post_dic=post_data)
        url_video = json.loads(url_video)
        url_video = url_video['message'].replace('\\', '')

        return url_video.split('&b=')[0]
def get_video_url(params):
    """Get video URL and start video player"""
    video_json = utils.get_webcontent(URL_API_MEDIA %
                                      (params.video_id, PARTNER))
    video_json_parser = json.loads(video_json)

    desired_quality = common.PLUGIN.get_setting('quality')

    url = ''
    if 'rendition' in video_json_parser["media"]:
        # (Video Hosted By Allocine)
        if desired_quality == "DIALOG":
            all_datas_videos_quality = []
            all_datas_videos_path = []
            for media in video_json_parser["media"]["rendition"]:
                all_datas_videos_quality.append(media["bandwidth"]["$"])
                all_datas_videos_path.append(media["href"])
            seleted_item = common.sp.xbmcgui.Dialog().select(
                _('Choose video quality'), all_datas_videos_quality)
            if seleted_item == -1:
                return None
            url = all_datas_videos_path[seleted_item]
        elif desired_quality == "BEST":
            for media in video_json_parser["media"]["rendition"]:
                url = media["href"]
        else:
            for media in video_json_parser["media"]["rendition"][0]:
                url = media["href"]
        if requests.get(url, stream=True).status_code == 404:
            utils.send_notification(common.ADDON.get_localized_string(30111))
            return ''
        return url
    else:
        # (Video Not Hosted By Allocine)
        url_video_embeded = re.compile('src=\'(.*?)\'').findall(
            video_json_parser["media"]["trailerEmbed"])[0]
        if 'allocine' in url_video_embeded:
            url_video_embeded_html = utils.get_webcontent(url_video_embeded)
            url_video_resolver = re.compile('data-model="(.*?)"').findall(
                url_video_embeded_html)[0]
            url_video_resolver = url_video_resolver.replace('"', '"')
            url_video_resolver = url_video_resolver.replace('\\', '')
            url_video_resolver = url_video_resolver.replace('&', '&')
            url_video_resolver = url_video_resolver.replace('%2F', '/')
            # Case Youtube
            if 'youtube' in url_video_resolver:
                video_id = re.compile('www.youtube.com/embed/(.*?)[\?\"\&]'
                                      ).findall(url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_youtube(video_id, True)
                else:
                    return resolver.get_stream_youtube(video_id, False)
            # Case DailyMotion
            elif 'dailymotion' in url_video_resolver:
                video_id = re.compile(r'embed/video/(.*?)[\"\?]').findall(
                    url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_dailymotion(video_id, True)
                else:
                    return resolver.get_stream_dailymotion(video_id, False)
            # Case Facebook
            elif 'facebook' in url_video_resolver:
                video_id = re.compile('www.facebook.com/allocine/videos/(.*?)/'
                                      ).findall(url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_facebook(video_id, True)
                else:
                    return resolver.get_stream_facebook(video_id, False)
            # Case Vimeo
            elif 'vimeo' in url_video_resolver:
                video_id = re.compile('player.vimeo.com/video/(.*?)"').findall(
                    url_video_resolver)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_vimeo(video_id, True)
                else:
                    return resolver.get_stream_vimeo(video_id, False)
            # TO DO ? (return an error)
            else:
                return ''
        else:
            # Case Youtube
            if 'youtube' in url_video_embeded:
                video_id = re.compile('www.youtube.com/embed/(.*?)[\?\"\&]'
                                      ).findall(url_video_embeded)[0]
                if params.next == 'download_video':
                    return resolver.get_stream_youtube(video_id, True)
                else:
                    return resolver.get_stream_youtube(video_id, False)
            # TO DO ? (return an error)
            else:
                return ''
Ejemplo n.º 26
0
def get_video_url(params):
    """Get video URL and start video player"""

    desired_quality = common.PLUGIN.get_setting('quality')

    if params.next == 'play_r' or params.next == 'download_video':

        file_prgm = utils.get_webcontent(SHOW_INFO % (params.id_diffusion))
        json_parser = json.loads(file_prgm)

        url_selected = ''

        if desired_quality == "DIALOG":
            all_datas_videos_quality = []
            all_datas_videos_path = []

            for video in json_parser['videos']:
                if video['format'] == 'hls_v5_os' or \
                        video['format'] == 'm3u8-download':
                    if video['format'] == 'hls_v5_os':
                        all_datas_videos_quality.append("HD")
                    else:
                        all_datas_videos_quality.append("SD")
                    all_datas_videos_path.append((video['url'], video['drm']))

            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)

            if seleted_item == -1:
                return None

            url_selected = all_datas_videos_path[seleted_item][0]
            drm = all_datas_videos_path[seleted_item][1]

        elif desired_quality == "BEST":
            for video in json_parser['videos']:
                if video['format'] == 'hls_v5_os':
                    url_selected = video['url']
                    drm = video['drm']
        else:
            for video in json_parser['videos']:
                if video['format'] == 'm3u8-download':
                    url_selected = video['url']
                    drm = video['drm']

        if drm:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return None
        else:
            return url_selected

    elif params.next == 'play_l':

        file_prgm = utils.get_webcontent(SHOW_INFO % (params.id_diffusion))

        json_parser = json.loads(file_prgm)

        url_hls_v1 = ''
        url_hls_v5 = ''
        url_hls = ''

        for video in json_parser['videos']:
            if 'format' in video:
                if 'hls_v1_os' in video['format'] and \
                        video['geoblocage'] is not None:
                    url_hls_v1 = video['url']
                if 'hls_v5_os' in video['format'] and \
                        video['geoblocage'] is not None:
                    url_hls_v5 = video['url']
                if 'hls' in video['format']:
                    url_hls = video['url']

        final_url = ''

        # Case France 3 Région
        if url_hls_v1 == '' and url_hls_v5 == '':
            final_url = url_hls
        # Case Jarvis
        if common.sp.xbmc.__version__ == '2.24.0' \
                and url_hls_v1 != '':
            final_url = url_hls_v1
        # Case Krypton, Leia, ...
        if final_url == '' and url_hls_v5 != '':
            final_url = url_hls_v5
        elif final_url == '':
            final_url = url_hls_v1

        file_prgm2 = utils.get_webcontent(HDFAUTH_URL % (final_url))
        json_parser2 = json.loads(file_prgm2)

        return json_parser2['url']
Ejemplo n.º 27
0
def list_live(params):
    """Build live listing"""
    lives = []

    title = ''
    plot = ''
    duration = 0
    img = ''
    url_live = ''

    session_requests = requests.session()
    result = session_requests.get(URL_COMPTE_LOGIN)

    token_form_login = re.compile(
        r'name=\"login_form\[_token\]\" value=\"(.*?)\"').findall(
            result.text)[0]

    # Build PAYLOAD
    payload = {
        "login_form[email]":
        common.PLUGIN.get_setting(
            params.channel_id.rsplit('.', 1)[0] + '.login'),
        "login_form[password]":
        common.PLUGIN.get_setting(
            params.channel_id.rsplit('.', 1)[0] + '.password'),
        "login_form[_token]":
        token_form_login
    }

    # LOGIN
    result_2 = session_requests.post(URL_COMPTE_LOGIN,
                                     data=payload,
                                     headers=dict(referer=URL_COMPTE_LOGIN))
    if 'adresse e-mail ou le mot de passe est invalide.' in result_2.text.encode(
            'utf-8'):
        utils.send_notification(common.ADDON.get_localized_string(30113))
        return None

    # GET page with url_live with the session logged
    result_3 = session_requests.get(
        URL_LIVE_WITH_TOKEN % (params.channel_name),
        headers=dict(referer=URL_LIVE_WITH_TOKEN % (params.channel_name)))

    root_soup = bs(result_3.text, 'html.parser')
    live_soup = root_soup.find('div', class_="player")

    url_live_json = live_soup.get('data-options')
    url_live_json_jsonparser = json.loads(url_live_json)

    url_live = url_live_json_jsonparser["file"]

    title = '%s Live' % params.channel_name.upper()

    info = {'video': {'title': title, 'plot': plot, 'duration': duration}}

    lives.append({
        'label':
        title,
        'fanart':
        img,
        'thumb':
        img,
        'url':
        common.PLUGIN.get_url(
            action='channel_entry',
            next='play_l',
            url_live=url_live,
        ),
        'is_playable':
        True,
        'info':
        info
    })

    return common.PLUGIN.create_listing(
        lives,
        sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED,
                      common.sp.xbmcplugin.SORT_METHOD_LABEL),
        category=common.get_window_title())
Ejemplo n.º 28
0
def get_video_url(params):
    """Get video URL and start video player"""

    desired_quality = common.PLUGIN.get_setting('quality')

    if params.next == 'play_r' or params.next == 'download_video':
        if 'id_yatta' in params:
            result = utils.get_webcontent(URL_YATTA_VIDEO % params.id_yatta)
            result = json.loads(result)
            for media in result['content_has_medias']:
                if 'si_id' in media['media']:
                    params['id_diffusion'] = media['media']['si_id']
                    break

        json_parser = json.loads(
            utils.get_webcontent(SHOW_INFO % (params.id_diffusion)))

        subtitles = []
        if json_parser['subtitles']:
            subtitles_list = json_parser['subtitles']
            for subtitle in subtitles_list:
                if subtitle['format'] == 'vtt':
                    subtitles.append(subtitle['url'].encode('utf-8'))

        url_selected = ''

        if desired_quality == "DIALOG":
            all_datas_videos_quality = []
            all_datas_videos_path = []

            for video in json_parser['videos']:
                if video['format'] == 'hls_v5_os' or \
                        video['format'] == 'm3u8-download':
                    if video['format'] == 'hls_v5_os':
                        all_datas_videos_quality.append("HD")
                    else:
                        all_datas_videos_quality.append("SD")
                    all_datas_videos_path.append((video['url'], video['drm']))

            seleted_item = common.sp.xbmcgui.Dialog().select(
                common.GETTEXT('Choose video quality'),
                all_datas_videos_quality)

            if seleted_item == -1:
                return None

            url_selected = all_datas_videos_path[seleted_item][0]
            drm = all_datas_videos_path[seleted_item][1]

        elif desired_quality == "BEST":
            for video in json_parser['videos']:
                if video['format'] == 'hls_v5_os':
                    url_selected = video['url']
                    drm = video['drm']
        else:
            for video in json_parser['videos']:
                if video['format'] == 'm3u8-download':
                    url_selected = video['url']
                    drm = video['drm']

        if drm:
            utils.send_notification(common.ADDON.get_localized_string(30702))
            return None
        else:
            return url_selected

    elif params.next == 'play_l':

        json_parser = json.loads(utils.get_webcontent(URL_LIVE_JSON))
        for live in json_parser["result"]:
            if live["channel"] == params.channel_name:
                live_datas = live["collection"][0]["content_has_medias"]
                liveId = ''
                for live_data in live_datas:
                    if "si_direct_id" in live_data["media"]:
                        liveId = live_data["media"]["si_direct_id"]
                json_parser_liveId = json.loads(
                    utils.get_webcontent(SHOW_INFO % liveId))
                url_hls_v1 = ''
                url_hls_v5 = ''
                url_hls = ''

                for video in json_parser_liveId['videos']:
                    if 'format' in video:
                        if 'hls_v1_os' in video['format'] and \
                                video['geoblocage'] is not None:
                            url_hls_v1 = video['url']
                        if 'hls_v5_os' in video['format'] and \
                                video['geoblocage'] is not None:
                            url_hls_v5 = video['url']
                        if 'hls' in video['format']:
                            url_hls = video['url']

                final_url = ''

                # Case France 3 Région
                if url_hls_v1 == '' and url_hls_v5 == '':
                    final_url = url_hls
                # Case Jarvis
                if common.sp.xbmc.__version__ == '2.24.0' \
                        and url_hls_v1 != '':
                    final_url = url_hls_v1
                # Case Krypton, Leia, ...
                if final_url == '' and url_hls_v5 != '':
                    final_url = url_hls_v5
                elif final_url == '':
                    final_url = url_hls_v1

                json_parser2 = json.loads(
                    utils.get_webcontent(HDFAUTH_URL % (final_url)))

                return json_parser2['url']
Ejemplo n.º 29
0
def get_video_url(params):
    """Get video URL and start video player"""
    if params.next == 'play_l':
        token_json = utils.get_webcontent(URL_TOKEN_LIVE, request_type='post')
        token_jsonparser = json.loads(token_json)
        url_stream_json = utils.get_webcontent(
            URL_LIVE %
            (params.channel_name, token_jsonparser["vrtPlayerToken"]))
        url_stream_jsonparser = json.loads(url_stream_json)
        url_live = ''
        if "code" in url_stream_jsonparser:
            if url_stream_jsonparser["code"] == "INVALID_LOCATION":
                utils.send_notification(
                    common.ADDON.get_localized_string(30713))
            return None
        for url_stream_datas in url_stream_jsonparser["targetUrls"]:
            if url_stream_datas["type"] == "hls_aes":
                url_live = url_stream_datas["url"]
        return url_live
    elif params.next == 'play_r' or params.next == 'download_video':

        session_requests = requests.session()

        module_name = eval(params.module_path)[-1]

        # Build PAYLOAD
        payload = {
            'loginID': common.PLUGIN.get_setting(module_name + '.login'),
            'password': common.PLUGIN.get_setting(module_name + '.password'),
            'targetEnv': 'jssdk',
            'APIKey': get_api_key(),
            'includeSSOToken': 'true',
            'authMode': 'cookie'
        }
        result = session_requests.post(URL_LOGIN, data=payload)
        result_jsonpaser = json.loads(result.text)
        if result_jsonpaser['statusCode'] != 200:
            utils.send_notification(params.channel_name + ' : ' +
                                    common.ADDON.get_localized_string(30711))
            return None

        headers = {
            'Content-Type': 'application/json',
            'Referer': URL_ROOT + '/vrtnu/'
        }
        data = '{"uid": "%s", ' \
            '"uidsig": "%s", ' \
            '"ts": "%s", ' \
            '"email": "%s"}' % (
            result_jsonpaser['UID'],
            result_jsonpaser['UIDSignature'],
            result_jsonpaser['signatureTimestamp'],
            common.PLUGIN.get_setting(
                module_name + '.login'))
        result_2 = session_requests.post(URL_TOKEN, data=data, headers=headers)

        build_url = params.video_url[:-1] + '.mssecurevideo.json'
        result_3 = session_requests.get(build_url)
        video_id_json = json.loads(result_3.text)
        video_id = ''
        for key in video_id_json.iteritems():
            video_id = video_id_json[key[0]]['videoid']

        result_4 = session_requests.get(URL_STREAM_JSON % video_id)
        streams_json = json.loads(result_4.text)
        url = ''
        for stream in streams_json['targetUrls']:
            if 'HLS' in stream['type']:
                url = stream['url']
        return url