def vod_season(label, title, id, **kwargs): folder = plugin.Folder(title=label) items = [] season = api.vod_season(id) for episode in season: items.append( plugin.Item( label=episode['episodeNumber'] + " - " + episode['title'], info={ 'plot': episode['desc'], 'duration': episode['duration'], 'mediatype': 'video', }, art={ 'thumb': "{image_url}/vod/{image}/1920x1080.jpg?blurred=false". format(image_url=CONST_IMAGE_URL, image=episode['image']), 'fanart': "{image_url}/vod/{image}/1920x1080.jpg?blurred=false". format(image_url=CONST_IMAGE_URL, image=episode['image']) }, path=plugin.url_for(func_or_url=play_video, type='vod', channel=None, id=episode['id'], title=title), playable=True, )) folder.add_items(items) return folder
def vod_series(label, description, image, id, **kwargs): folder = plugin.Folder(title=label) items = [] seasons = api.vod_seasons(id) title = label for season in seasons: label = _.SEASON + " " + unicode(season['seriesNumber']) items.append( plugin.Item( label=label, info={'plot': season['desc']}, art={ 'thumb': "{image_url}/vod/{image}/1920x1080.jpg?blurred=false". format(image_url=CONST_IMAGE_URL, image=season['image']), 'fanart': "{image_url}/vod/{image}/1920x1080.jpg?blurred=false". format(image_url=CONST_IMAGE_URL, image=season['image']) }, path=plugin.url_for(func_or_url=vod_season, label=label, title=title, id=season['id']), )) folder.add_items(items) return folder
def vod_series(label, description, image, id, **kwargs): folder = plugin.Folder(title=label) items = [] seasons = api.vod_seasons(id) title = label for season in seasons: label = _.SEASON + " " + unicode(season['seriesNumber']) items.append(plugin.Item( label = label, info = {'plot': season['desc']}, art = { 'thumb': season['image'], 'fanart': season['image'] }, path = plugin.url_for(func_or_url=vod_season, label=label, title=title, id=season['id']), )) folder.add_items(items) return folder
def vod_season(label, title, id, **kwargs): folder = plugin.Folder(title=label) items = [] season = api.vod_season(id) for episode in season: items.append(plugin.Item( label = episode['episodeNumber'] + " - " + episode['title'], info = { 'plot': episode['desc'], 'duration': episode['duration'], 'mediatype': 'video', }, art = { 'thumb': episode['image'], 'fanart': episode['image'] }, path = plugin.url_for(func_or_url=play_video, type='vod', channel=episode['media_id'], id=episode['id'], title=title), playable = True, )) folder.add_items(items) return folder
def process_replaytv_list(data, start=0): start = int(start) items = [] count = 0 item_count = 0 time_now = int((datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds()) for row in sorted(data): currow = data[row] if item_count == 51: break if count < start: count += 1 continue count += 1 if not check_key(currow, 'orig') or not check_key(currow, 'ids'): continue if check_key(currow, 'a') and check_key(currow, 'e') and (time_now < int(currow['a']) or time_now > int(currow['e'])): continue label = currow['orig'] items.append(plugin.Item( label = label, path = plugin.url_for(func_or_url=replaytv_item, ids=json.dumps(currow['ids']), label=label, start=0), )) item_count += 1 return {'items': items, 'count': count}
def vod_season(label, id, **kwargs): folder = plugin.Folder(title=label) items = [] season = api.vod_season(id) for episode in season: items.append( plugin.Item( label=episode['episodeNumber'] + " - " + episode['title'], info={ 'plot': episode['desc'], 'duration': episode['duration'], 'mediatype': 'video', }, art={ 'thumb': "{image_url}/vod/{image}/{img_size}.jpg?blurred=false". format(image_url=CONST_IMAGE_URL, image=episode['image'], img_size=settings.get(key='_img_size')) }, path=plugin.url_for(func_or_url=play_video, type='vod', id=episode['id'], asset_id=episode['assetid'], duration=episode['duration'], _is_live=False), playable=True, )) folder.add_items(items) return folder
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 process_replaytv_search(data, start=0, search=None): start = int(start) items = [] count = 0 item_count = 0 time_now = int((datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds()) for row in data: letter_row = data[row] for row2 in letter_row: currow = data[row][row2] if item_count == 51: break if count < start: count += 1 continue count += 1 if not check_key(currow, 'orig') or not check_key(currow, 'ids'): continue if check_key(currow, 'a') and check_key( currow, 'e') and (time_now < int(currow['a']) or time_now > int(currow['e'])): continue label = currow['orig'] + ' (ReplayTV)' fuzz_set = fuzz.token_set_ratio(label, search) fuzz_partial = fuzz.partial_ratio(label, search) fuzz_sort = fuzz.token_sort_ratio(label, search) if (fuzz_set + fuzz_partial + fuzz_sort) > 160: items.append( plugin.Item( label=label, properties={ "fuzz_set": fuzz_set, "fuzz_sort": fuzz_sort, "fuzz_partial": fuzz_partial, "fuzz_total": fuzz_set + fuzz_partial + fuzz_sort }, path=plugin.url_for(func_or_url=replaytv_item, ids=json.dumps(currow['ids']), label=label, start=0), )) item_count += 1 return {'items': items, 'count': count}
def renew_token(id=None, type=None, locator=None, **kwargs): api.get_play_token(locator=locator) id = id.replace("/manifest.mpd", "/") id = id.replace("/Manifest?device=Orion-Replay-DASH", "/") listitem = plugin.Item( path = id, ) newItem = listitem.get_li() xbmcplugin.addDirectoryItem(ADDON_HANDLE, id, newItem) xbmcplugin.endOfDirectory(ADDON_HANDLE, cacheToDisc=False) time.sleep(0.1)
def play_video(type=None, channel=None, id=None, catchup=None, duration=0, **kwargs): properties = {} if not type and 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' playdata = api.play_url(type=type, channel=channel, id=id) if not playdata or not check_key(playdata, 'path') or not check_key( playdata, 'token'): return False CDMHEADERS = CONST_BASE_HEADERS CDMHEADERS['User-Agent'] = settings.get(key='_user_agent') if type == 'channel': playdata['path'] = playdata['path'].split("&", 1)[0] else: playdata['path'] = playdata['path'].split("&min_bitrate", 1)[0] if check_key(playdata, 'license'): item_inputstream = inputstream.Widevine( license_key=playdata['license'], ) else: item_inputstream = inputstream.MPD() settings.setInt(key='_stream_duration', value=duration) listitem = plugin.Item( properties=properties, path=playdata['path'], headers=CDMHEADERS, inputstream=item_inputstream, ) return listitem
def play_video(type=None, channel=None, id=None, catchup=None, duration=0, **kwargs): properties = {} if not type and 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' playdata = api.play_url(type=type, channel=channel, id=id) if not playdata or not check_key(playdata, 'path') or not check_key( playdata, 'token') or not check_key(playdata, 'sessionid'): return False CDMHEADERS = { 'User-Agent': settings.get(key='_user_agent'), 'Authorization': 'Bearer ' + playdata['token'], } settings.setInt(key='_stream_duration', value=duration) listitem = plugin.Item( properties=properties, path=playdata['path'], headers=CDMHEADERS, inputstream=inputstream.Widevine(license_key=playdata['license'], ), ) return listitem
def vod_series(label, description, image, seasons, mediagroupid=None, **kwargs): folder = plugin.Folder(title=label) items = [] context = [] seasons = json.loads(seasons) 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')), )) for season in seasons: items.append(plugin.Item( label = _.SEASON + " " + unicode(season['seriesNumber']), info = {'plot': description}, art = {'thumb': image}, path = plugin.url_for(func_or_url=vod_season, label=label, id=season['id'], mediagroupid=mediagroupid), context = context, )) folder.add_items(items) return folder
def play_video(type=None, channel=None, id=None, from_beginning=0, **kwargs): from_beginning = int(from_beginning) profile_settings = load_profile(profile_id=1) properties = {} if not type and not len(unicode(type)) > 0: return False if type == 'program': properties['seekTime'] = 1 playdata = api.play_url(type=type, channel=channel, id=id, from_beginning=from_beginning) if not playdata or not check_key(playdata, 'path'): return False CDMHEADERS = { 'User-Agent': profile_settings['user_agent'], 'X_CSRFToken': profile_settings['csrf_token'], 'Cookie': playdata['license']['cookie'], } if check_key(playdata, 'license') and check_key(playdata['license'], 'triggers') and check_key(playdata['license']['triggers'][0], 'licenseURL'): item_inputstream = inputstream.Widevine( license_key = playdata['license']['triggers'][0]['licenseURL'], ) if check_key(playdata['license']['triggers'][0], 'customData'): CDMHEADERS['AcquireLicense.CustomData'] = playdata['license']['triggers'][0]['customData'] CDMHEADERS['CADeviceType'] = 'Widevine OTT client' else: item_inputstream = inputstream.MPD() itemlabel = '' label2 = '' description = '' program_image = '' program_image_large = '' duration = 0 cast = [] director = [] writer = [] credits = [] if check_key(playdata['info'], 'startTime') and check_key(playdata['info'], 'endTime'): startT = datetime.datetime.fromtimestamp((int(playdata['info']['startTime']) / 1000)) startT = convert_datetime_timezone(startT, "UTC", "UTC") endT = datetime.datetime.fromtimestamp((int(playdata['info']['endTime']) / 1000)) endT = convert_datetime_timezone(endT, "UTC", "UTC") duration = int((endT - startT).total_seconds()) if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': itemlabel = '{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: itemlabel = startT.strftime("%A %d %B %Y %H:%M ").capitalize() itemlabel += " - " if check_key(playdata['info'], 'name'): itemlabel += playdata['info']['name'] label2 = playdata['info']['name'] if type == 'channel': if from_beginning == 1: properties['seekTime'] = 1 elif settings.getBool(key='ask_start_from_beginning'): if gui.yes_no(message=_.START_FROM_BEGINNING, heading=label2): properties['seekTime'] = 1 if check_key(playdata['info'], 'introduce'): description = playdata['info']['introduce'] if check_key(playdata['info'], 'picture'): program_image = playdata['info']['picture']['posters'][0] program_image_large = playdata['info']['picture']['posters'][0] query = "SELECT name FROM `channels` WHERE id='{channel}'".format(channel=channel) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) if data: for row in data: label2 += " - " + row['name'] query = "UPDATE `vars` SET `stream_duration`='{stream_duration}' WHERE profile_id={profile_id}".format(stream_duration=duration, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) listitem = plugin.Item( label = itemlabel, label2 = label2, art = { 'thumb': program_image, 'fanart': program_image_large }, info = { 'credits': credits, 'cast': cast, 'writer': writer, 'director': director, 'plot': description, 'duration': duration, 'mediatype': 'video', }, properties = properties, path = playdata['path'], headers = CDMHEADERS, inputstream = item_inputstream, ) return listitem
def process_vod_content(data, start=0, search=None, type=None): subscription = load_file(file='vod_subscription.json', isJSON=True) start = int(start) items = [] count = 0 item_count = 0 if sys.version_info >= (3, 0): subscription = list(subscription) for row in data: currow = row if item_count == 50: break if count < start: count += 1 continue count += 1 if not check_key(currow, 'id') or not check_key(currow, 'title'): continue id = currow['id'] label = currow['title'] if not int(id) in subscription: continue if search: fuzz_set = fuzz.token_set_ratio(label, search) fuzz_partial = fuzz.partial_ratio(label, search) fuzz_sort = fuzz.token_sort_ratio(label, search) if (fuzz_set + fuzz_partial + fuzz_sort) > 160: properties = { "fuzz_set": fuzz.token_set_ratio(label, search), "fuzz_sort": fuzz.token_sort_ratio(label, search), "fuzz_partial": fuzz.partial_ratio(label, search), "fuzz_total": fuzz.token_set_ratio(label, search) + fuzz.partial_ratio(label, search) + fuzz.token_sort_ratio(label, search) } label = label + " (" + type + ")" else: continue description = '' program_image_large = '' duration = 0 properties = [] if check_key(currow, 'desc'): description = currow['desc'] if check_key(currow, 'duration'): duration = int(currow['duration']) if check_key(currow, 'image'): program_image_large = currow['image'] if not check_key(currow, 'type'): continue if currow['type'] == "show": path = plugin.url_for(func_or_url=vod_series, label=label, description=description, image=program_image_large, id=id) info = {'plot': description} playable = False else: path = plugin.url_for(func_or_url=play_video, type='vod', id=id, duration=duration, _is_live=False) info = { 'plot': description, 'duration': duration, 'mediatype': 'video' } playable = True items.append( plugin.Item( label=label, properties=properties, info=info, art={'thumb': program_image_large}, path=path, playable=playable, )) item_count += 1 return {'items': items, 'count': count}
def process_vod_content(data, start=0, series=0, search=None, type=None): start = int(start) series = int(series) items = [] count = 0 item_count = 0 for row in data: context = [] currow = row if item_count == 50: break if count < start: count += 1 continue count += 1 if not check_key(currow, 'id') or not check_key(currow, 'title'): continue id = currow['id'] label = currow['title'] if search: fuzz_set = fuzz.token_set_ratio(label,search) fuzz_partial = fuzz.partial_ratio(label,search) fuzz_sort = fuzz.token_sort_ratio(label,search) if (fuzz_set + fuzz_partial + fuzz_sort) > 160: properties = {"fuzz_set": fuzz.token_set_ratio(label,search), "fuzz_sort": fuzz.token_sort_ratio(label,search), "fuzz_partial": fuzz.partial_ratio(label,search), "fuzz_total": fuzz.token_set_ratio(label,search) + fuzz.partial_ratio(label,search) + fuzz.token_sort_ratio(label,search)} label = label + " (" + type + ")" else: continue description = '' program_image_large = '' duration = 0 properties = [] if check_key(currow, 'desc'): description = currow['desc'] if check_key(currow, 'duration'): duration = int(currow['duration']) if check_key(currow, 'image'): program_image_large = currow['image'] if not check_key(currow, 'type'): continue if currow['type'] == "show": if check_key(currow, 'seasons') and series != 2: path = plugin.url_for(func_or_url=vod_series, label=label, description=description, image=program_image_large, seasons=json.dumps(currow['seasons']), mediagroupid=id) info = {'plot': description} playable = False context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=id, type='group')), )) else: continue else: if series != 1: path = plugin.url_for(func_or_url=play_video, type='vod', id=id, duration=duration, _is_live=False) info = {'plot': description, 'duration': duration, 'mediatype': 'video'} playable = True context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=id, type='group')), )) else: continue items.append(plugin.Item( label = label, properties = properties, info = info, art = {'thumb': program_image_large}, path = path, playable = playable, context = context )) item_count += 1 return {'items': items, 'count': count}
def process_vod_content(data, start=0, search=None, type=None): profile_settings = load_profile(profile_id=1) subscription = load_file(file='vod_subscription.json', isJSON=True) start = int(start) items = [] count = start item_count = 0 if subscription and sys.version_info >= (3, 0): subscription = list(subscription) query = "SELECT * FROM `{table}` ORDER BY title ASC LIMIT 999999 OFFSET {start}".format(table=data, start=start) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) if not data: return {'items': items, 'count': item_count, 'count2': count, 'total': 0} for row in data: if item_count == 50: break count += 1 id = row['id'] label = row['title'] if subscription and not int(id) in subscription: continue if search: fuzz_set = fuzz.token_set_ratio(label,search) fuzz_partial = fuzz.partial_ratio(label,search) fuzz_sort = fuzz.token_sort_ratio(label,search) if (fuzz_set + fuzz_partial + fuzz_sort) > 160: properties = {"fuzz_set": fuzz.token_set_ratio(label,search), "fuzz_sort": fuzz.token_sort_ratio(label,search), "fuzz_partial": fuzz.partial_ratio(label,search), "fuzz_total": fuzz.token_set_ratio(label,search) + fuzz.partial_ratio(label,search) + fuzz.token_sort_ratio(label,search)} label = label + " (" + type + ")" else: continue item_count += 1 properties = [] description = row['description'] duration = 0 if row['duration'] and len(unicode(row['duration'])) > 0: duration = int(row['duration']) program_image = row['icon'] program_image_large = row['icon'] if row['type'] == "show": path = plugin.url_for(func_or_url=vod_series, label=label, description=description, image=program_image_large, id=id) info = {'plot': description} playable = False else: path = plugin.url_for(func_or_url=play_video, type='vod', channel=None, id=id) info = {'plot': description, 'duration': duration, 'mediatype': 'video'} playable = True items.append(plugin.Item( label = label, properties = properties, info = info, art = { 'thumb': program_image, 'fanart': program_image_large }, path = path, playable = playable, )) if item_count == 50: total = int(len(data) + count) else: total = count returnar = {'items': items, 'count': item_count, 'count2': count, 'total': total} return returnar
def play_video(type=None, channel=None, id=None, title=None, from_beginning=0, **kwargs): from_beginning = int(from_beginning) profile_settings = load_profile(profile_id=1) properties = {} if not type and not len(unicode(type)) > 0: return False if type == 'program': properties['seekTime'] = 1 playdata = api.play_url(type=type, channel=channel, id=id, from_beginning=from_beginning) if not playdata or not check_key(playdata, 'path'): return False CDMHEADERS = CONST_BASE_HEADERS CDMHEADERS['User-Agent'] = profile_settings['user_agent'] if check_key(playdata, 'license'): item_inputstream = inputstream.Widevine( license_key=playdata['license'], ) else: item_inputstream = inputstream.MPD() itemlabel = '' label2 = '' description = '' program_image = '' program_image_large = '' duration = 0 cast = [] director = [] writer = [] genres = [] if playdata['info']: if check_key(playdata['info'], 'params'): if check_key(playdata['info']['params'], 'start') and check_key( playdata['info']['params'], 'end'): startT = datetime.datetime.fromtimestamp( time.mktime( time.strptime(playdata['info']['params']['start'], "%Y-%m-%dT%H:%M:%SZ"))) endT = datetime.datetime.fromtimestamp( time.mktime( time.strptime(playdata['info']['params']['end'], "%Y-%m-%dT%H:%M:%SZ"))) duration = int((endT - startT).total_seconds()) if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': itemlabel = '{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: itemlabel = startT.strftime( "%A %d %B %Y %H:%M ").capitalize() itemlabel += " - " if title: itemlabel += title + ' - ' if check_key(playdata['info'], 'title'): itemlabel += playdata['info']['title'] if check_key(playdata['info'], 'desc'): description = playdata['info']['desc'] if check_key(playdata['info'], 'images') and check_key( playdata['info']['images'][0], 'url'): program_image = playdata['info']['images'][0]['url'] program_image_large = playdata['info']['images'][0]['url'] if check_key(playdata['info'], 'params'): if check_key(playdata['info']['params'], 'credits'): for castmember in playdata['info']['params']['credits']: if castmember['role'] == "Actor": cast.append(castmember['person']) elif castmember['role'] == "Director": director.append(castmember['person']) elif castmember['role'] == "Writer": writer.append(castmember['person']) if check_key(playdata['info']['params'], 'genres'): for genre in playdata['info']['params']['genres']: genres.append(genre['title']) if check_key(playdata['info']['params'], 'duration'): duration = playdata['info']['params']['duration'] epcode = '' if check_key(playdata['info']['params'], 'seriesSeason'): epcode += 'S' + unicode( playdata['info']['params']['seriesSeason']) if check_key(playdata['info']['params'], 'seriesEpisode'): epcode += 'E' + unicode( playdata['info']['params']['seriesEpisode']) if check_key(playdata['info']['params'], 'episodeTitle'): label2 = playdata['info']['params']['episodeTitle'] if len(epcode) > 0: label2 += " (" + epcode + ")" elif check_key(playdata['info'], 'title'): label2 = playdata['info']['title'] if check_key(playdata['info']['params'], 'channelId'): query = "SELECT name FROM `channels` WHERE id='{channel}'".format( channel=playdata['info']['params']['channelId']) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) if data: for row in data: label2 += " - " + row['name'] query = "UPDATE `vars` SET `stream_duration`='{stream_duration}' WHERE profile_id={profile_id}".format( stream_duration=duration, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) listitem = plugin.Item( label=itemlabel, label2=label2, art={ 'thumb': program_image, 'fanart': program_image_large }, info={ 'cast': cast, 'writer': writer, 'director': director, 'genre': genres, 'plot': description, 'duration': duration, 'mediatype': 'video', }, properties=properties, path=playdata['path'], headers=CDMHEADERS, inputstream=item_inputstream, ) return listitem
def process_replaytv_content(station, day=0, start=0): profile_settings = load_profile(profile_id=1) day = int(day) start = int(start) curdate = datetime.date.today() - datetime.timedelta(days=day) startDate = convert_datetime_timezone(datetime.datetime(curdate.year, curdate.month, curdate.day, 0, 0, 0), "Europe/Amsterdam", "UTC") endDate = convert_datetime_timezone(datetime.datetime(curdate.year, curdate.month, curdate.day, 23, 59, 59), "Europe/Amsterdam", "UTC") startTimeStamp = int((startDate - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) endTimeStamp = int((endDate - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) query = "SELECT * FROM `epg` WHERE channel='{channel}' AND start >= {startTime} AND start <= {endTime} LIMIT 51 OFFSET {start}".format(channel=station, startTime=startTimeStamp, endTime=endTimeStamp, start=start) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) items = [] item_count = 0 if not data: return {'items': items, 'count': item_count, 'total': 0} for row in data: if item_count == 51: break item_count += 1 startT = datetime.datetime.fromtimestamp(row['start']) startT = convert_datetime_timezone(startT, "Europe/Amsterdam", "Europe/Amsterdam") endT = datetime.datetime.fromtimestamp(row['end']) endT = convert_datetime_timezone(endT, "Europe/Amsterdam", "Europe/Amsterdam") if endT < (datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7)): continue label = startT.strftime("%H:%M") + " - " + row['title'] description = row['description'] duration = int((endT - startT).total_seconds()) program_image = row['icon'] program_image_large = row['icon'] items.append(plugin.Item( label = label, info = { 'plot': description, 'duration': duration, 'mediatype': 'video', }, art = { 'thumb': program_image, 'fanart': program_image_large }, path = plugin.url_for(func_or_url=play_video, type='program', channel=row['channel'], id=row['program_id']), playable = True, )) returnar = {'items': items, 'count': item_count, 'total': len(data)} return returnar
def process_replaytv_list_content(data, ids, start=0): start = int(start) items = [] count = 0 item_count = 0 ids = json.loads(ids) totalrows = len(ids) for id in ids: currow = data[id] if item_count == 51: break if count < start: count += 1 continue count += 1 if not check_key(currow, 's') or not check_key( currow, 't') or not check_key(currow, 'c') or not check_key( currow, 'e'): continue startsplit = unicode(currow['s'].split(' ', 1)[0]) endsplit = unicode(currow['e'].split(' ', 1)[0]) if not startsplit.isdigit() or not len( startsplit) == 14 or not endsplit.isdigit() or not len( endsplit) == 14: continue startT = datetime.datetime.fromtimestamp( time.mktime(time.strptime(startsplit, "%Y%m%d%H%M%S"))) startT = convert_datetime_timezone(startT, "UTC", "Europe/Amsterdam") endT = datetime.datetime.fromtimestamp( time.mktime(time.strptime(endsplit, "%Y%m%d%H%M%S"))) endT = convert_datetime_timezone(endT, "UTC", "Europe/Amsterdam") if startT > datetime.datetime.now( pytz.timezone("Europe/Amsterdam")) or endT < ( datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7)): continue if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': itemlabel = '{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: itemlabel = startT.strftime("%A %d %B %Y %H:%M ").capitalize() itemlabel += currow['t'] + " (" + currow['cn'] + ")" description = '' program_image_large = '' if check_key(currow, 'desc'): description = currow['desc'] duration = int((endT - startT).total_seconds()) if check_key(currow, 'i'): program_image_large = currow['i'] items.append( plugin.Item( label=itemlabel, info={ 'plot': description, 'duration': duration, 'mediatype': 'video', }, art={'thumb': program_image_large}, path=plugin.url_for(func_or_url=play_video, type='program', id=id, duration=duration, _is_live=False), playable=True, )) item_count = item_count + 1 return {'items': items, 'totalrows': totalrows, 'count': count}
def process_replaytv_content(data, day=0, start=0): day = int(day) start = int(start) curdate = datetime.date.today() - datetime.timedelta(days=day) startDate = convert_datetime_timezone( datetime.datetime(curdate.year, curdate.month, curdate.day, 0, 0, 0), "Europe/Amsterdam", "UTC") endDate = convert_datetime_timezone( datetime.datetime(curdate.year, curdate.month, curdate.day, 23, 59, 59), "Europe/Amsterdam", "UTC") startTime = startDate.strftime("%Y%m%d%H%M%S") endTime = endDate.strftime("%Y%m%d%H%M%S") items = [] count = 0 item_count = 0 for row in data: currow = data[row] if item_count == 51: break if count < start: count += 1 continue count += 1 if not check_key(currow, 's') or not check_key( currow, 't') or not check_key(currow, 'c') or not check_key( currow, 'e'): continue startsplit = unicode(currow['s'].split(' ', 1)[0]) endsplit = unicode(currow['e'].split(' ', 1)[0]) if not startsplit.isdigit() or not len( startsplit ) == 14 or startsplit < startTime or not endsplit.isdigit() or not len( endsplit) == 14 or startsplit >= endTime: continue startT = datetime.datetime.fromtimestamp( time.mktime(time.strptime(startsplit, "%Y%m%d%H%M%S"))) startT = convert_datetime_timezone(startT, "UTC", "Europe/Amsterdam") endT = datetime.datetime.fromtimestamp( time.mktime(time.strptime(endsplit, "%Y%m%d%H%M%S"))) endT = convert_datetime_timezone(endT, "UTC", "Europe/Amsterdam") if endT < (datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7)): continue label = startT.strftime("%H:%M") + " - " + currow['t'] description = '' program_image_large = '' if check_key(currow, 'desc'): description = currow['desc'] duration = int((endT - startT).total_seconds()) if check_key(currow, 'i'): program_image_large = currow['i'] 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='program', id=row, duration=duration, _is_live=False), playable=True, )) item_count += 1 return {'items': items, 'count': count}
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 process_replaytv_list(character, start=0): profile_settings = load_profile(profile_id=1) now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7) nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) channels_ar2 = {} if data: for row in data: channels_ar2[unicode(row['id'])] = row['name'] prefs = load_prefs(profile_id=1) channels_ar = [] if prefs: for row in prefs: currow = prefs[row] if '18+' in channels_ar2[unicode(currow['id'])]: continue if currow['replay'] == 1: channels_ar.append(row) channels = "', '".join(map(str, channels_ar)) query = "SELECT idtitle, title, icon FROM `epg` WHERE first='{first}' AND start < {nowstamp} AND end > {sevendaysstamp} AND channel IN ('{channels}') GROUP BY idtitle LIMIT 51 OFFSET {start}".format(first=character, nowstamp=nowstamp, sevendaysstamp=sevendaysstamp, channels=channels, start=start) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) start = int(start) items = [] item_count = 0 if not data: return {'items': items, 'count': item_count, 'total': 0} for row in data: if item_count == 51: break item_count += 1 label = row['title'] idtitle = row['idtitle'] items.append(plugin.Item( label = label, art = { 'thumb': row['icon'], 'fanart': row['icon'] }, path = plugin.url_for(func_or_url=replaytv_item, label=label, idtitle=idtitle, start=0), )) returnar = {'items': items, 'count': item_count, 'total': len(data)} return returnar
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_replaytv_search(search): profile_settings = load_profile(profile_id=1) now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7) nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) channels_ar2 = {} if data: for row in data: channels_ar2[unicode(row['id'])] = row['name'] prefs = load_prefs(profile_id=1) channels_ar = [] if prefs: for row in prefs: currow = prefs[row] if '18+' in channels_ar2[unicode(currow['id'])]: continue if currow['replay'] == 1: channels_ar.append(row) channels = "', '".join(map(str, channels_ar)) query = "SELECT idtitle, title, icon FROM `epg` WHERE start < {nowstamp} AND end > {sevendaysstamp} AND channel IN ('{channels}') GROUP BY idtitle".format(nowstamp=nowstamp, sevendaysstamp=sevendaysstamp, channels=channels) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) items = [] if not data: return {'items': items} for row in data: fuzz_set = fuzz.token_set_ratio(row['title'], search) fuzz_partial = fuzz.partial_ratio(row['title'], search) fuzz_sort = fuzz.token_sort_ratio(row['title'], search) if (fuzz_set + fuzz_partial + fuzz_sort) > 160: label = row['title'] + ' (ReplayTV)' idtitle = row['idtitle'] items.append(plugin.Item( label = label, art = { 'thumb': row['icon'], 'fanart': row['icon'] }, properties = {"fuzz_set": fuzz_set, "fuzz_sort": fuzz_sort, "fuzz_partial": fuzz_partial, "fuzz_total": fuzz_set + fuzz_partial + fuzz_sort}, path = plugin.url_for(func_or_url=replaytv_item, label=label, idtitle=idtitle, start=0), )) returnar = {'items': items} return returnar
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
def process_replaytv_list_content(label, idtitle, start=0): profile_settings = load_profile(profile_id=1) start = int(start) now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7) nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) channels_ar2 = {} if data: for row in data: channels_ar2[unicode(row['id'])] = row['name'] prefs = load_prefs(profile_id=1) channels_ar = [] if prefs: for row in prefs: currow = prefs[row] if '18+' in channels_ar2[unicode(currow['id'])]: continue if currow['replay'] == 1: channels_ar.append(row) channels = "', '".join(map(str, channels_ar)) query = "SELECT * FROM `epg` WHERE idtitle='{idtitle}' AND start < {nowstamp} AND end > {sevendaysstamp} AND channel IN ('{channels}') LIMIT 51 OFFSET {start}".format(idtitle=idtitle, nowstamp=nowstamp, sevendaysstamp=sevendaysstamp, channels=channels, start=start) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) items = [] item_count = 0 if not data: return {'items': items, 'count': item_count, 'total': 0} for row in data: if item_count == 51: break item_count += 1 startT = datetime.datetime.fromtimestamp(row['start']) startT = convert_datetime_timezone(startT, "Europe/Amsterdam", "Europe/Amsterdam") endT = datetime.datetime.fromtimestamp(row['end']) endT = convert_datetime_timezone(endT, "Europe/Amsterdam", "Europe/Amsterdam") if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': itemlabel = '{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: itemlabel = startT.strftime("%A %d %B %Y %H:%M ").capitalize() itemlabel += row['title'] + " (" + channels_ar2[unicode(row['channel'])] + ")" description = row['description'] duration = int((endT - startT).total_seconds()) program_image = row['icon'] program_image_large = row['icon'] items.append(plugin.Item( label = itemlabel, info = { 'plot': description, 'duration': duration, 'mediatype': 'video', }, art = { 'thumb': program_image, 'fanart': program_image_large }, path = plugin.url_for(func_or_url=play_video, type='program', channel=row['channel'], id=row['program_id'], duration=duration), playable = True, )) returnar = {'items': items, 'count': item_count, 'total': len(data)} return returnar
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