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']
def api_add_to_watchlist(id, type): if not api_get_session(): return None profile_settings = load_profile(profile_id=1) if type == "item": mediaitems_url = '{listings_url}/{id}'.format( listings_url=profile_settings['listings_url'], id=id) download = api_download(url=mediaitems_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, 'mediaGroupId'): return False id = data['mediaGroupId'] if profile_settings['base_v3'] == 1: watchlist_url = 'https://prod.spark.ziggogo.tv/nld/web/watchlist-service/v1/watchlists/{watchlist_id}/entries/{id}?sharedProfile=true'.format( watchlist_id=profile_settings['watchlist_id'], id=id) else: watchlist_url = '{watchlist_url}/entries'.format( watchlist_url=profile_settings['watchlist_url']) download = api_download(url=watchlist_url, type='post', headers=api_get_headers(), data={"mediaGroup": { 'id': id }}, json_data=True, return_json=False) data = download['data'] code = download['code'] if not code or not code == 204 or not data: return False return True
def api_clean_after_playback(stoptime): profile_settings = load_profile(profile_id=1) if len(str(profile_settings['ticket_id'])) > 0: offset = "00:00:00" if stoptime > 0: m, s = divmod(stoptime, 60) h, m = divmod(m, 60) offset = '{:02d}:{:02d}:{:02d}'.format(h, m, s) session_post_data = { 'action': "stop", 'buffer_state': 0, 'buffer_total': 1, 'offset': offset, 'token': profile_settings['token'] } headers = api_get_headers(personal=False) stop_url = '{base_url}/api/v3/heartbeat/{ticket_id}?action=stop&offset={offset}'.format( base_url=CONST_URLS['base'], ticket_id=profile_settings['ticket_id'], offset=offset) download = api_download(url=stop_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) session_post_data['action'] = 'exit' exit_url = '{base_url}/api/v3/heartbeat/{ticket_id}?action=exit&offset={offset}'.format( base_url=CONST_URLS['base'], ticket_id=profile_settings['ticket_id'], offset=offset) download = api_download(url=exit_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True)
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}
def api_get_info(id, channel=''): profile_settings = load_profile(profile_id=1) info = {} friendly = '' headers = { 'authorization': 'Bearer {id_token}'.format(id_token=profile_settings['access_token'])} data = api_get_channels() try: friendly = data[str(id)]['assetid'] except: return info channel_url = '{base_url}/v6/epg/locations/{friendly}/live/1?fromDate={date}'.format(base_url=CONST_API_URL, friendly=friendly, date=datetime.datetime.now().strftime("%Y-%m-%dT%H%M%S")) download = api_download(url=channel_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: return info for row in data: if not check_key(row, 'Channel') or not check_key(row, 'Locations'): return info for row2 in row['Locations']: id = row2['LocationId'] if not id: return info info_url = '{base_url}/v6/epg/location/{location}'.format(base_url=CONST_API_URL, location=id) download = api_download(url=info_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: return info info = data return plugin_process_info({'title': '', 'channel': channel, 'info': info})
def api_vod_season(series, id): if not api_get_session(): return None season = [] profile_settings = load_profile(profile_id=1) season_url = '{mediaitems_url}?byMediaType=Episode%7CFeatureFilm&byParentId={id}&includeAdult=true&range=1-1000&sort=seriesEpisodeNumber|ASC'.format(mediaitems_url=CONST_API_URLS[0]['mediaitems_url'], id=id) download = api_download(url=season_url, type='get', headers=None, data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if not data or not check_key(data, 'mediaItems'): return None data['mediaItems'] = list(data['mediaItems']) for row in data['mediaItems']: desc = '' image = '' label = '' if not check_key(row, 'title') or not check_key(row, 'id'): continue if check_key(row, 'description'): desc = row['description'] if check_key(row, 'duration'): duration = int(row['duration']) if check_key(row, 'images'): program_image = get_image("boxart", row['images']) image = get_image("HighResLandscape", row['images']) if image == '': image = program_image else: image += '?w=1920&mode=box' if check_key(row, 'earliestBroadcastStartTime'): startsplit = int(row['earliestBroadcastStartTime']) // 1000 startT = datetime.datetime.fromtimestamp(startsplit) startT = convert_datetime_timezone(startT, "UTC", "UTC") if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': label = date_to_nl_dag(startT) + startT.strftime(" %d ") + date_to_nl_maand(startT) + startT.strftime(" %Y %H:%M ") + row['title'] else: label = (startT.strftime("%A %d %B %Y %H:%M ") + row['title']).capitalize() else: label = row['title'] season.append({'label': label, 'id': row['id'], 'start': '', 'duration': duration, 'title': row['title'], 'seasonNumber': '', 'episodeNumber': '', 'description': desc, 'image': image}) return season
def api_add_to_watchlist(id, type): if not api_get_session(): return None profile_settings = load_profile(profile_id=1) if type == "item": mediaitems_url = '{listings_url}/{id}'.format( listings_url=CONST_API_URLS['listings_url'], id=id) download = api_download(url=mediaitems_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, 'mediaGroupId'): return False id = data['mediaGroupId'] watchlist_url = '{watchlist_url}/{watchlist_id}/entries/{id}?sharedProfile=true'.format( watchlist_url=CONST_API_URLS['watchlist_url'], watchlist_id=profile_settings['watchlist_id'], id=id) download = api_download(url=watchlist_url, type='post', headers=api_get_headers(), data={"mediaGroup": { 'id': id }}, json_data=True, return_json=False) data = download['data'] code = download['code'] if not code or not code == 204 or not data: return False return True
def api_vod_seasons(id): if not api_get_session(): return None profile_settings = load_profile(profile_id=1) seasons = [] program_url = '{api_url}/CONTENT/DETAIL/GROUP_OF_BUNDLES/{id}'.format( api_url=profile_settings['api_url'], id=id) file = "cache" + os.sep + "vod_seasons_" + unicode(id) + ".json" if settings.getBool( key='enable_cache') and not is_file_older_than_x_minutes( file=ADDON_PROFILE + file, minutes=10): data = load_file(file=file, isJSON=True) else: download = api_download(url=program_url, type='get', headers=None, data=None, json_data=True, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key( data, 'resultCode') and data['resultCode'] == 'OK' and check_key( data, 'resultObj') and check_key( data['resultObj'], 'containers') and settings.getBool(key='enable_cache'): write_file(file=file, data=data, isJSON=True) if not data or not check_key(data['resultObj'], 'containers'): return None for row in data['resultObj']['containers']: for currow in row['containers']: if check_key(currow, 'metadata') and check_key( currow['metadata'], 'season' ) and currow['metadata']['contentSubtype'] == 'SEASON': seasons.append({ 'id': currow['metadata']['contentId'], 'seriesNumber': currow['metadata']['season'], 'description': currow['metadata']['shortDescription'], 'image': "{image_url}/vod/{image}/1920x1080.jpg?blurred=false". format(image_url=CONST_IMAGE_URL, image=currow['metadata']['pictureUrl']) }) return {'type': 'seasons', 'seasons': seasons}
def api_vod_download(type, start=0): if type == "moviesnpo": url = '{base_url}/v7/recommend/movies?limit=9999&offset=0&contentProvider=npo'.format( base_url=CONST_URLS['api'], start=start) elif type == "movies": url = '{base_url}/v7/recommend/movies?limit=9999&offset=0'.format( base_url=CONST_URLS['api'], start=start) elif type == "watchaheadnpo": url = '{base_url}/v7/watchinadvance?limit=9999&offset=0&contentProvider=npo'.format( base_url=CONST_URLS['api'], start=start) elif type == "watchahead": url = '{base_url}/v7/watchinadvance?limit=9999&offset=0'.format( base_url=CONST_URLS['api'], start=start) elif type == "seriesbingenpo": url = '{base_url}/v7/recommend/series?limit=9999&offset=0&contentProvider=npo'.format( base_url=CONST_URLS['api'], start=start) elif type == "seriesbinge": url = '{base_url}/v7/recommend/series?limit=9999&offset=0'.format( base_url=CONST_URLS['api'], start=start) elif type == "mostviewed": url = '{base_url}/v7/recommend/trendingvideos?limit=9999&offset=0'.format( base_url=CONST_URLS['api'], start=start) elif type == "tipfeednpo": url = '{base_url}/v7/recommend/recommendedvideos?limit=9999&offset=0&contentProvider=npo'.format( base_url=CONST_URLS['api'], start=start) elif type == "tipfeed": url = '{base_url}/v7/recommend/recommendedvideos?limit=9999&offset=0'.format( base_url=CONST_URLS['api'], start=start) else: return None type = "vod_{type}_{start}".format(type=type, start=start) type = encode32(txt=type) file = os.path.join("cache", "{type}.json".format(type=type)) if not is_file_older_than_x_days(file=os.path.join(ADDON_PROFILE, file), days=0.5): data = load_file(file=file, isJSON=True) else: download = api_download(url=url, type='get', headers=None, data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data: write_file(file=file, data=data, isJSON=True) if not data: return None return data
def api_vod_season(series, id): if not api_get_session(): return None season = [] type = "vod_season_" + unicode(id) encodedBytes = base64.b32encode(type.encode("utf-8")) type = unicode(encodedBytes, "utf-8") file = "cache" + os.sep + type + ".json" if not is_file_older_than_x_days(file=ADDON_PROFILE + file, days=0.5): data = load_file(file=file, isJSON=True) else: profile_settings = load_profile(profile_id=1) headers = {'Content-Type': 'application/json', 'X_CSRFToken': profile_settings['csrf_token']} session_post_data = { 'VODID': unicode(id), 'offset': '0', 'count': '35', } seasons_url = '{base_url}/VSP/V3/QueryEpisodeList?from=throughMSAAccess'.format(base_url=CONST_BASE_URL) download = api_download(url=seasons_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key(data, 'result') and check_key(data['result'], 'retCode') and data['result']['retCode'] == '000000000' and check_key(data, 'episodes'): write_file(file=file, data=data, isJSON=True) if not data or not check_key(data, 'episodes'): return None for row in data['episodes']: if check_key(row, 'VOD') and check_key(row['VOD'], 'ID') and check_key(row['VOD'], 'name') and check_key(row, 'sitcomNO'): image = '' duration = 0 if not check_key(row['VOD'], 'mediaFiles') or not check_key(row['VOD']['mediaFiles'][0], 'ID'): continue if check_key(row['VOD']['mediaFiles'][0], 'elapseTime'): duration = row['VOD']['mediaFiles'][0]['elapseTime'] if check_key(row['VOD'], 'picture') and check_key(row['VOD']['picture'], 'posters'): image = row['VOD']['picture']['posters'][0] label = '{episode} - {title}'.format(episode=row['sitcomNO'], title=row['VOD']['name']) season.append({'label': label, 'id': row['VOD']['ID'], 'media_id': row['VOD']['mediaFiles'][0]['ID'], 'duration': duration, 'title': row['VOD']['name'], 'episodeNumber': row['sitcomNO'], 'description': '', 'image': image}) return season
def api_vod_seasons(type, id): if not api_get_session(): return None seasons = [] program_url = '{api_url}/CONTENT/DETAIL/GROUP_OF_BUNDLES/{id}'.format( api_url=CONST_DEFAULT_API, id=id) type = "vod_seasons_" + unicode(id) encodedBytes = base64.b64encode(type.encode("utf-8")) type = unicode(encodedBytes, "utf-8") file = "cache" + os.sep + type + ".json" if not is_file_older_than_x_days(file=ADDON_PROFILE + file, days=0.5): data = load_file(file=file, isJSON=True) else: download = api_download(url=program_url, type='get', headers=None, data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key( data, 'resultCode') and data['resultCode'] == 'OK' and check_key( data, 'resultObj') and check_key(data['resultObj'], 'containers'): write_file(file=file, data=data, isJSON=True) if not data or not check_key(data['resultObj'], 'containers'): return None for row in data['resultObj']['containers']: for currow in row['containers']: if check_key(currow, 'metadata') and check_key( currow['metadata'], 'season' ) and currow['metadata']['contentSubtype'] == 'SEASON': seasons.append({ 'id': currow['metadata']['contentId'], 'seriesNumber': currow['metadata']['season'], 'description': currow['metadata']['shortDescription'], 'image': "{image_url}/vod/{image}/1920x1080.jpg?blurred=false". format(image_url=CONST_IMAGE_URL, image=currow['metadata']['pictureUrl']) }) return {'type': 'seasons', 'seasons': seasons}
def api_clean_after_playback(): profile_settings = load_profile(profile_id=1) headers = api_get_headers() headers['Content-type'] = 'application/json' download = api_download(url=CONST_API_URLS['clearstreams_url'], type='post', headers=headers, data='{}', json_data=False, return_json=False)
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
def api_remove_from_watchlist(id): if not api_get_session(): return None profile_settings = load_profile(profile_id=1) remove_url = '{watchlist_url}/{watchlist_id}/entries/{id}?sharedProfile=true'.format(watchlist_url=CONST_API_URLS[0]['watchlist_url'], watchlist_id=profile_settings['watchlist_id'], id=id) download = api_download(url=remove_url, type='delete', headers=api_get_headers(), data=None, json_data=False, return_json=False) code = download['code'] if not code or not code == 204: return False return True
def api_clean_after_playback(): profile_settings = load_profile(profile_id=1) session_post_data = { 'action': "stop", 'buffer_state': 0, 'buffer_total': 1, 'offset': "00:00:00", 'token': profile_settings['token'] } headers = { 'videoland-platform': 'videoland', } stop_url = '{base_url}/api/v3/heartbeat/{ticket_id}?action=stop&offset=00:00:00'.format( base_url=CONST_BASE_URL, ticket_id=profile_settings['ticket_id']) download = api_download(url=stop_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) session_post_data['action'] = 'exit' exit_url = '{base_url}/api/v3/heartbeat/{ticket_id}?action=exit&offset=00:00:00'.format( base_url=CONST_BASE_URL, ticket_id=profile_settings['ticket_id']) download = api_download(url=exit_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True)
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 }
def api_vod_seasons(type, id): if not api_get_session(): return None type = "vod_seasons_{id}".format(id=id) type = encode32(type) file = os.path.join("cache", "{type}.json".format(type=type)) cache = 0 if not is_file_older_than_x_days(file=os.path.join(ADDON_PROFILE, file), days=0.5) and use_cache == True: data = load_file(file=file, isJSON=True) cache = 1 else: profile_settings = load_profile(profile_id=1) headers = { 'Content-Type': 'application/json', 'X_CSRFToken': profile_settings['csrf_token'] } session_post_data = { 'VODID': str(id), 'offset': '0', 'count': '50', } seasons_url = '{base_url}/VSP/V3/QueryEpisodeList?from=throughMSAAccess'.format( base_url=CONST_URLS['base']) download = api_download(url=seasons_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key( data, 'result') and check_key( data['result'], 'retCode' ) and data['result']['retCode'] == '000000000' and check_key( data, 'episodes'): write_file(file=file, data=data, isJSON=True) return {'data': data, 'cache': cache}
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
def api_list_devices(): download = api_download(url='{devices_url}/status'.format( devices_url=CONST_URLS['devices_digital_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, 'devices'): return False return data['devices']
def api_list_watchlist(): if not api_get_session(): return None profile_settings = load_profile(profile_id=1) watchlist_url = '{watchlist_url}/profile/{profile_id}?language=nl&order=DESC&sharedProfile=true&sort=added'.format(watchlist_url=CONST_API_URLS[0]['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, 'entries'): return False return data
def api_vod_download(type, start=0): if not api_get_session(): return None if type == "movies": url = '{base_url}/v6/tabs/GenreFilms?count=52&expand=true&expandlist=true&maxResults=52&offset={start}'.format( base_url=CONST_API_URL, start=start) elif type == "watchahead": url = '{base_url}/v6/tabs/VooruitKijken2?count=52&expand=true&expandlist=true&maxResults=52&offset={start}'.format( base_url=CONST_API_URL, start=start) elif type == "seriesbinge": url = '{base_url}/v6/tabs/SeriesBingewatch?count=52&expand=true&expandlist=true&maxResults=52&offset={start}'.format( base_url=CONST_API_URL, start=start) elif type == "mostviewed": url = '{base_url}/v6/tabs/MostViewed?count=52&expand=true&expandlist=true&maxResults=52&offset={start}'.format( base_url=CONST_API_URL, start=start) elif type == "tipfeed": url = '{base_url}/v6/tabs/Tipfeed?count=52&expand=true&expandlist=true&maxResults=52&offset={start}'.format( base_url=CONST_API_URL, start=start) else: return None type = "vod_" + type + "_" + unicode(start) encodedBytes = base64.b32encode(type.encode("utf-8")) type = unicode(encodedBytes, "utf-8") file = "cache" + os.sep + type + ".json" if not is_file_older_than_x_days(file=ADDON_PROFILE + file, days=0.5): data = load_file(file=file, isJSON=True) else: download = api_download(url=url, type='get', headers=None, data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data: write_file(file=file, data=data, isJSON=True) if not data or not check_key(data, 'Items'): return None return api_process_vod(data=data)
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
def api_vod_season(series, id): if not api_get_session(): return None season = [] episodes = [] program_url = '{api_url}/CONTENT/DETAIL/BUNDLE/{id}'.format(api_url=CONST_DEFAULT_API, id=id) type = "vod_season_" + unicode(id) encodedBytes = base64.b32encode(type.encode("utf-8")) type = unicode(encodedBytes, "utf-8") file = "cache" + os.sep + type + ".json" if not is_file_older_than_x_days(file=ADDON_PROFILE + file, days=0.5): data = load_file(file=file, isJSON=True) else: download = api_download(url=program_url, type='get', headers=None, data=None, json_data=True, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key(data, 'resultCode') and data['resultCode'] == 'OK' and check_key(data, 'resultObj') and check_key(data['resultObj'], 'containers'): write_file(file=file, data=data, isJSON=True) if not data or not check_key(data['resultObj'], 'containers'): return None for row in data['resultObj']['containers']: for currow in row['containers']: if check_key(currow, 'metadata') and check_key(currow['metadata'], 'season') and unicode(currow['metadata']['contentSubtype']) == 'EPISODE' and not unicode(currow['metadata']['episodeNumber']) in episodes: asset_id = '' for asset in currow['assets']: if check_key(asset, 'videoType') and asset['videoType'] == 'SD_DASH_PR' and check_key(asset, 'assetType') and asset['assetType'] == 'MASTER': asset_id = unicode(asset['assetId']) break episodes.append(unicode(currow['metadata']['episodeNumber'])) label = '{season}.{episode} - {title}'.format(season=unicode(currow['metadata']['season']), episode=unicode(currow['metadata']['episodeNumber']), title=unicode(currow['metadata']['episodeTitle'])) season.append({'label': label, 'id': unicode(currow['metadata']['contentId']), 'assetid': asset_id, 'duration': currow['metadata']['duration'], 'title': unicode(currow['metadata']['episodeTitle']), 'episodeNumber': '{season}.{episode}'.format(season=unicode(currow['metadata']['season']), episode=unicode(currow['metadata']['episodeNumber'])), 'description': unicode(currow['metadata']['shortDescription']), 'image': "{image_url}/vod/{image}/1920x1080.jpg?blurred=false".format(image_url=CONST_IMAGE_URL, image=unicode(currow['metadata']['pictureUrl']))}) return season
def api_watchlist_listing(id): if not api_get_session(): return None profile_settings = load_profile(profile_id=1) end = int(time.time() * 1000) start = end - (7 * 24 * 60 * 60 * 1000) mediaitems_url = '{media_items_url}?&byMediaGroupId={id}&byStartTime={start}~{end}&range=1-250&sort=startTime%7Cdesc'.format(media_items_url=CONST_API_URLS[0]['listings_url'], id=id, start=start, end=end) download = api_download(url=mediaitems_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, 'listings'): return False return data
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
def api_get_info(id, channel=''): profile_settings = load_profile(profile_id=1) info = {} base_listing_url = CONST_API_URLS[0]['listings_url'] listing_url = '{listings_url}?byEndTime={time}~&byStationId={channel}&range=1-1&sort=startTime'.format(listings_url=base_listing_url, time=int(time.time() * 1000), channel=id) download = api_download(url=listing_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key(data, 'listings'): for row in data['listings']: if check_key(row, 'program'): info = row['program'] info = plugin_process_info({'title': '', 'channel': channel, 'info': info}) return info
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: query = "UPDATE `vars` SET `last_login_time`={last_login_time}, `last_login_success`=1 WHERE profile_id={profile_id}".format( last_login_time=int(time.time()), profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) except: pass return True
def api_vod_seasons(id): if not api_get_session(): return None seasons = [] file = "cache" + os.sep + "vod_seasons_" + unicode(id) + ".json" if settings.getBool(key='enable_cache') and not is_file_older_than_x_minutes(file=ADDON_PROFILE + file, minutes=10): data = load_file(file=file, isJSON=True) else: profile_settings = load_profile(profile_id=1) headers = {'Content-Type': 'application/json', 'X_CSRFToken': profile_settings['csrf_token']} session_post_data = { 'VODID': unicode(id), 'offset': '0', 'count': '50', } seasons_url = '{base_url}/VSP/V3/QueryEpisodeList?from=throughMSAAccess'.format(base_url=CONST_BASE_URL) download = api_download(url=seasons_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key(data, 'result') and check_key(data['result'], 'retCode') and data['result']['retCode'] == '000000000' and check_key(data, 'episodes') and settings.getBool(key='enable_cache'): write_file(file=file, data=data, isJSON=True) if not data or not check_key(data, 'episodes'): return None for row in data['episodes']: if check_key(row, 'VOD') and check_key(row['VOD'], 'ID') and check_key(row, 'sitcomNO'): image = '' if check_key(row['VOD'], 'picture') and check_key(row['VOD']['picture'], 'posters'): image = row['VOD']['picture']['posters'][0] seasons.append({'id': row['VOD']['ID'], 'seriesNumber': row['sitcomNO'], 'description': '', 'image': image}) return {'type': 'seasons', 'seasons': seasons}
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 = '{api_url}/USER/DEVICES'.format( api_url=profile_settings['api_url']) 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: query = "UPDATE `vars` SET `last_login_time`={last_login_time}, `last_login_success`=1 WHERE profile_id={profile_id}".format( last_login_time=int(time.time()), profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) except: pass return True
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