Ejemplo n.º 1
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    #if not force ==1 and check_key(profile_settings, 'last_login_time') and profile_settings['last_login_time'] > int(time.time() - 3600) and profile_settings['last_login_success'] == 1:
    #    return True
    #elif force == 1 and (not check_key(profile_settings, 'last_login_time') or not profile_settings['last_login_success'] == 1):
    #    return False

    devices_url = '{api_url}/USER/DEVICES'.format(api_url=CONST_DEFAULT_API)

    download = api_download(url=devices_url, type='get', headers=None, data=None, json_data=False, return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(data, 'resultCode') or not data['resultCode'] == 'OK':
        login_result = api_login()

        if not login_result['result']:
            return False

    try:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        profile_settings['last_login_time'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 2
0
def api_get_session(force=0):
    force = int(force)

    profile_url = '{base_url}/api/v3/profiles'.format(base_url=CONST_BASE_URL)

    headers = {
        'videoland-platform': 'videoland',
        "Referer": CONST_BASE_URL + "/profielkeuze",
    }

    download = api_download(url=profile_url,
                            type='get',
                            headers=headers,
                            data=None,
                            json_data=False,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(
            data[0], 'id') or not check_key(data[0], 'gigya_id'):
        login_result = api_login()

        if not login_result['result']:
            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    return True
Ejemplo n.º 3
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    #if not force ==1 and check_key(profile_settings, 'last_login_time') and profile_settings['last_login_time'] > int(time.time() - 3600) and profile_settings['last_login_success'] == 1:
    #    return True
    #elif force == 1 and not profile_settings['last_login_success'] == 1:
    #    return False

    heartbeat_url = '{base_url}/VSP/V3/OnLineHeartbeat?from=inMSAAccess'.format(base_url=CONST_BASE_URL)

    headers = {'Content-Type': 'application/json', 'X_CSRFToken': profile_settings['csrf_token']}

    session_post_data = {}

    download = api_download(url=heartbeat_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(data, 'result') or not check_key(data['result'], 'retCode') or not data['result']['retCode'] == '000000000':
        login_result = api_login()

        if not login_result['result']:
            return False

    try:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        profile_settings['last_login_time'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 4
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    #if not force ==1 and check_key(profile_settings, 'last_login_time') and profile_settings['last_login_time'] > int(time.time() - 3600) and profile_settings['last_login_success'] == 1:
    #    return True
    #elif force == 1 and not profile_settings['last_login_success'] == 1:
    #    return False
    
    headers = {'Authorization': 'Bearer ' + profile_settings['session_token']}

    capi_url = '{api_url}/settings'.format(api_url=CONST_DEFAULT_API)

    download = api_download(url=capi_url, type='get', headers=headers, data=None, json_data=False, return_json=False, allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 200:
        login_result = api_login()

        if not login_result['result']:
            return False

    try:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        profile_settings['last_login_time'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 5
0
def alternative(num, addon, addons, **kwargs):
    num = int(num)
    profile_settings = load_profile(profile_id=1)
    profile_settings['addon' + str(num)] = addon
    save_profile(profile_id=1, profile=profile_settings)

    folder = plugin.Folder(title=_.SELECT_SECONDARY)

    addons = json.loads(addons)
    addons2 = []

    desc = _.SELECT_SECONDARY_DESC

    for entry in addons:
        if not entry['addonid'] == addon:
            addons2.append(entry)

    for entry in addons2:
        folder.add_item(label=_(entry['label'], _bold=True),
                        info={'plot': desc},
                        path=plugin.url_for(func_or_url=alternative,
                                            num=num + 1,
                                            addon=entry['addonid'],
                                            addons=json.dumps(addons2)))

    folder.add_item(label=_.DONE,
                    info={'plot': desc},
                    path=plugin.url_for(func_or_url=radio_select, num=num + 1))

    return folder
Ejemplo n.º 6
0
def api_get_watchlist_id():
    if not api_get_session():
        return None

    profile_settings = load_profile(profile_id=1)

    watchlist_url = '{watchlist_url}/profile/{profile_id}?language=nl&maxResults=1&order=DESC&sharedProfile=true&sort=added'.format(
        watchlist_url=CONST_API_URLS[int(
            profile_settings['v3'])]['watchlist_url'],
        profile_id=profile_settings['ziggo_profile_id'])

    download = api_download(url=watchlist_url,
                            type='get',
                            headers=api_get_headers(),
                            data=None,
                            json_data=False,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(
            data, 'watchlistId'):
        return False

    try:
        profile_settings['watchlist_id'] = data['watchlistId']
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 7
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    devices_url = CONST_API_URLS['devices_url']

    download = api_download(url=devices_url,
                            type='get',
                            headers=api_get_headers(),
                            data=None,
                            json_data=False,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(
            data, 'isAccountEnabled'):
        login_result = api_login()

        if not login_result['result']:
            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    return True
Ejemplo n.º 8
0
def login(ask=1, **kwargs):
    ask = int(ask)

    creds = get_credentials()

    if len(creds['username']) < 1 or len(creds['password']) < 1 or ask == 1:
        user_info = plugin_ask_for_creds(creds)

        if user_info['result']:
            set_credentials(username=user_info['username'], password=user_info['password'])

    login_result = api_login()

    if not login_result['result']:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 0
        profile_settings['pswd'] = ''
        save_profile(profile_id=1, profile=profile_settings)

        plugin_login_error(login_result)
    else:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        save_profile(profile_id=1, profile=profile_settings)

        gui.ok(message=_.LOGIN_SUCCESS)

        api_get_channels()
        plugin_post_login()

    gui.refresh()
Ejemplo n.º 9
0
def radio_select(num, **kwargs):
    num = int(num)

    profile_settings = load_profile(profile_id=1)

    for x in range(num, 6):
        profile_settings['addon' + str(x)] = ''

    save_profile(profile_id=1, profile=profile_settings)

    folder = plugin.Folder(title=_.ADD_RADIO)

    desc = _.ADD_RADIO_DESC

    folder.add_item(label=_.YES,
                    info={'plot': desc},
                    path=plugin.url_for(func_or_url=channel_picker_menu,
                                        type_tv_radio='live',
                                        save_all=1,
                                        radio=1))
    folder.add_item(label=_.NO,
                    info={'plot': desc},
                    path=plugin.url_for(func_or_url=channel_picker_menu,
                                        type_tv_radio='live',
                                        save_all=1,
                                        radio=0))

    return folder
Ejemplo n.º 10
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    #if not force ==1 and check_key(profile_settings, 'last_login_time') and profile_settings['last_login_time'] > int(time.time() - 3600) and profile_settings['last_login_success'] == 1:
    #    return True
    #elif force == 1 and not profile_settings['last_login_success'] == 1:
    #    return False

    if not check_key(profile_settings, 'access_token_age') or not check_key(
            profile_settings, 'access_token') or int(
                profile_settings['access_token_age']) < int(time.time() -
                                                            3540):
        login_result = api_login()

        if not login_result['result']:
            return False

    try:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        profile_settings['last_login_time'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 11
0
def check_first():
    profile_settings = load_profile(profile_id=1)

    if not check_key(profile_settings, 'setup_complete'):
        if gui.yes_no(message=_.DISABLE_EROTICA) == False:
            settings.setBool(key='disableErotica', value=False)
        else:
            settings.setBool(key='disableErotica', value=True)

        if gui.yes_no(message=_.MINIMAL_CHANNELS) == False:
            settings.setBool(key='minimalChannels', value=False)
        else:
            settings.setBool(key='minimalChannels', value=True)

        if gui.yes_no(message=_.DISABLE_REGIONAL) == False:
            settings.setBool(key='disableRegionalChannels', value=False)
        else:
            settings.setBool(key='disableRegionalChannels', value=True)

        if PROVIDER_NAME == 'kpn':
            if gui.yes_no(message=_.HOME_CONNECTION) == True:
                settings.setBool(key='homeConnection', value=True)
            else:
                settings.setBool(key='homeConnection', value=False)

        profile_settings['setup_complete'] = 1
        save_profile(profile_id=1, profile=profile_settings)
Ejemplo n.º 12
0
def api_get_session_token():
    creds = get_credentials()
    username = creds['username']

    profile_settings = load_profile(profile_id=1)

    headers = {
        'User-Agent': DEFAULT_USER_AGENT,
        'X-Client-Id': CONST_DEFAULT_CLIENTID + "||" + DEFAULT_USER_AGENT,
    }

    download = api_download(url='{session_url}?token=true'.format(
        session_url=CONST_URLS['session_url']),
                            type='post',
                            headers=headers,
                            data={
                                "username": username,
                                "refreshToken":
                                profile_settings['refresh_token']
                            },
                            json_data=True,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not data or not check_key(data, 'oespToken'):
        if not code:
            code = {}

        if not data:
            data = {}

        return {'code': code, 'data': data, 'result': False}

    betelenet_profile_id = ''
    household_id = ''

    try:
        betelenet_profile_id = data['customer']['sharedProfileId']
    except:
        pass

    try:
        household_id = data['customer']['householdId']
    except:
        pass

    profile_settings['access_token'] = data['oespToken']
    profile_settings['refresh_token'] = data['refreshToken']
    profile_settings['refresh_token_expiry'] = data['refreshTokenExpiry']
    profile_settings['betelenet_profile_id'] = betelenet_profile_id
    profile_settings['household_id'] = household_id
    save_profile(profile_id=1, profile=profile_settings)

    if len(str(profile_settings['watchlist_id'])) == 0:
        api_get_watchlist_id()

    return {'code': code, 'data': data, 'result': True}
Ejemplo n.º 13
0
def logout(**kwargs):
    if not gui.yes_no(message=_.LOGOUT_YES_NO):
        return

    profile_settings = load_profile(profile_id=1)
    profile_settings['pswd'] = ''
    profile_settings['username'] = ''
    save_profile(profile_id=1, profile=profile_settings)

    gui.refresh()
Ejemplo n.º 14
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    #if not force ==1 and check_key(profile_settings, 'last_login_time') and profile_settings['last_login_time'] > int(time.time() - 3600) and profile_settings['last_login_success'] == 1:
    #    return True
    #elif force == 1 and not profile_settings['last_login_success'] == 1:
    #    return False

    if not check_key(profile_settings, 'resource_verifier'):
        login_result = api_login()

        if not login_result['result']:
            return False
    else:
        token_url_base = '{base_url}/v6/favorites/items'.format(
            base_url=CONST_API_URL)

        token_parameter = 'oauth_consumer_key=key&oauth_signature_method=HMAC-SHA1&oauth_verifier=' + unicode(
            profile_settings['resource_verifier']
        ) + '&oauth_token={token}&oauth_version=1.0&oauth_timestamp={timestamp}&oauth_nonce={nonce}&count=1&expand=false&expandlist=false&maxResults=1&offset=0'

        url_encoded = api_oauth_encode(type="GET",
                                       base_url=token_url_base,
                                       parameters=token_parameter)

        download = api_download(url=url_encoded,
                                type='get',
                                headers=None,
                                data=None,
                                json_data=False,
                                return_json=False)
        data = download['data']
        code = download['code']

        if not code or not code == 200:
            login_result = api_login()

            if not login_result['result']:
                return False

    try:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        profile_settings['last_login_time'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 15
0
def api_get_session(force=0, return_data=False):
    force = int(force)

    profile_url = '{base_url}/api/v3/profiles'.format(
        base_url=CONST_URLS['base'])

    headers = api_get_headers(personal=False)
    headers["Referer"] = "{base_url}/profielkeuze".format(
        base_url=CONST_URLS['base'])

    download = api_download(url=profile_url,
                            type='get',
                            headers=headers,
                            data=None,
                            json_data=False,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(data[0], 'id'):
        login_result = api_login()

        if not login_result['result']:
            if return_data == True:
                return {
                    'result': False,
                    'data': login_result['data'],
                    'code': login_result['code']
                }

            return False
        else:
            download = api_download(url=profile_url,
                                    type='get',
                                    headers=headers,
                                    data=None,
                                    json_data=False,
                                    return_json=True)
            data = download['data']
            code = download['code']

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    if return_data == True:
        return {'result': True, 'data': data, 'code': code}

    return True
Ejemplo n.º 16
0
def api_get_session(force=0, return_data=False):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    heartbeat_url = '{base_url}/VSP/V3/OnLineHeartbeat?from=inMSAAccess'.format(
        base_url=CONST_URLS['base'])

    headers = {
        'Content-Type': 'application/json',
        'X_CSRFToken': profile_settings['csrf_token']
    }

    session_post_data = {}

    download = api_download(url=heartbeat_url,
                            type='post',
                            headers=headers,
                            data=session_post_data,
                            json_data=True,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(
            data, 'result') or not check_key(
                data['result'],
                'retCode') or not data['result']['retCode'] == '000000000':
        login_result = api_login()

        if not login_result['result']:
            if return_data == True:
                return {
                    'result': False,
                    'data': login_result['data'],
                    'code': login_result['code']
                }

            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    if return_data == True:
        return {'result': True, 'data': data, 'code': code}

    return True
Ejemplo n.º 17
0
def search(query=None, **kwargs):
    items = []

    if not query:
        query = gui.input(message=_.SEARCH, default='').strip()

        if not query:
            return

        profile_settings = load_profile(profile_id=1)

        for x in reversed(range(2, 10)):
            if check_key(profile_settings, 'search' + unicode(x - 1)):
                profile_settings['search' + unicode(x)] = profile_settings['search' + unicode(x - 1)]
            else:
                profile_settings['search' + unicode(x)] = ''

        profile_settings['search1'] = query

        if CONST_ONLINE_SEARCH:
            for x in reversed(range(2, 10)):
                if check_key(profile_settings, 'search_type' + unicode(x - 1)):
                    profile_settings['search_type' + unicode(x)] = profile_settings['search_type' + unicode(x - 1)]
                else:
                    profile_settings['search_type' + unicode(x)] = 0

            profile_settings['search_type1'] = 0

        save_profile(profile_id=1, profile=profile_settings)
    else:
        query = unicode(query)

    folder = plugin.Folder(title=_(_.SEARCH_FOR, query=query))

    processed = process_replaytv_search(search=query)
    items += processed['items']

    if settings.getBool('showMoviesSeries'):
        for vod_entry in CONST_VOD_CAPABILITY:
            processed = process_vod_content(data=vod_entry['file'], start=vod_entry['start'], search=query, type=vod_entry['label'], online=vod_entry['online'])
            items += processed['items']

    items[:] = sorted(items, key=_sort_replay_items, reverse=True)
    items = items[:25]

    folder.add_items(items)

    return folder
Ejemplo n.º 18
0
def api_login():
    creds = get_credentials()
    username = creds['username']
    password = creds['password']

    try:
        os.remove(ADDON_PROFILE + 'stream_cookies')
    except:
        pass

    profile_settings = load_profile(profile_id=1)

    profile_settings['access_token'] = ''
    profile_settings['ziggo_profile_id'] = ''
    profile_settings['household_id'] = ''
    profile_settings['watchlist_id'] = ''
    save_profile(profile_id=1, profile=profile_settings)

    HEADERS = {
        'User-Agent':  DEFAULT_USER_AGENT,
        'X-Client-Id': CONST_DEFAULT_CLIENTID + "||" + DEFAULT_USER_AGENT,
    }

    download = api_download(url=CONST_API_URLS[0]['session_url'], type='post', headers=HEADERS, data={"username": username, "password": password}, json_data=True, return_json=True)
    data = download['data']
    code = download['code']

    if not code or not data or not check_key(data, 'oespToken'):
        if not code:
            code = {}

        if not data:
            data = {}

        return { 'code': code, 'data': data, 'result': False }

    ziggo_profile_id = data['customer']['sharedProfileId']
    household_id = data['customer']['householdId']

    profile_settings['access_token'] = data['oespToken']
    profile_settings['ziggo_profile_id'] = ziggo_profile_id
    profile_settings['household_id'] = household_id
    save_profile(profile_id=1, profile=profile_settings)

    if len(str(profile_settings['watchlist_id'])) == 0:
        api_get_watchlist_id()

    return { 'code': code, 'data': data, 'result': True }
Ejemplo n.º 19
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    if not check_key(profile_settings, 'access_token_age') or not check_key(profile_settings, 'access_token') or int(profile_settings['access_token_age']) < int(time.time() - 3540):
        login_result = api_login()

        if not login_result['result']:
            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    return True
Ejemplo n.º 20
0
def api_get_session(force=0, return_data=False):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    devices_url = '{devices_url}{household_id}/devices'.format(
        devices_url=CONST_URLS['devices_url'],
        household_id=profile_settings['household_id'])

    download = api_download(url=devices_url,
                            type='get',
                            headers=api_get_headers(),
                            data=None,
                            json_data=False,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200:  # or not data or not check_key(data, 'isAccountEnabled'):
        if int(time.time() * 1000) > int(
                profile_settings['refresh_token_expiry']):
            login_result = api_login()
        else:
            login_result = api_get_session_token()

        if not login_result['result']:
            if return_data == True:
                return {
                    'result': False,
                    'data': login_result['data'],
                    'code': login_result['code']
                }

            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    if return_data == True:
        return {'result': True, 'data': data, 'code': code}

    return True
Ejemplo n.º 21
0
def api_get_session(force=0, return_data=False):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    headers = {
        'Authorization':
        'Bearer {token}'.format(token=profile_settings['session_token'])
    }

    capi_url = '{api_url}/settings'.format(api_url=CONST_URLS['api'])

    download = api_download(url=capi_url,
                            type='get',
                            headers=headers,
                            data=None,
                            json_data=False,
                            return_json=False,
                            allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 200:
        login_result = api_login()

        if not login_result['result']:
            if return_data == True:
                return {
                    'result': False,
                    'data': login_result['data'],
                    'code': login_result['code']
                }

            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    if return_data == True:
        return {'result': True, 'data': data, 'code': code}

    return True
Ejemplo n.º 22
0
def api_login():
    creds = get_credentials()
    username = creds['username']
    password = creds['password']

    try:
        os.remove(os.path.join(ADDON_PROFILE, 'stream_cookies'))
    except:
        pass

    session_url = '{api_url}/subscriber/authenticate/by-password'.format(api_url=CONST_URLS['api'])

    session_post_data = {
        "DeviceType": 16,
        "DistributionChannel": '871435e3-2d31-4d4f-9004-96c6a8011656',
        "Language": 'en-GB',
        "Login": username,
        "Password": password
    }

    headers = {
        "Content-Type": "application/json",
        "apikey": "fCUCjWrKPu9ylJwRAv8BpGLEgiAuThx7",
        "CD-DeviceType": '16',
        "CD-DistributionChannel": '871435e3-2d31-4d4f-9004-96c6a8011656',
        'User-Agent': 'RaceControl'
    }

    download = api_download(url=session_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(data, 'SessionId') or not data['data']['subscriptionStatus'] == 'active':
        return { 'code': code, 'data': data, 'result': False }

    profile_settings = load_profile(profile_id=1)
    profile_settings['subscriptionToken'] = data["data"]["subscriptionToken"]
    save_profile(profile_id=1, profile=profile_settings)

    return { 'code': code, 'data': data, 'result': True }
Ejemplo n.º 23
0
def online_search(query=None, **kwargs):
    items = []

    if not query:
        query = gui.input(message=_.SEARCH, default='').strip()

        if not query:
            return

        profile_settings = load_profile(profile_id=1)

        for x in reversed(range(2, 10)):
            if check_key(profile_settings, 'search' + unicode(x - 1)):
                profile_settings['search' + unicode(x)] = profile_settings['search' + unicode(x - 1)]
            else:
                profile_settings['search' + unicode(x)] = ''

            if check_key(profile_settings, 'search_type' + unicode(x - 1)):
                profile_settings['search_type' + unicode(x)] = profile_settings['search_type' + unicode(x - 1)]
            else:
                profile_settings['search_type' + unicode(x)] = 0

        profile_settings['search1'] = query
        profile_settings['search_type1'] = 1

        save_profile(profile_id=1, profile=profile_settings)
    else:
        query = unicode(query)

    folder = plugin.Folder(title=_(_.SEARCH_FOR, query=query))

    processed = process_vod_content(data=None, start=0, search=query, type='Online', online=1)
    items += processed['items']

    items[:] = sorted(items, key=_sort_replay_items, reverse=True)
    items = items[:25]

    folder.add_items(items)

    return folder
Ejemplo n.º 24
0
def api_get_play_token(locator=None, path=None, force=0):
    if not api_get_session():
        return None

    force = int(force)

    profile_settings = load_profile(profile_id=1)

    if not check_key(profile_settings, 'drm_token_age') or not check_key(
            profile_settings, 'tokenrun') or not check_key(
                profile_settings,
                'tokenruntime') or profile_settings['drm_token_age'] < int(
                    time.time() - 50) and (profile_settings['tokenrun'] == 0
                                           or profile_settings['tokenruntime']
                                           < int(time.time() - 30)):
        force = 1

    if not check_key(profile_settings, 'drm_token_age') or not check_key(
            profile_settings, 'drm_locator') or locator != profile_settings[
                'drm_locator'] or profile_settings['drm_token_age'] < int(
                    time.time() - 90) or force == 1:
        profile_settings['tokenrun'] = 1
        profile_settings['tokenruntime'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)

        if 'sdash' in path:
            jsondata = {
                "contentLocator": locator,
                "drmScheme": "sdash:BR-AVC-DASH"
            }
        else:
            jsondata = {"contentLocator": locator}

        download = api_download(url=CONST_API_URLS['token_url'],
                                type='post',
                                headers=api_get_headers(),
                                data=jsondata,
                                json_data=True,
                                return_json=True)
        data = download['data']
        code = download['code']

        if not code or not code == 200 or not data or not check_key(
                data, 'token'):
            profile_settings['tokenrun'] = 0
            save_profile(profile_id=1, profile=profile_settings)

            return None

        profile_settings['tokenrun'] = 0
        profile_settings['drm_token'] = data['token']
        write_file(file='widevine_token', data=data['token'], isJSON=False)
        profile_settings['drm_token_age'] = int(time.time())
        profile_settings['drm_locator'] = locator
        save_profile(profile_id=1, profile=profile_settings)

        return data['token']
    else:
        return profile_settings['drm_token']
Ejemplo n.º 25
0
def api_get_session(force=0, return_data=False):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    devices_url = '{api_url}/USER/DEVICES'.format(api_url=CONST_URLS['api'])

    download = api_download(url=devices_url,
                            type='get',
                            headers=None,
                            data=None,
                            json_data=False,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(
            data, 'resultCode') or not data['resultCode'] == 'OK':
        login_result = api_login()

        if not login_result['result']:
            if return_data == True:
                return {
                    'result': False,
                    'data': login_result['data'],
                    'code': login_result['code']
                }

            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)

    if return_data == True:
        return {'result': True, 'data': data, 'code': code}

    return True
Ejemplo n.º 26
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    #if not force ==1 and check_key(profile_settings, 'last_login_time') and profile_settings['last_login_time'] > int(time.time() - 3600) and profile_settings['last_login_success'] == 1:
    #    return True
    #elif force == 1 and not profile_settings['last_login_success'] == 1:
    #    return False

    capi_url = '{base_url}/m7be2iphone/capi.aspx?z=pg&a=cds&lng=nl'.format(
        base_url=CONST_BASE_URL)

    download = api_download(url=capi_url,
                            type='get',
                            headers=None,
                            data=None,
                            json_data=False,
                            return_json=False,
                            allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 200:
        login_result = api_login()

        if not login_result['result']:
            return False

    try:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        profile_settings['last_login_time'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 27
0
def api_get_session(force=0):
    force = int(force)
    profile_settings = load_profile(profile_id=1)

    #if not force ==1 and check_key(profile_settings, 'last_login_time') and profile_settings['last_login_time'] > int(time.time() - 3600) and profile_settings['last_login_success'] == 1:
    #    return True
    #elif force == 1 and not profile_settings['last_login_success'] == 1:
    #    return False

    devices_url = CONST_API_URLS[int(profile_settings['v3'])]['devices_url']

    download = api_download(url=devices_url,
                            type='get',
                            headers=api_get_headers(),
                            data=None,
                            json_data=False,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(
            data, 'isAccountEnabled'):
        login_result = api_login()

        if not login_result['result']:
            return False

    try:
        profile_settings = load_profile(profile_id=1)
        profile_settings['last_login_success'] = 1
        profile_settings['last_login_time'] = int(time.time())
        save_profile(profile_id=1, profile=profile_settings)
    except:
        pass

    return True
Ejemplo n.º 28
0
def api_get_session(force=0, return_data=False):
    force = int(force)
    profile_settings = load_profile(profile_id=1)
    subscriptionToken = None

    try:
        saved_token = profile_settings['subscriptionToken']

        if saved_token is not None:
            cached_token_expiration_time = datetime.fromtimestamp(pyjwt.decode(saved_token, verify=False)['exp'])

            token_validity_time_remaining = cached_token_expiration_time - datetime.now()

            if token_validity_time_remaining.total_seconds() > 60 * 60 * 24:
                subscriptionToken = saved_token
    except:
        pass

    if subscriptionToken is None:
        login_result = api_login()

        if not login_result['result']:
            if return_data == True:
                return {'result': False, 'data': login_result['data'], 'code': login_result['code']}
                
            return False

    profile_settings = load_profile(profile_id=1)
    profile_settings['last_login_success'] = 1
    profile_settings['last_login_time'] = int(time.time())
    save_profile(profile_id=1, profile=profile_settings)
    
    if return_data == True:
        return {'result': True, 'data': login_result['data'], 'code': login_result['code']}

    return True
Ejemplo n.º 29
0
def api_login():
    creds = get_credentials()
    username = creds['username']
    password = creds['password']

    try:
        os.remove(ADDON_PROFILE + 'stream_cookies')
    except:
        pass

    profile_settings = load_profile(profile_id=1)

    profile_settings['session_token'] = ''

    if not profile_settings or not check_key(profile_settings, 'devicekey') or len(profile_settings['devicekey']) == 0:
        devicekey = 'w{uuid}'.format(uuid=uuid.uuid4())
        profile_settings['devicekey'] = devicekey

    save_profile(profile_id=1, profile=profile_settings)

    oauth = ''
    auth_url = '{login_url}/authenticate?redirect_uri=https%3A%2F%2Flivetv.canaldigitaal.nl%2Fauth.aspx&state={state}&response_type=code&scope=TVE&client_id=StreamGroup'.format(login_url=CONST_LOGIN_URL, state=int(time.time()))

    download = api_download(url=auth_url, type='get', headers=None, data=None, json_data=False, return_json=False, allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data:
        return { 'code': code, 'data': data, 'result': False }

    headers = CONST_LOGIN_HEADERS
    headers.update({'Referer': auth_url})

    session_post_data = {
        "Password": password,
        "Username": username,
    }

    download = api_download(url=CONST_LOGIN_URL, type='post', headers=headers, data=session_post_data, json_data=False, return_json=False, allow_redirects=False)
    data = download['data']
    code = download['code']
    headers = download['headers']

    if not code or not code == 302:
        return { 'code': code, 'data': data, 'result': False }

    params = parse_qs(urlparse(headers['Location']).query)

    if check_key(params, 'code'):
        oauth = params['code'][0]

    if len(oauth) == 0:
        return { 'code': code, 'data': data, 'result': False }

    challenge_url = "{base_url}/m7be2iphone/challenge.aspx".format(base_url=CONST_BASE_URL)

    session_post_data = {
        "autotype": "nl",
        "app": "cds",
        "prettyname": DEFAULT_BROWSER_NAME,
        "model": "web",
        "serial": profile_settings['devicekey'],
        "oauthcode": oauth
    }

    headers = {'Content-Type': 'application/json;charset=UTF-8'}

    download = api_download(url=challenge_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True, allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(data, 'id') or not check_key(data, 'secret'):
        return { 'code': code, 'data': data, 'result': False }

    login_url = "{base_url}/m7be2iphone/login.aspx".format(base_url=CONST_BASE_URL)

    headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}

    secret = '{id}\t{secr}'.format(id=data['id'], secr=data['secret'])

    session_post_data = {
        "secret": secret,
        "uid": profile_settings['devicekey'],
        "app": "cds",
    }

    download = api_download(url=login_url, type='post', headers=headers, data=session_post_data, json_data=False, return_json=False, allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 302:
        return { 'code': code, 'data': data, 'result': False }

    ssotoken_url = "{base_url}/m7be2iphone/capi.aspx?z=ssotoken".format(base_url=CONST_BASE_URL)

    download = api_download(url=ssotoken_url, type='get', headers=None, data=None, json_data=False, return_json=True, allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(data, 'ssotoken'):
        return { 'code': code, 'data': data, 'result': False }

    session_url = "{api_url}/session".format(api_url=CONST_DEFAULT_API)

    session_post_data = {
        "sapiToken": data['ssotoken'],
        "deviceType": "PC",
        "deviceModel": DEFAULT_BROWSER_NAME,
        "osVersion": '{name} {version}'.format(name=DEFAULT_OS_NAME, version=DEFAULT_OS_VERSION),
        "deviceSerial": profile_settings['devicekey'],
        "appVersion": DEFAULT_BROWSER_VERSION,
        "brand": "cds"
    }

    headers = {'Content-Type': 'application/json;charset=UTF-8'}

    download = api_download(url=session_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True, allow_redirects=False)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(data, 'token'):
        return { 'code': code, 'data': data, 'result': False }

    profile_settings['session_token'] = data['token']
    save_profile(profile_id=1, profile=profile_settings)

    return { 'code': code, 'data': data, 'result': True }
Ejemplo n.º 30
0
def api_login():
    creds = get_credentials()
    username = creds['username']
    password = creds['password']

    try:
        os.remove(ADDON_PROFILE + 'stream_cookies')
    except:
        pass

    profile_settings = load_profile(profile_id=1)

    if not profile_settings or not check_key(
            profile_settings, 'devicekey') or len(
                profile_settings['devicekey']) == 0:
        devicekey = ''.join(
            random.choice(string.ascii_uppercase + string.ascii_lowercase +
                          string.digits) for _ in range(64))
        profile_settings['devicekey'] = devicekey
        save_profile(profile_id=1, profile=profile_settings)

    session_url = '{api_url}/USER/SESSIONS/'.format(api_url=CONST_DEFAULT_API)

    email_or_pin = settings.getBool(key='email_instead_of_customer')

    if email_or_pin:
        session_post_data = {
            "credentialsExtAuth": {
                'credentials': {
                    'loginType': 'UsernamePassword',
                    'username': username,
                    'password': password,
                    'appId': 'KPN',
                },
                'remember': 'Y',
                'deviceInfo': {
                    'deviceId': profile_settings['devicekey'],
                    'deviceIdType': 'DEVICEID',
                    'deviceType': 'PCTV',
                    'deviceVendor': DEFAULT_BROWSER_NAME,
                    'deviceModel': DEFAULT_BROWSER_VERSION,
                    'deviceFirmVersion': DEFAULT_OS_NAME,
                    'appVersion': DEFAULT_OS_VERSION
                }
            },
        }
    else:
        session_post_data = {
            "credentialsStdAuth": {
                'username': username,
                'password': password,
                'remember': 'Y',
                'deviceRegistrationData': {
                    'deviceId': profile_settings['devicekey'],
                    'accountDeviceIdType': 'DEVICEID',
                    'deviceType': 'PCTV',
                    'vendor': DEFAULT_BROWSER_NAME,
                    'model': DEFAULT_BROWSER_VERSION,
                    'deviceFirmVersion': DEFAULT_OS_NAME,
                    'appVersion': DEFAULT_OS_VERSION
                }
            },
        }

    download = api_download(url=session_url,
                            type='post',
                            headers=None,
                            data=session_post_data,
                            json_data=True,
                            return_json=True)
    data = download['data']
    code = download['code']

    if not code or not code == 200 or not data or not check_key(
            data, 'resultCode') or not data['resultCode'] == 'OK':
        return {'code': code, 'data': data, 'result': False}

    return {'code': code, 'data': data, 'result': True}