def replaytv_by_day(label='', image='', description='', station='', **kwargs): folder = plugin.Folder(title=label) for x in range(0, 7): curdate = datetime.date.today() - datetime.timedelta(days=x) itemlabel = '' if x == 0: itemlabel = _.TODAY + " - " elif x == 1: itemlabel = _.YESTERDAY + " - " if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': itemlabel += date_to_nl_dag(curdate=curdate) + curdate.strftime(" %d ") + date_to_nl_maand(curdate=curdate) + curdate.strftime(" %Y") else: itemlabel += curdate.strftime("%A %d %B %Y").capitalize() folder.add_item( label = itemlabel, info = {'plot': description}, art = {'thumb': image}, path = plugin.url_for(func_or_url=replaytv_content, label=itemlabel, day=x, station=station), ) 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_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, 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 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_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_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