def login(**kwargs): if len(settings.get(key='_devicekey')) == 0: settings.set(key='_devicekey', value=''.join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(64))) creds = get_credentials() username = gui.numeric(message=_.ASK_USERNAME, default=creds['username']).strip() if not len(username) > 0: gui.ok(message=_.EMPTY_USER, heading=_.LOGIN_ERROR_TITLE) return password = gui.numeric(message=_.ASK_PASSWORD).strip() if not len(password) > 0: gui.ok(message=_.EMPTY_PASS, heading=_.LOGIN_ERROR_TITLE) return api.login(username=username, password=password, channels=True) plugin.logged_in = api.logged_in gui.refresh()
def new_session(self, force=False, channels=False): cookies = settings.get(key='_cookies') if len(cookies) > 0 and force == False: self._session = Session(cookies_key='_cookies') self.logged_in = True return self.logged_in = False creds = get_credentials() username = creds['username'] password = creds['password'] if not len(username) > 0: return if not len(password) > 0: password = gui.numeric(message=_.ASK_PASSWORD).strip() if not len(password) > 0: gui.ok(message=_.EMPTY_PASS, heading=_.LOGIN_ERROR_TITLE) return self.login(username=username, password=password, channels=channels)
def new_session(self, force=False, channels=False): access_token = settings.get(key='_access_token') creds = get_credentials() username = creds['username'] password = creds['password'] if len(access_token) > 0 and len(username) > 0 and force == False: user_agent = settings.get(key='_user_agent') HEADERS = { 'User-Agent': user_agent, 'X-Client-Id': settings.get(key='_client_id') + "||" + user_agent, 'X-OESP-Token': access_token, 'X-OESP-Username': username, } self._session = Session(headers=HEADERS) self.logged_in = True return self.logged_in = False if not len(username) > 0: return if not len(password) > 0: password = gui.numeric(message=_.ASK_PASSWORD).strip() if not len(password) > 0: gui.ok(message=_.EMPTY_PASS, heading=_.LOGIN_ERROR_TITLE) return self.login(username=username, password=password, channels=channels)
def login(ask=1, **kwargs): ask = int(ask) profile_settings = load_profile(profile_id=1) if len(profile_settings['devicekey']) == 0: _devicekey = 'w{uuid}'.format(uuid=uuid.uuid4()) query = "UPDATE `vars` SET `devicekey`='{devicekey}' WHERE profile_id={profile_id}".format( devicekey=_devicekey, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) creds = get_credentials() if len(creds['username']) < 1 or len(creds['password']) < 1 or ask == 1: username = gui.input(message=_.ASK_USERNAME, default=creds['username']).strip() if not len(username) > 0: gui.ok(message=_.EMPTY_USER, heading=_.LOGIN_ERROR_TITLE) return password = gui.input(message=_.ASK_PASSWORD, hide_input=True).strip() if not len(password) > 0: gui.ok(message=_.EMPTY_PASS, heading=_.LOGIN_ERROR_TITLE) return set_credentials(username=username, password=password) login_result = api.login() if login_result['result'] == False: query = "UPDATE `vars` SET `pswd`='', `last_login_success`='{last_login_success}' WHERE profile_id={profile_id}".format( last_login_success=0, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) if check_key(login_result['data'], 'error') and login_result['data']['error'] == 'toomany': gui.ok(message=_.TOO_MANY_DEVICES, heading=_.LOGIN_ERROR_TITLE) else: gui.ok(message=_.LOGIN_ERROR, heading=_.LOGIN_ERROR_TITLE) else: gui.ok(message=_.LOGIN_SUCCESS) query = "UPDATE `vars` SET `last_login_success`='{last_login_success}' WHERE profile_id={profile_id}".format( last_login_success=1, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) gui.refresh()
def login(ask=1, **kwargs): ask = int(ask) profile_settings = load_profile(profile_id=1) if len(profile_settings['devicekey']) == 0: devicekey = ''.join(random.choice(string.digits) for _ in range(10)) query = "UPDATE `vars` SET `devicekey`='{devicekey}' WHERE profile_id={profile_id}".format(devicekey=devicekey, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) creds = get_credentials() if len(creds['username']) < 1 or len(creds['password']) < 1 or ask == 1: username = gui.numeric(message=_.ASK_USERNAME, default=creds['username']).strip() if not len(username) > 0: gui.ok(message=_.EMPTY_USER, heading=_.LOGIN_ERROR_TITLE) return password = gui.numeric(message=_.ASK_PASSWORD).strip() if not len(password) > 0: gui.ok(message=_.EMPTY_PASS, heading=_.LOGIN_ERROR_TITLE) return set_credentials(username=username, password=password) login_result = api.login() if login_result['result'] == False: query = "UPDATE `vars` SET `pswd`='', `last_login_success`='{last_login_success}' WHERE profile_id={profile_id}".format(last_login_success=0, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) if check_key(login_result['data'], 'result') and check_key(login_result['data']['result'], 'retCode') and login_result['data']['result']['retCode'] == "157022007": gui.ok(message=_.TOO_MANY_DEVICES, heading=_.LOGIN_ERROR_TITLE) else: gui.ok(message=_.LOGIN_ERROR, heading=_.LOGIN_ERROR_TITLE) else: query = "UPDATE `vars` SET `last_login_success`='{last_login_success}' WHERE profile_id={profile_id}".format(last_login_success=1, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) gui.ok(message=_.LOGIN_SUCCESS) gui.refresh()
def login(**kwargs): creds = get_credentials() username = gui.numeric(message=_.ASK_USERNAME, default=creds['username']).strip() if not len(username) > 0: gui.ok(message=_.EMPTY_USER, heading=_.LOGIN_ERROR_TITLE) return password = gui.numeric(message=_.ASK_PASSWORD).strip() if not len(password) > 0: gui.ok(message=_.EMPTY_PASS, heading=_.LOGIN_ERROR_TITLE) return api.login(username=username, password=password, channels=True) plugin.logged_in = api.logged_in gui.refresh()
def check_vars(self): try: self._debug_mode except: self._debug_mode = settings.getBool(key='enable_debug') if self._debug_mode: log.debug('Executing: api.check_vars') try: self._cookies except: self._cookies = settings.get(key='_cookies') try: self._session_age except: self._session_age = settings.getInt(key='_session_age') try: self._last_login_success except: self._last_login_success = settings.getBool( key='_last_login_success') try: self._channels_age except: self._channels_age = settings.getInt(key='_channels_age') try: self._enable_cache except: self._enable_cache = settings.getBool(key='enable_cache') try: self._api_url except: self._api_url = settings.get(key='_api_url') try: self._devicekey except: self._devicekey = settings.get(key='_devicekey') try: self._username except: try: creds except: creds = get_credentials() self._username = creds['username'] try: self._abortRequested except: self._abortRequested = False try: self._password except: try: creds except: creds = get_credentials() self._password = creds['password'] if self._debug_mode: log.debug('Execution Done: api.check_vars')
def login(self): creds = get_credentials() username = creds['username'] password = creds['password'] query = "UPDATE `vars` SET `cookies`='' WHERE profile_id={profile_id}".format( profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) profile_settings = load_profile(profile_id=1) session_url = '{api_url}/USER/SESSIONS/'.format( api_url=profile_settings['api_url']) 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': profile_settings['browser_name'], 'deviceModel': profile_settings['browser_version'], 'deviceFirmVersion': profile_settings['os_name'], 'appVersion': profile_settings['os_version'] } }, } else: session_post_data = { "credentialsStdAuth": { 'username': username, 'password': password, 'remember': 'Y', 'deviceRegistrationData': { 'deviceId': profile_settings['devicekey'], 'accountDeviceIdType': 'DEVICEID', 'deviceType': 'PCTV', 'vendor': profile_settings['browser_name'], 'model': profile_settings['browser_version'], 'deviceFirmVersion': profile_settings['os_name'], 'appVersion': profile_settings['os_version'] } }, } download = self.download(url=session_url, type='post', headers=None, data=session_post_data, json_data=True, return_json=True) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data or not check_key( data, 'resultCode') or not data['resultCode'] == 'OK': if not data: data = {} return {'data': data, 'result': False} return {'data': data, 'result': True}
def login(self): creds = get_credentials() username = creds['username'] password = creds['password'] query = "UPDATE `vars` SET `csrf_token`='', `cookies`='', `user_filter`='' WHERE profile_id={profile_id}".format( profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) profile_settings = load_profile(profile_id=1) login_url = '{base_url}/VSP/V3/Authenticate?from=throughMSAAccess'.format( base_url=CONST_BASE_URL) session_post_data = { "authenticateBasic": { #'VUID': '6_7_{devicekey}'.format(devicekey=profile_settings['devicekey']), 'clientPasswd': password, 'isSupportWebpImgFormat': '0', 'lang': 'nl', 'needPosterTypes': [ '1', '2', '3', '4', '5', '6', '7', ], 'timeZone': 'Europe/Amsterdam', 'userID': username, 'userType': '0', }, 'authenticateDevice': { 'CADeviceInfos': [ { 'CADeviceID': profile_settings['devicekey'], 'CADeviceType': '7', }, ], 'deviceModel': '3103_PCClient', 'physicalDeviceID': profile_settings['devicekey'], 'terminalID': profile_settings['devicekey'], }, 'authenticateTolerant': { 'areaCode': '', 'bossID': '', 'subnetID': '', 'templateName': '', 'userGroup': '', }, } headers = CONST_BASE_HEADERS download = self.download(url=login_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data or not check_key( data, 'result') or not check_key( data['result'], 'retCode') or not data['result'][ 'retCode'] == '000000000' or not check_key( data, 'csrfToken'): if not resp: resp = {} if not data: data = {} return {'resp': resp, 'data': data, 'result': False} query = "UPDATE `vars` SET `csrf_token`='{csrf_token}', `user_filter`='{user_filter}' WHERE profile_id={profile_id}".format( csrf_token=data['csrfToken'], user_filter=data['userFilter'], profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) return {'resp': resp, 'data': data, 'result': True}
def login(self): creds = get_credentials() username = creds['username'] password = creds['password'] query = "UPDATE `vars` SET `cookies`='', `session_token`='' WHERE profile_id={profile_id}".format( profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) profile_settings = load_profile(profile_id=1) 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 = self.download(url=auth_url, type='get', headers=None, data=None, json_data=False, return_json=False, allow_redirects=False) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data: if not data: data = {} return {'data': data, 'result': False} headers = CONST_LOGIN_HEADERS headers.update({'Referer': auth_url}) session_post_data = { "Password": password, "Username": username, } download = self.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'] resp = download['resp'] if not resp or not resp.status_code == 302: if not data: data = {} return {'data': data, 'result': False} params = parse_qs(urlparse(resp.headers['Location']).query) if check_key(params, 'code'): oauth = params['code'][0] if len(oauth) == 0: if not data: data = {} return {'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": profile_settings['browser_name'], "model": "web", "serial": profile_settings['devicekey'], "oauthcode": oauth } headers = CONST_BASE_HEADERS headers.update({'Content-Type': 'application/json;charset=UTF-8'}) download = self.download(url=challenge_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True, allow_redirects=False) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data or not check_key( data, 'id') or not check_key(data, 'secret'): if not data: data = {} return {'data': data, 'result': False} login_url = "{base_url}/m7be2iphone/login.aspx".format( base_url=CONST_BASE_URL) headers = CONST_BASE_HEADERS headers.update({ '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": self._devicekey, "app": "cds", } download = self.download(url=login_url, type='post', headers=headers, data=session_post_data, json_data=False, return_json=False, allow_redirects=False) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 302: if not data: data = {} return {'data': data, 'result': False} ssotoken_url = "{base_url}/m7be2iphone/capi.aspx?z=ssotoken".format( base_url=CONST_BASE_URL) headers = CONST_BASE_HEADERS download = self.download(url=ssotoken_url, type='get', headers=headers, data=None, json_data=False, return_json=True, allow_redirects=False) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data or not check_key( data, 'ssotoken'): if not data: data = {} return {'data': data, 'result': False} session_url = "{api_url}/session".format(api_url=CONST_DEFAULT_API) session_post_data = { "sapiToken": data['ssotoken'], "deviceType": "PC", "deviceModel": profile_settings['browser_name'], "osVersion": '{name} {version}'.format(name=profile_settings['os_name'], version=profile_settings['os_version']), "deviceSerial": profile_settings['devicekey'], "appVersion": profile_settings['browser_version'], "brand": "cds" } headers = CONST_BASE_HEADERS headers.update({'Content-Type': 'application/json;charset=UTF-8'}) download = self.download(url=session_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True, allow_redirects=False) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data or not check_key( data, 'token'): if not data: data = {} return {'data': data, 'result': False} query = "UPDATE `vars` SET `session_token`={session_token} WHERE profile_id={profile_id}".format( session_token=data['token'], profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) return {'data': data, 'result': True}
def play_video(type=None, id=None, locator=None, catchup=None, duration=0, **kwargs): properties = {} label = '' info = {} art = {} if not type or not len(type) > 0: return False if (catchup and len(catchup) > 0) or type=='program': if catchup and len(catchup) > 0: id = catchup properties['seekTime'] = 1 type = 'program' if not id or not len(id) > 0: return False if type == "program": listings_url = "{listings_url}/{id}".format(listings_url=settings.get(key='_listings_url'), id=id) data = api.download(url=listings_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False) if not data or not check_key(data, 'program') or not check_key(data['program'], 'videoStreams'): gui.ok(message=_.STREAM_NOT_AVAILABLE, heading=_.STREAM_NOT_FOUND) return False urldata = get_play_url(content=data['program']['videoStreams']) if not urldata or not check_key(urldata, 'play_url') or not check_key(urldata, 'locator'): gui.ok(message=_.STREAM_NOT_AVAILABLE, heading=_.STREAM_NOT_FOUND) return False playdata = api.play_url(type='program', path=urldata['play_url'], locator=urldata['locator']) if check_key(data['program'], 'duration'): duration = int(data['program']['duration']) elif check_key(data, 'startTime') and check_key(data, 'endTime'): duration = int(int(data['endTime']) - int(data['startTime'])) // 1000 label = data['program']['title'] info = { 'plot': data['program']['description'], 'duration': duration, 'mediatype': 'video'} art = {'thumb': get_image("boxart", data['program']['images'])} elif type == "vod": playdata = api.play_url(type='vod', path=id) elif type == "channel": if not locator or not len(locator) > 0: return False playdata = api.play_url(type='channel', path=id, locator=locator) if not check_key(playdata, 'path') or not check_key(playdata, 'license') or not check_key(playdata, 'token') or not check_key(playdata, 'locator'): return False user_agent = settings.get(key='_user_agent') creds = get_credentials() CDMHEADERS = { 'User-Agent': user_agent, 'X-Client-Id': settings.get(key='_client_id') + '||' + user_agent, 'X-OESP-Token': settings.get(key='_access_token'), 'X-OESP-Username': creds['username'], 'X-OESP-License-Token': settings.get(key='_drm_token'), 'X-OESP-DRM-SchemeIdUri': 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed', 'X-OESP-Content-Locator': playdata['locator'], } settings.setInt(key='_stream_duration', value=duration) listitem = plugin.Item( properties = properties, label = label, info = info, art = art, playable = True, path = playdata['path'], headers = CDMHEADERS, inputstream = inputstream.Widevine( license_key = playdata['license'], media_renewal_url = plugin.url_for(func_or_url=renew_token, id=playdata['path'], type=type, locator=playdata['locator']), media_renewal_time = 60, ), ) return listitem