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 process_vod_season(data, mediagroupid=None): items = [] if sys.version_info >= (3, 0): data['mediaItems'] = list(data['mediaItems']) for row in data['mediaItems']: context = [] label = '' description = '' program_image_large = '' duration = 0 if not check_key(row, 'title') or not check_key(row, 'id'): continue if check_key(row, 'description'): description = row['description'] 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'] if check_key(row, 'duration'): duration = int(row['duration']) if check_key(row, 'images'): program_image_large = get_image("boxart", row['images']) if check_key(row, 'videoStreams'): urldata = get_play_url(content=row['videoStreams']) if urldata and check_key(urldata, 'play_url') and check_key(urldata, 'locator'): if mediagroupid: context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=mediagroupid, type='group')), )) items.append(plugin.Item( label = label, info = { 'plot': description, 'duration': duration, 'mediatype': 'video', }, art = {'thumb': program_image_large}, path = plugin.url_for(func_or_url=play_video, type='vod', id=row['id'], duration=duration, _is_live=False), playable = True, context = context )) return items
def get_channel_data(self, row): channeldata = { 'channel_id': row['stationSchedules'][0]['station']['id'], 'channel_number': row['channelNumber'], 'description': row['stationSchedules'][0]['station']['description'], 'label': row['stationSchedules'][0]['station']['title'], 'station_image_large': get_image("station-logo", row['stationSchedules'][0]['station']['images']), 'stream': row['stationSchedules'][0]['station']['videoStreams'] } return channeldata
def api_search(query): if not api_get_session(): return None profile_settings = load_profile(profile_id=1) if int(profile_settings['v3']) == 1: return False end = int(time.time() * 1000) start = end - (7 * 24 * 60 * 60 * 1000) vodstr = '' encodedBytes = base64.b32encode(query.encode("utf-8")) queryb32 = unicode(encodedBytes, "utf-8") file = "cache" + os.sep + "{query}.json".format(query=queryb32) try: profile_settings = load_profile(profile_id=1) if int(profile_settings['v3']) == 1: file = "cache" + os.sep + "{query}.v3.json".format(query=queryb32) except: pass search_url = '{search_url}?byBroadcastStartTimeRange={start}~{end}&numItems=25&byEntitled=true&personalised=true&q={query}'.format( search_url=CONST_API_URLS[int(profile_settings['v3'])]['search_url'], start=start, end=end, query=quote(query)) 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=search_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, 'tvPrograms') or check_key(data, 'moviesAndSeries')): write_file(file=file, data=data, isJSON=True) if not data or (not check_key(data, 'tvPrograms') and not check_key(data, 'moviesAndSeries')): return False items = [] items_vod = [] items_program = [] vod_links = {} if not settings.getBool('showMoviesSeries'): try: data.pop('moviesAndSeries', None) except: pass else: for entry in CONST_VOD_CAPABILITY: data2 = api_get_vod_by_type(type=entry['file'], character=None, subscription_filter=None) for currow in data2: row = data2[currow] vod_links[row['id']] = {} vod_links[row['id']]['seasons'] = row['seasons'] vod_links[row['id']]['duration'] = row['duration'] vod_links[row['id']]['desc'] = row['description'] vod_links[row['id']]['type'] = row['type'] for currow in list(data): if currow == "moviesAndSeries": type = 'vod' else: type = 'program' for row in data[currow]['entries']: if not check_key(row, 'id') or not check_key(row, 'title'): continue item = {} id = row['id'] label = row['title'] description = '' duration = 0 program_image = '' program_image_large = '' start = '' if check_key(row, 'images'): program_image = get_image("boxart", row['images']) program_image_large = get_image("HighResLandscape", row['images']) if program_image_large == '': program_image_large = program_image else: program_image_large += '?w=1920&mode=box' if type == 'vod': if check_key(vod_links, row['id']): description = vod_links[row['id']]['desc'] item_type = vod_links[row['id']]['type'] else: item_type = 'Vod' label += " (Movies and Series)" else: item_type = 'Epg' label += " (ReplayTV)" if check_key(row, 'groupType') and row['groupType'] == 'show': if check_key(row, 'episodeMatch') and check_key( row['episodeMatch'], 'seriesEpisodeNumber') and check_key( row['episodeMatch'], 'secondaryTitle'): if len(description) == 0: description += label season = '' if check_key(row, 'seriesNumber'): season = "S" + row['seriesNumber'] description += " Episode Match: {season}E{episode} - {secondary}".format( season=season, episode=row['episodeMatch']['seriesEpisodeNumber'], secondary=row['episodeMatch']['secondaryTitle']) else: if check_key(row, 'duration'): duration = int(row['duration']) elif check_key(row, 'episodeMatch') and check_key( row['episodeMatch'], 'startTime') and check_key( row['episodeMatch'], 'endTime'): duration = int( int(row['episodeMatch']['endTime']) - int(row['episodeMatch']['startTime'])) // 1000 id = row['episodeMatch']['id'] elif check_key(vod_links, row['id']) and check_key( vod_links[row['id']], 'duration'): duration = vod_links[row['id']]['duration'] item['id'] = id item['title'] = label item['description'] = description item['duration'] = duration item['type'] = item_type item['icon'] = program_image_large item['start'] = start if type == "vod": items_vod.append(item) else: items_program.append(item) num = min(len(items_program), len(items_vod)) items = [None] * (num * 2) items[::2] = items_program[:num] items[1::2] = items_vod[:num] items.extend(items_program[num:]) items.extend(items_vod[num:]) return items
def process_online_search(data): items_vod = [] items_program = [] vod_links = {} if settings.getBool('showMoviesSeries') == True: vod_data = load_file(file='vod.json', isJSON=True) for vod_type in list(vod_data): for row in vod_data[vod_type]: if not check_key(row, 'id'): continue vod_links[row['id']] = {} if check_key(row, 'seasons'): vod_links[row['id']]['seasons'] = row['seasons'] if check_key(row, 'duration'): vod_links[row['id']]['duration'] = row['duration'] if check_key(row, 'desc'): vod_links[row['id']]['desc'] = row['desc'] for currow in list(data): if currow == "moviesAndSeries": if settings.getBool('showMoviesSeries') != True: continue type = 'vod' else: type = 'program' for row in data[currow]['entries']: context = [] if not check_key(row, 'id') or not check_key(row, 'title'): continue id = row['id'] label = row['title'] mediatype = '' description = '' duration = 0 program_image_large = '' if check_key(row, 'images'): get_image("boxart", row['images']) playable = False path = '' if check_key(vod_links, row['id']) and check_key(vod_links[row['id']], 'desc'): description = vod_links[row['id']]['desc'] if type == 'vod': label += " (Movies and Series)" else: label += " (ReplayTV)" if check_key(row, 'groupType') and row['groupType'] == 'show': if check_key(row, 'episodeMatch') and check_key(row['episodeMatch'], 'seriesEpisodeNumber') and check_key(row['episodeMatch'], 'secondaryTitle'): if len(description) == 0: description += label season = '' if check_key(row, 'seriesNumber'): season = "S" + row['seriesNumber'] description += " Episode Match: {season}E{episode} - {secondary}".format(season=season, episode=row['episodeMatch']['seriesEpisodeNumber'], secondary=row['episodeMatch']['secondaryTitle']) if type == 'vod': if not check_key(vod_links, row['id']) or not check_key(vod_links[row['id']], 'seasons'): continue context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=id, type='group')), )) path = plugin.url_for(func_or_url=vod_series, label=label, description=description, image=program_image_large, seasons=json.dumps(vod_links[row['id']]['seasons']), mediagroupid=id) else: context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=id, type='group')), )) path = plugin.url_for(func_or_url=watchlist_listing, label=label, description=description, image=program_image_large, id=id, search=True) else: context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=id, type='group')), )) if check_key(row, 'duration'): duration = int(row['duration']) elif check_key(row, 'episodeMatch') and check_key(row['episodeMatch'], 'startTime') and check_key(row['episodeMatch'], 'endTime'): duration = int(int(row['episodeMatch']['endTime']) - int(row['episodeMatch']['startTime'])) // 1000 id = row['episodeMatch']['id'] elif check_key(vod_links, row['id']) and check_key(vod_links[row['id']], 'duration'): duration = vod_links[row['id']]['duration'] path = plugin.url_for(func_or_url=play_video, type=type, id=id, duration=duration, _is_live=False) playable = True mediatype = 'video' item = plugin.Item( label = label, info = { 'plot': description, 'duration': duration, 'mediatype': mediatype, }, art = {'thumb': program_image_large}, path = path, playable = playable, context = context ) if type == "vod": items_vod.append(item) else: items_program.append(item) num = min(len(items_program), len(items_vod)) items = [None]*(num*2) items[::2] = items_program[:num] items[1::2] = items_vod[:num] items.extend(items_program[num:]) items.extend(items_vod[num:]) return items
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
def process_watchlist_listing(data, id=None): items = [] channeldata = {} stations = load_file(file='channels.json', isJSON=True) if stations: for row in stations: channeldata[row['stationSchedules'][0]['station']['id']] = row['stationSchedules'][0]['station']['title'] for row in data['listings']: context = [] if not check_key(row, 'program'): continue currow = row['program'] if not check_key(currow, 'title') or not check_key(row, 'id'): continue duration = 0 if check_key(row, 'endTime') and check_key(row, 'startTime'): startsplit = int(row['startTime']) // 1000 endsplit = int(row['endTime']) // 1000 duration = endsplit - startsplit startT = datetime.datetime.fromtimestamp(startsplit) startT = convert_datetime_timezone(startT, "UTC", "UTC") endT = datetime.datetime.fromtimestamp(endsplit) endT = convert_datetime_timezone(endT, "UTC", "UTC") if endT < (datetime.datetime.now(pytz.timezone("UTC")) - datetime.timedelta(days=7)): continue if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': label = '{weekday} {day} {month} {yearhourminute} '.format(weekday=date_to_nl_dag(startT), day=startT.strftime("%d"), month=date_to_nl_maand(startT), yearhourminute=startT.strftime("%Y %H:%M")) else: label = startT.strftime("%A %d %B %Y %H:%M ").capitalize() label += currow['title'] else: label = currow['title'] if check_key(channeldata, row['stationId']): label += ' ({station})'.format(station=channeldata[row['stationId']]) if id: context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=id, type="group")), )) description = '' image = '' if check_key(currow, 'description'): description = currow['description'] if check_key(currow, 'duration'): duration = int(currow['duration']) if check_key(currow, 'images'): image = get_image("boxart", currow['images']) items.append(plugin.Item( label = label, info = { 'plot': description, 'duration': duration, 'mediatype': 'video', }, art = {'thumb': image}, path = plugin.url_for(func_or_url=play_video, type="program", id=row['id'], duration=duration, _is_live=False), playable = True, context = context )) return items
def process_watchlist(data): items = [] for row in data['entries']: context = [] if check_key(row, 'mediaGroup') and check_key(row['mediaGroup'], 'medium') and check_key(row['mediaGroup'], 'id'): currow = row['mediaGroup'] id = currow['id'] elif check_key(row, 'mediaItem') and check_key(row['mediaItem'], 'medium') and check_key(row['mediaItem'], 'mediaGroupId'): currow = row['mediaItem'] id = currow['mediaGroupId'] else: continue if not check_key(currow, 'title'): continue context.append((_.REMOVE_FROM_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=remove_from_watchlist, id=id)), )) if check_key(currow, 'isReplayTv') and currow['isReplayTv'] == "false": if settings.getBool('showMoviesSeries') == False: continue type = 'vod' else: type = 'program' mediatype = '' duration = '' description = '' program_image_large = '' playable = False path = '' if check_key(currow, 'description'): description = currow['description'] if check_key(currow, 'images'): program_image_large = get_image("boxart", currow['images']) if currow['medium'] == 'TV': if not check_key(currow, 'seriesLinks'): path = plugin.url_for(func_or_url=watchlist_listing, label=currow['title'], description=description, image=program_image_large, id=id, search=False) else: path = plugin.url_for(func_or_url=vod_series, label=currow['title'], description=description, image=program_image_large, seasons=json.dumps(currow['seriesLinks'])) elif currow['medium'] == 'Movie': if check_key(currow, 'duration'): duration = int(currow['duration']) elif check_key(currow, 'startTime') and check_key(currow, 'endTime'): duration = int(int(currow['endTime']) - int(currow['startTime'])) // 1000 else: duration = 0 path = plugin.url_for(func_or_url=play_video, type=type, id=currow['id'], duration=duration, _is_live=False) playable = True mediatype = 'video' items.append(plugin.Item( label = currow['title'], info = { 'plot': description, 'duration': duration, 'mediatype': mediatype, }, art = {'thumb': program_image_large}, path = path, playable = playable, context = context )) return items