def __get_game_data(game, meta, offline): utc_timezone = control.get_current_brasilia_utc_offset() parsed_date = util.strptime_workaround(game['datetime'], format='%Y-%m-%dT%H:%M:%S') + datetime.timedelta(hours=(-utc_timezone)) date_string = kodi_util.format_datetimeshort(parsed_date) # plot = game['championship'] + u': ' + game['home']['name'] + u' x ' + game['away']['name'] + u' (' + game['stadium'] + u')' + u'. ' + date_string label = game['home']['name'] + u' x ' + game['away']['name'] media_desc = '\n' + game['medias'][0]['description'] if 'medias' in game and game['medias'] and len(game['medias']) > 0 else '' plot = game['phase'] + u' d' + get_artigo(game['championship']) + u' ' + game['championship'] + u'. Disputado n' + get_artigo(game['stadium']) + u' ' + game['stadium'] + u'. ' + date_string + media_desc name = ((date_string + u' - ') if offline else u'') + label if not control.isFTV else label meta.update({ 'name': name, 'label2': label, 'playable': 'true' if 'medias' in game and game['medias'] and len(game['medias']) > 0 else 'false', 'plot': game['stadium'] if control.isFTV else plot, 'plotoutline': date_string, 'id': game['medias'][0]['id'], 'logo': game['home']['logo_60x60_url'], 'logo2': game['away']['logo_60x60_url'], 'initials1': game['home']['abbreviation'], 'initials2': game['away']['abbreviation'], 'isFolder': 'false', 'mediatype': 'episode', 'tvshowtitle': game['home']['abbreviation'] + u' x ' + game['away']['abbreviation'], 'title': game['championship'], 'brplayprovider': 'globosat', 'gamedetails': None, 'livefeed': game['status'] == 'live', }) return meta
def get_live_channels(): utc_timezone = control.get_current_brasilia_utc_offset() today = datetime.datetime.utcnow() + datetime.timedelta(hours=(utc_timezone)) today_string = datetime.datetime.strftime(today, '%Y-%m-%d') url = 'http://www.futuraplay.org/api/programacao/%s/' % today_string response = cache.get(client.request, 1, url) programs = [slot for slot in response['exibicoes'] if util.strptime_workaround(slot['dia'], '%d/%m/%Y %H:%M') < today] program = programs[-1] program_datetime = util.strptime_workaround(program['dia'], '%d/%m/%Y %H:%M') - datetime.timedelta(hours=(utc_timezone)) start_time = util.strptime_workaround(program['hora'], '%H:%M') - datetime.timedelta(hours=(utc_timezone)) end_time = util.strptime_workaround(program['fim'], '%H:%M:%S') - datetime.timedelta(hours=(utc_timezone)) return [{ 'slug': 'futura', 'name': '[B]Futura[/B] ' + '[I] - ' + program['subtitulo'] + '[/I]', 'title': program['titulo'] if program['titulo'] != program['titulo_serie'] else None, "subtitle": program['subtitulo'] if program['subtitulo'] != program['titulo'] else None, "plot": program['sinopse'], 'tvshowtitle': program['titulo_serie'], 'sorttitle': 'Futura', 'clearlogo': CLEAR_LOGO_COLOR, 'fanart': FUTURA_FANART, 'thumb': FUTURA_THUMB + '?v=' + str(int(time.time())), 'studio': 'Futura', 'playable': 'true', 'id': get_live_id(), 'channel_id': 1985, 'live': False, # use vod player "mediatype": 'episode', 'livefeed': 'true' if program['ao_vivo'] is True or program['ao_vivo'] == 'true' else 'false', 'logo': CLEAR_LOGO_COLOR, 'duration': int(program['duracao']) * 60, "plotoutline": datetime.datetime.strftime(start_time, '%H:%M') + ' - ' + datetime.datetime.strftime(end_time, '%H:%M'), "dateadded": datetime.datetime.strftime(program_datetime, '%Y-%m-%d %H:%M:%S'), 'brplayprovider': 'globoplay', 'anonymous': True }]
def get_premiere_games(): headers = {'Accept-Encoding': 'gzip'} page = 1 result = requests.get(PREMIERE_NEXT_MATCHES_JSON + str(page), headers=headers).json() next_games = result['results'] pages = result['pagination']['pages'] if pages > 1: threads = [] for page in range(2, pages + 1): threads.append(workers.Thread(requests.get, PREMIERE_NEXT_MATCHES_JSON + str(page), headers)) [i.start() for i in threads] [i.join() for i in threads] [next_games.extend(i.get_result().json().get('results', []) or []) for i in threads] for game in next_games: utc_timezone = control.get_current_brasilia_utc_offset() parsed_date = util.strptime_workaround(game['datetime'], format='%Y-%m-%dT%H:%M:%S') + datetime.timedelta(hours=(-utc_timezone)) date_string = kodi_util.format_datetimeshort(parsed_date) label = game['home']['name'] + u' x ' + game['away']['name'] medias = game.get('medias', []) or [] media_desc = '\n\n' + '\n\n'.join([u'Transmissão %s\n%s' % (media.get('title'), media.get('description')) for media in medias]) plot = game['phase'] + u' d' + get_artigo(game['championship']) + u' ' + game['championship'] + u'\nDisputado n' + get_artigo(game['stadium']) + u' ' + game['stadium'] + u'. ' + date_string + media_desc name = (date_string + u' - ') + label # thumb = merge_logos(game['home']['logo_60x60_url'], game['away']['logo_60x60_url'], str(game['id']) + '.png') # thumb = PREMIERE_FANART yield { 'label': name, 'plot': plot, 'tvshowtitle': game['championship'], 'IsPlayable': False, 'setCast': [{ 'name': game['home']['name'], 'role': 'Mandante', 'thumbnail': game['home']['logo_60x60_url'], 'order': 0 }, { 'name': game['away']['name'], 'role': 'Visitante', 'thumbnail': game['away']['logo_60x60_url'], 'order': 1 }], 'art': { 'thumb': game['home']['logo_60x60_url'], 'fanart': PREMIERE_FANART } }
def get_simulcast(): url = 'https://sexyhot.globo.com/api/v1/simulcast' simulcast = client.request(url) program_title = simulcast['nowEvent']['title'] program_start = simulcast['nowEvent']['date'] program_stop = simulcast['nextEvent']['date'] program_start_date = util.strptime_workaround(program_start, '%Y-%m-%dT%H:%M:%S-03:00') program_stop_date = util.strptime_workaround(program_stop, '%Y-%m-%dT%H:%M:%S-03:00') utc_timezone = control.get_current_brasilia_utc_offset() duration = util.get_total_seconds(program_stop_date - program_start_date) return { 'program_title': program_title, 'duration_seconds': duration, 'start_date': program_start_date - datetime.timedelta(hours=(utc_timezone)) }
def _get_combate_schedule(self, schedule): globosat_schedule_url = "http://api.simulcast.globosat.tv/combate/?page=%s" headers = { "User-Agent": "GlobosatPlay/142 CFNetwork/811.4.18 Darwin/16.5.0", "Authorization": "Token 59150c4cc6a00f467bf225cf3bf8f44617e27037", "Accept-Encoding": "gzip, deflate" } page = 1 response = client.request(globosat_schedule_url % page, headers=headers) results = response['results'] while response['next'] is not None: page += 1 response = client.request(globosat_schedule_url % page, headers=headers) results += response['results'] for result in results: beginsAt = util.strptime_workaround( result['day'], '%d/%m/%Y %H:%M') + util.get_utc_delta() schedule.append({ "name": result['channel']['title'], "title": result['title'], "description": result['subtitle'], "begins_at": beginsAt.isoformat(), "ends_at": beginsAt + datetime.timedelta(minutes=result['duration']), "id": result['id_midia_live_play'], "program_id": None, "live_poster": None, "thumbnail": result['channel']['url_snapshot'], "thumbnail_hd": result['channel']['url_snapshot'], "fanart": result['thumb_cms'], "color": result['channel']['color'] }) return schedule
def get_transmissions_live_channels_from_json(): transmissions = [] threads = [ workers.Thread(__get_transmissions_page, transmissions, 1), workers.Thread(__get_transmissions_page, transmissions, 2) ] [i.start() for i in threads] [i.join() for i in threads] channels = [] for transmission in transmissions: updated_at = util.strptime_workaround(transmission['updated_at'], '%Y-%m-%dT%H:%M:%SZ') if updated_at > datetime.datetime.utcnow() - datetime.timedelta( hours=24): if transmission['status'] == "ativa": for item in transmission['items']: title = transmission['title'] if item['title'] != str(item['id_globo_videos']): title = title + item['title'] channel = { 'slug': str(item['id_globo_videos']), 'name': title, 'studio': transmission['title'], 'title': title, 'plot': None, 'duration': None, 'sorttitle': title, 'thumb': item['image'], 'logo': None, 'clearlogo': None, 'clearart': None, 'banner': None, 'color': None, 'fanart': None, 'id': item['id_globo_videos'], 'channel_id': transmission['id_channel'], 'brplayprovider': 'globosat', 'playable': 'true', 'livefeed': 'true', # 'dateadded': datetime.datetime.strftime(updated_at, '%Y-%m-%d %H:%M:%S') } channels.append(channel) return channels
def get_premiere_live_24h_channels(): live = [] headers = {'Authorization': GLOBOSAT_API_AUTHORIZATION, 'Accept-Encoding': 'gzip'} live_channels = client.request(PREMIERE_24H_SIMULCAST, headers=headers) studio = 'Premiere Clubes' # control.log("-- PREMIERE CLUBES SIMULCAST: %s" % repr(live_channels)) utc_timezone = control.get_current_brasilia_utc_offset() for channel_data in live_channels: program_date = util.strptime_workaround(channel_data['starts_at'][0:19]) + datetime.timedelta(hours=-utc_timezone) + util.get_utc_delta() if channel_data and 'starts_at' in channel_data and channel_data['starts_at'] is not None else None live_text = ' (' + control.lang(32004) + ')' if channel_data['live'] else '' studio = channel_data['channel']['title'] title = '[B]' + studio + '[/B]' + ('[I] - ' + channel_data['name'] + '[/I]' if channel_data['name'] else '') + live_text live_channel = { 'slug': 'premiere-fc', 'name': title, 'studio': studio, 'title': channel_data['description'], 'tvshowtitle': channel_data['name'], 'sorttitle': studio, 'logo': PREMIERE_LOGO, 'clearlogo': PREMIERE_LOGO, 'fanart': channel_data['image_url'], 'thumb': channel_data['snapshot_url'] + '?v=' + str(int(time.time())), 'playable': 'true', 'plot': channel_data['description'], 'id': int(channel_data['media_globovideos_id']), 'channel_id': int(channel_data['channel']['globovideos_id']), 'duration': int(channel_data['duration'] or 0) / 1000, 'isFolder': 'false', 'live': channel_data['live'], 'livefeed': 'true', 'brplayprovider': 'globosat' } if program_date is not None: live_channel.update({'dateadded': datetime.datetime.strftime(program_date, '%Y-%m-%d %H:%M:%S')}) live.append(live_channel) return live
def __get_simulcast_data(result): utc_timezone = control.get_current_brasilia_utc_offset() live_text = ' (' + control.lang(32004) + ')' if result['live'] else '' program_date = util.strptime_workaround(result['starts_at'][:-6]) + datetime.timedelta(hours=-utc_timezone) + util.get_utc_delta() if not result['starts_at'] is None else datetime.datetime.now() # program_local_date_string = datetime.datetime.strftime(program_date, '%d/%m/%Y %H:%M') # duration_str = (' - ' + str(result['duration'] or 0) + ' minutos') if (result['duration'] or 0) > 0 else '' name = "[B]" + result['channel']['title'] + "[/B]" + ('[I] - ' + (result['name'] or '') + '[/I]' if result['name'] else '') + live_text return { 'slug': result['channel']['title'].lower(), 'studio': result['channel']['title'], 'name': name, 'title': result['name'], 'tvshowtitle': result['name'] if result['name'] else None, 'sorttitle': result['channel']['title'], 'logo': result['channel']['default_logo'], 'color': result['channel']['color'], 'fanart': result['image_url'], 'thumb': result['snapshot_url'] + '?v=' + str(int(time.time())), 'live': result['live'], 'playable': 'true', 'plot': result['description'] or '' if not control.isFTV else ' ', #(result['title'] or '') + ' - ' + (result['subtitle'] or ''), #program_local_date_string + duration_str + '\n' + (result['title'] or '') + '\n' + (result['subtitle'] or ''), 'plotoutline': datetime.datetime.strftime(program_date, '%H:%M') + ' - ' + (datetime.datetime.strftime(program_date + datetime.timedelta(minutes=(int(result['duration'] or 0) / 1000 / 60)), '%H:%M') if (result['duration'] or 0) > 0 else 'N/A'), # 'programTitle': result['subtitle'], 'id': result['media_globovideos_id'], 'channel_id': result['channel']['globovideos_id'], 'duration': int(result['duration'] or 0) / 1000, # 'tagline': result['subtitle'], # 'date': datetime.datetime.strftime(program_date, '%d.%m.%Y'), # 'aired': datetime.datetime.strftime(program_date, '%Y-%m-%d'), 'dateadded': datetime.datetime.strftime(program_date, '%Y-%m-%d %H:%M:%S'), # 'StartTime': datetime.datetime.strftime(program_date, '%H:%M:%S'), # 'EndTime': datetime.datetime.strftime(program_date + datetime.timedelta(minutes=(result['duration'] or 0)), '%H:%M:%S'), 'brplayprovider': 'globosat', 'livefeed': 'true', 'clearlogo': result['channel']['white_logo'], 'clearart': None, 'banner': None, }
def __get_simulcast_data(result): live_text = ' (' + control.lang(32004) + ')' if result['live'] else '' program_date = util.strptime_workaround(result['day'], '%d/%m/%Y %H:%M') + datetime.timedelta(hours=3) + util.get_utc_delta() if not result['day'] is None else datetime.datetime.now() # program_local_date_string = datetime.datetime.strftime(program_date, '%d/%m/%Y %H:%M') # duration_str = (' - ' + str(result['duration'] or 0) + ' minutos') if (result['duration'] or 0) > 0 else '' title = result['channel']['title'] + ('[I] - ' + (result['title'] or '') + '[/I]' if result['title'] else '') + live_text return { 'slug': result['channel']['title'].lower(), 'studio': result['channel']['title'], 'name': title, 'title': result['subtitle'], 'tvshowtitle': result['title'] if result['title'] else None, 'sorttitle': result['channel']['title'], # 'logo': None, # 'color': None, 'fanart': result['thumb_cms'], 'thumb': result['channel']['url_snapshot'] + '?v=' + str(int(time.time())), 'live': result['live'], 'playable': 'true', 'plot': ' ', #(result['title'] or '') + ' - ' + (result['subtitle'] or ''), #program_local_date_string + duration_str + '\n' + (result['title'] or '') + '\n' + (result['subtitle'] or ''), 'plotoutline': datetime.datetime.strftime(program_date, '%H:%M') + ' - ' + (datetime.datetime.strftime(program_date + datetime.timedelta(minutes=(result['duration'] or 0)), '%H:%M') if (result['duration'] or 0) > 0 else 'N/A'), # 'programTitle': result['subtitle'], 'id': result['id_midia_live_play'], 'channel_id': result['channel']['id_globo_videos'], 'duration': int(result['duration'] or 0) * 60, # 'tagline': result['subtitle'], # 'date': datetime.datetime.strftime(program_date, '%d.%m.%Y'), # 'aired': datetime.datetime.strftime(program_date, '%Y-%m-%d'), 'dateadded': datetime.datetime.strftime(program_date, '%Y-%m-%d %H:%M:%S'), # 'StartTime': datetime.datetime.strftime(program_date, '%H:%M:%S'), # 'EndTime': datetime.datetime.strftime(program_date + datetime.timedelta(minutes=(result['duration'] or 0)), '%H:%M:%S'), 'brplayprovider': 'globosat' }
def channel_directory(self, items): if items is None or len(items) == 0: control.idle() sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) try: isOld = False control.item().getArt('type') except: isOld = True refreshMenu = control.lang(32072).encode('utf-8') list_items = [] for order, channel in enumerate(items): label = channel['name'] meta = channel meta.update({'mediatype': channel['mediatype'] if 'mediatype' in channel else 'tvshow'}) # string - "video", "movie", "tvshow", "season", "episode" or "musicvideo" meta.update({'playcount': 0, 'overlay': 6}) meta.update({'duration': channel['duration']}) if 'duration' in channel else None meta.update({'title': channel['title']}) if 'title' in channel else None meta.update({'tagline': channel['tagline']}) if 'tagline' in channel else None meta.update({'year': channel['year']}) if 'year' in channel else None meta.update({'sorttitle': meta['title']}) meta.update({'title': meta['name']}) sysmeta = urllib.quote_plus(json.dumps(meta)) id_globo_videos = channel['id'] brplayprovider = channel['brplayprovider'] if 'brplayprovider' in channel else None isFolder = channel['isFolder'] == 'true' if 'isFolder' in channel else False isPlayable = channel['playable'] == 'true' if 'playable' in channel else False url = channel['url'] if 'url' in channel else '%s?action=playlive&provider=%s&id_globo_videos=%s&isFolder=%s&meta=%s&t=%s' % (sysaddon, brplayprovider, id_globo_videos, isFolder, sysmeta, self.systime) cm = [(refreshMenu, 'RunPlugin(%s?action=refresh)' % sysaddon)] if isOld is True: cm.append((control.lang2(19033).encode('utf-8'), 'Action(Info)')) item = control.item(label=label) fanart = channel['fanart'] art = {'icon': channel['logo'], 'fanart': fanart} if 'poster' in channel: art.update({'poster': channel['poster']}) if 'banner' in channel: art.update({'banner': channel['banner']}) if 'clearart' in channel: art.update({'clearart': channel['clearart']}) if 'clearlogo' in channel: art.update({'clearlogo': channel['clearlogo']}) if 'landscape' in channel: art.update({'landscape': channel['landscape']}) if 'thumb' in channel: art.update({'thumb': channel['thumb']}) item.setArt(art) if 'logo' in channel and 'logo2' in channel: item.setProperty('Logo1', channel['logo']) item.setProperty('Logo2', channel['logo2']) item.setProperty('Initials1', channel['initials1']) item.setProperty('Initials2', channel['initials2']) if 'live' in channel: item.setProperty('Live', str(channel['live'])) if 'gamedetails' in channel: item.setProperty('GameDetails', channel['gamedetails']) item.setProperty('Fanart_Image', fanart) if 'hd' not in channel or channel['hd'] == True: video_info = {'aspect': 1.78, 'width': 1280, 'height': 720} else: video_info = {'aspect': 1.78, 'width': 720, 'height': 480} item.addStreamInfo('video', video_info) item.addContextMenuItems(cm) item.setProperty('IsPlayable', 'false' if isFolder or not isPlayable else 'true') item.setInfo(type='video', infoLabels=meta) item.setContentLookup(False) if 'duration' in channel and channel['duration'] is not None: duration = float(meta['duration']) startdate = util.strptime_workaround(channel['dateadded'], '%Y-%m-%d %H:%M:%S') if 'dateadded' in channel else None offset = float(util.get_total_seconds(datetime.datetime.now() - startdate)) if startdate else 0 item.setProperty('Progress', str((offset / duration) * 100) if duration else str(0)) item.setProperty('totaltime', str(duration)) # if not isFolder: # item.setMimeType("application/vnd.apple.mpegurl") list_items.append((url, item, isFolder)) # control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_VIDEO_SORT_TITLE) # control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_DATEADDED) # control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_LABEL_IGNORE_FOLDERS) control.addItems(syshandle, list_items) control.category(handle=syshandle, category=control.lang(32001).encode('utf-8')) content = 'LiveTV' if control.isJarvis else 'tvshows' control.content(syshandle, content) control.directory(syshandle, cacheToDisc=False)
def __get_full_day_schedule(today, affiliate='RJ'): url = "https://api.globoplay.com.br/v1/epg/%s/praca/%s?api_key=%s" % (today, affiliate, GLOBOPLAY_APIKEY) headers = {'Accept-Encoding': 'gzip'} slots = client.request(url, headers=headers)['gradeProgramacao']['slots'] result = [] for index, slot in enumerate(slots): cast = None castandrole = None if 'elenco' in slot: try: cast_raw = slot['elenco'].split('||') cast = [c.strip() for c in cast_raw[0].split(',')] if cast_raw is not None and len(cast_raw) > 0 else None if cast_raw is not None and len(cast_raw) > 1 and cast_raw[1].strip().startswith('Elenco de dublagem:'): castandrole_raw = cast_raw[1].strip().split('Elenco de dublagem:') if len(castandrole_raw) > 1: #Dubladores e seus personagens castandrole_raw = castandrole_raw[1].split('Outras Vozes:') castandrole = [(c.strip().split(':')[1].strip(), c.strip().split(':')[0].strip()) for c in castandrole_raw[0].split('/')] if len(castandrole_raw) > 1: #Outros dubladores sem papel definido castandrole = [(c.strip(), 'Outros') for c in castandrole_raw[1].split('/')] except Exception as ex: control.log("ERROR POPULATING CAST: %s" % repr(ex)) pass program_datetime_utc = util.strptime_workaround(slot['data_exibicao_e_horario']) + datetime.timedelta(hours=3) program_datetime = program_datetime_utc + util.get_utc_delta() # program_local_date_string = datetime.datetime.strftime(program_datetime, '%d/%m/%Y %H:%M') title = slot['nome_programa'] if 'nome_programa' in slot else None if slot["tipo"] == "confronto": showtitle = slot['confronto']['titulo_confronto'] + ' - ' + slot['confronto']['participantes'][0]['nome'] + ' X ' + slot['confronto']['participantes'][1]['nome'] else: showtitle = slot['nome'] if 'nome' in slot else None next_start = slots[index+1]['data_exibicao_e_horario'] if index+1 < len(slots) else None next_start = (util.strptime_workaround(next_start) + datetime.timedelta(hours=3) + util.get_utc_delta()) if next_start else datetime.datetime.now() item = { "tagline": slot['chamada'] if 'chamada' in slot else slot['nome'], "closed_caption": slot['closed_caption'], "facebook": slot['facebook'], "twitter": slot['twitter'], "hd": slot['hd'], "id": slot['id'], "id_programa": slot['id_programa'], "id_webmedia": slot['id_webmedia'], "fanart": 'https://s02.video.glbimg.com/x720/%s.jpg' % get_globo_live_id(), "thumb": slot['imagem'], "logo": slot['logo'], "clearlogo": slot['logo'], "poster": slot['poster'] if 'poster' in slot else 'None', "subtitle": slot['nome'], "title": title, "plot": slot['resumo'] if 'resumo' in slot else None, #program_local_date_string + ' - ' + (slot['resumo'] if 'resumo' in slot else showtitle.replace(' - ', '\n') if showtitle and len(showtitle) > 0 else slot['nome_programa']), "plotoutline": datetime.datetime.strftime(program_datetime, '%H:%M') + ' - ' + datetime.datetime.strftime(next_start, '%H:%M'), "mediatype": 'episode' if showtitle and len(showtitle) > 0 else 'video', "genre": slot['tipo_programa'], "datetimeutc": program_datetime_utc, "dateadded": datetime.datetime.strftime(program_datetime, '%Y-%m-%d %H:%M:%S'), # 'StartTime': datetime.datetime.strftime(program_datetime, '%H:%M:%S'), # 'EndTime': datetime.datetime.strftime(next_start, '%H:%M:%S'), 'duration': util.get_total_seconds(next_start - program_datetime) } if showtitle and len(showtitle) > 0: item.update({ 'tvshowtitle': showtitle }) if slot['tipo'] == 'filme': item.update({ "originaltitle": slot['titulo_original'] if 'titulo_original' in slot else None, 'genre': slot['genero'] if 'genero' in slot else None, 'year': slot['ano'] if 'ano' in slot else None, 'director': slot['direcao'] if 'direcao' in slot else None }) if cast: item.update({ 'cast': cast }) if castandrole: item.update({ 'castandrole': castandrole, }) result.append(item) return result
def __get_universal_epg(): utc_timezone = control.get_current_brasilia_utc_offset() utc_now = datetime.datetime.today().utcnow() now = utc_now + datetime.timedelta(hours=utc_timezone) epg_url = 'http://ancine.grade.globosat.tv/programada/01253766000140_UniversalChannel%s.csv' % datetime.datetime.strftime(now, '%Y%m%d') # '20180205' epg_csv = cache.get(client.request, 2, epg_url) epg_data = csv.reader(epg_csv.splitlines(), delimiter='\\', quotechar='"') for program in list(epg_data): p_date = program[0] p_start = program[1] p_end = program[2] original_title = program[3] director = program[4] title = program[5] tvshow = program[6] episode = program[7] country = program[8] year = program[9] rating = program[10] plot = program[11] start_time = util.strptime_workaround(p_date + ' ' + p_start, '%Y%m%d %H:%M') - datetime.timedelta(hours=(utc_timezone)) end_time = util.strptime_workaround(p_date + ' ' + p_end, '%Y%m%d %H:%M') - datetime.timedelta(hours=(utc_timezone)) start_hour = p_start.split(':')[0] end_hour = p_end.split(':')[0] if int(end_hour) < int(start_hour): end_time = end_time + datetime.timedelta(days=1) if end_time > utc_now > start_time: studio = 'Universal Channel' return { 'original_title': original_title, 'director': director, 'title': title, 'tvshowtitle': tvshow, 'episode': episode, 'country': country, 'year': year, 'rating': rating, 'plot': plot, 'duration': util.get_total_seconds(end_time - start_time), "dateadded": datetime.datetime.strftime(start_time + util.get_utc_delta(), '%Y-%m-%d %H:%M:%S'), "plotoutline": datetime.datetime.strftime(start_time + util.get_utc_delta(), '%H:%M') + ' - ' + datetime.datetime.strftime(end_time + util.get_utc_delta(), '%H:%M'), } return { 'original_title': None, 'director': None, 'title': None, 'tvshowtitle': None, 'episode': None, 'country': None, 'year': None, 'rating': None, 'plot': None, 'duration': None, "dateadded": None }
def get_live_channels(): start_date = datetime.datetime.utcnow() stop_date = start_date + datetime.timedelta(hours=6) url = 'https://api.pluto.tv/v2/channels?start=' + start_date.strftime( '%Y-%m-%dT%H:00:00.000Z') + '&stop=' + stop_date.strftime( '%Y-%m-%dT%H:00:00.000Z') response = cache.get(requests.get, 4, url, proxies=proxy, table='pluto').json() now_str = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.000Z') for channel in response: if 'timelines' not in channel: continue program = next(p for p in channel['timelines'] if p['start'] <= now_str < p['stop']) is_live = program.get('liveBroadcast', False) live_text = u' (' + control.lang(32004) + u')' if is_live else u'' title = program.get('title') sub_title = program.get('episode', {}).get('name') thumb = program.get('episode', {}).get('series', {}).get( 'featuredImage', {}).get('path') or program.get('episode', {}).get( 'poster', {}).get('path') or None fanart = thumb logo = channel['colorLogoPNG']['path'] program_name = title + (u': ' + sub_title if sub_title else u'') duration_milliseconds = int(program['episode']['duration']) start_time = util.strptime_workaround(program['start'], '%Y-%m-%dT%H:%M:%S.%fZ') stop_time = start_time + datetime.timedelta( milliseconds=duration_milliseconds) program_time_desc = datetime.datetime.strftime( start_time, '%H:%M') + ' - ' + datetime.datetime.strftime( stop_time, '%H:%M') tags = [program_time_desc] description = '%s | %s' % (program_time_desc, program.get( 'episode', {}).get('description')) studio = channel['name'] label = u"[B]%s[/B][I] - %s[/I]%s" % (studio, program_name, live_text) genres = [ program.get('episode', {}).get('genre').upper(), program.get('episode', {}).get('subGenre').upper(), program.get('episode', {}).get('series', {}).get('type').upper() ] sid = control.setting('pluto_sid') if not sid: sid = str(uuid.uuid4()) control.setSetting('pluto_sid', sid) did = control.setting('pluto_did') if not did: did = str(uuid.uuid4()) control.setSetting('pluto_did', did) video_url = u'https://service-stitcher.clusters.pluto.tv/stitch/hls/channel/{channel}/master.m3u8?deviceType=web&deviceMake=Chrome&deviceModel=Chrome&sid={sid}&deviceId={did}&deviceVersion=74.0.3729.131&appVersion=2.5.1-f9a6096b469cfe5e4f1cc92cc697e8500e57891c&deviceDNT=0&userId=&advertisingId=&deviceLat=38.8177&deviceLon=-77.1527&app_name=&appName=&buildVersion=&appStoreUrl=&architecture='.format( channel=channel['_id'], sid=sid, did=did) # video_url = channel.get('stitched', {}).get('urls', [])[0].get('url') yield { 'url': video_url, 'IsPlayable': True, 'label': label, 'title': label, 'studio': 'Pluto TV', 'tvshowtitle': title, 'sorttitle': program_name, 'dateadded': datetime.datetime.strftime(start_time, '%Y-%m-%d %H:%M:%S'), 'plot': description, 'tag': tags, 'duration': duration_milliseconds / 1000, 'adult': False, 'genre': genres, 'year': program.get('episode', {}).get('clip', {}).get('originalReleaseDate', '')[0:4], 'rating': program.get('episode', {}).get('rating'), 'episode': program.get('episode', {}).get('number'), 'art': { 'icon': logo, 'thumb': thumb, 'tvshow.poster': thumb, 'clearlogo': logo, 'fanart': fanart } }
def get_programmes(): page_range = [0, 1, 2] headers = { 'Authorization': get_authorization(), 'Origin': 'https://www.sbt.com.br', 'Accept-Encoding': 'gzip, deflate, br' } results = [] br_timezone = pytz.timezone('America/Sao_Paulo') now = datetime.datetime.now(tz=br_timezone) for i in page_range: date = now + datetime.timedelta(days=i) url = 'http://content.sbt.com.br/api/programgrade?datagrade={}&limit=200'.format( date.strftime('%Y-%m-%d')) print('GET ' + url) response = requests.get(url, headers=headers, verify=False).json() results.extend(response['results']) programmes = [] for result in results: start_time = util.strptime_workaround(result['startdate'], '%Y-%m-%dT%H:%M:%S') start_time = pytz.timezone('America/Sao_Paulo').localize(start_time) start_time = start_time.astimezone(pytz.UTC) start_time_string = datetime.datetime.strftime(start_time, '%Y%m%d%H%M%S +0000') title = result['title'] rating = result['classification'].strip() desc = result['description'] + u' ({})'.format(rating) programme = { 'channel': id, 'start': start_time_string, 'title': [(title, u'pt')], 'icon': [{ 'src': result['thumbnail'] }], 'desc': [(desc, u'pt')], 'category': [(result['gender'], u'pt')] } programmes.append(programme) programmes = sorted(programmes, key=lambda x: (x['channel'], x['start'])) size = len(programmes) for i in range(0, size - 1): if programmes[i]['channel'] == programmes[i + 1]['channel']: programmes[i]['stop'] = programmes[i + 1]['start'] return programmes
def get_live_channels(): headers = { 'Authorization': get_authorization(), 'Origin': 'https://www.sbt.com.br', 'Accept-Encoding': 'gzip, deflate, br' } br_timezone = pytz.timezone('America/Sao_Paulo') now = datetime.datetime.now(tz=br_timezone) if control.setting('sbt_ignore_dst') == 'true': now = now - br_timezone.localize(datetime.datetime.utcnow()).dst() url = 'https://content.sbt.com.br/api/programschedule?livegrade={date}&operation=le&orderby=startdate&limit=1'.format( date=now.strftime('%Y-%m-%dT%H:%M:%S')) control.log('GET %s' % url) programs = (requests.get(url, headers=headers, verify=False).json() or {}).get('results', []) control.log(programs) program = next(iter(programs), {}) or {} try: start_time = util.strptime_workaround(program.get('startdate'), '%Y-%m-%dT%H:%M:%S') start_time = br_timezone.localize(start_time) start_time = start_time.astimezone(pytz.UTC) start_time = start_time + util.get_utc_delta() except: control.log(traceback.format_exc(), control.LOGERROR) start_time = datetime.datetime.now() plot = program.get('description') plot = '%s - | %s' % (datetime.datetime.strftime(start_time, '%H:%M'), plot) program_name = program.get('title') channel_name = 'SBT' label = u"[B]%s[/B][I] - %s[/I]" % (channel_name, program_name) thumb = program.get('thumbnail') tags = [] yield { 'handler': PLAYER_HANDLER, 'method': 'playlive', 'IsPlayable': True, 'livefeed': True, 'studio': channel_name, 'label': label, 'title': label, 'genre': program.get('gender'), # 'title': program.get('metadata', program.get('name', '')), 'tvshowtitle': program_name, 'sorttitle': program_name, 'tag': tags, 'plot': plot, 'duration': int(0), 'dateadded': datetime.datetime.strftime(start_time, '%Y-%m-%d %H:%M:%S'), 'mediatype': 'episode', 'art': { 'icon': SBT_LOGO, 'clearlogo': SBT_LOGO, 'fanart': thumb, 'thumb': thumb, 'tvshow.poster': thumb, } }