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 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 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_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_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