From 19815f345f0e626e6a7cee799ae9b12833ff2ced Mon Sep 17 00:00:00 2001 From: Alhaziel Date: Thu, 30 Jan 2020 19:48:28 +0100 Subject: [PATCH] Rai Play [WIP 2] --- channels/raiplay.py | 149 ++++++++++++++++++++++++++++---------------- channelselector.py | 10 +-- 2 files changed, 103 insertions(+), 56 deletions(-) diff --git a/channels/raiplay.py b/channels/raiplay.py index 3aefd90b..d96f156d 100644 --- a/channels/raiplay.py +++ b/channels/raiplay.py @@ -8,35 +8,63 @@ from core import support from lib.concurrent import futures current_session = requests.Session() host = support.config.get_channel_url() -menuURL = 'http://www.rai.it/dl/RaiPlay/2016/menu/PublishingBlock-20b274b1-23ae-414f-b3bf-4bdc13b86af2.html?homejson' -channels = 'http://www.rai.it/dl/RaiPlay/2016/PublishingBlock-9a2ff311-fcf0-4539-8f8f-c4fee2a71d58.html?json' +onair = host + '/palinsesto/onAir.json' @support.menu def mainlist(item): - film = ['/film/index.json', - ('Genere', ['/film/index.json', 'menu', 'genre']), - ('A-Z', ['/film/index.json', 'menu', 'az']) - ] - tvshow = ['/serietv/index.json', - ('Genere', ['/serietv/index.json', 'menu', 'genre']), - ('A-Z', ['/serietv/index.json', 'menu', 'az']) - ] - fiction = [('Fiction {bullet bold}', ['/fiction/index.json', 'peliculas']), - ('Genere {submenu}', ['/fiction/index.json', 'menu', 'genre']), - ('A-Z {submenu}', ['/fiction/index.json', 'menu', 'az']), - ('Cerca Fiction... {submenu bold}', ['/fiction/index.json', 'search']) - ] + top = [('Dirette {bold}', ['/dl/RaiPlay/2016/PublishingBlock-9a2ff311-fcf0-4539-8f8f-c4fee2a71d58.html?json', 'dirette'])] - top = [('Dirette TV {bold}', ['', 'dirette']), - # ('Genere {submenu}', ['/fiction/index.json', 'menu', 'genre']), - # ('A-Z {submenu}', ['/fiction/index.json', 'menu', 'az']), - # ('Cerca Fiction... {submenu bold}', ['/fiction/index.json', 'search']) - ] + menu = [('Film {bullet bold}', ['/film/index.json', 'menu']), + ('Cerca Film... {submenu}', ['/film/index.json', 'search']), + + ('Serie TV {bullet bold}', ['/serietv/index.json', 'menu']), + ('Cerca Serie TV... {submenu}', ['/serietv/index.json', 'search']), + + ('Fiction {bullet bold}', ['/fiction/index.json', 'menu']), + ('Cerca Fiction... {submenu}', ['/fiction/index.json', 'search']), + + ('Documentari {bullet bold}', ['/documentari/index.json', 'menu']), + ('Cerca Documentari... {submenu}', ['/documentari/index.json', 'search']), + + ('Programmi TV{bullet bold}', ['/programmi/index.json', 'menu']), + ('Cerca Programmi TV... {submenu}', ['/programmi/index.json', 'search']), + + ('Programmi per Bambini {bullet bold}', ['/bambini/index.json', 'menu']), + ('Cerca Programmi per Bambini... {submenu}', ['/bambini/index.json', 'search']), + + ('Teche Rai {bullet bold storia}', ['/techerai/index.json', 'menu']), + ('Cerca in Teche Rai... {submenu}', ['/techerai/index.json', 'search']), + + ('Musica e Teatro {bullet bold}', ['/performing-arts/index.json', 'menu']), + ('Cerca in Musica e Teatro... {submenu}', ['/performing-arts/index.json', 'search']) + ] return locals() def menu(item): + support.log() + itemlist = [ + support.Item(channel= item.channel, + title = support.typo('Tutti','bullet bold'), + url = item.url, + action = 'peliculas'), + + support.Item(channel= item.channel, + title = support.typo('Generi','submenu'), + url = item.url, + action = 'submenu'), + + support.Item(channel= item.channel, + title = support.typo('A-Z','submenu'), + url = item.url, + action = 'submenu'), + ] + + + return support.thumb(itemlist) + +def submenu(item): itemlist = [] json = current_session.get(item.url).json()['contents'][-1]['contents'] if item.args == 'az': @@ -64,11 +92,13 @@ def menu(item): fulltitle = key['name'], show = key['name'], thumbnail = getUrl(key['image']), + url = getUrl(key['path_id']), action = 'peliculas', args = item.args )) - support.thumb(itemlist) - return itemlist + itemlist.pop(-1) + + return support.thumb(itemlist) def search(item, text): @@ -86,6 +116,27 @@ def search(item, text): return itemlist +def dirette(item): + support.log() + itemlist =[] + json = current_session.get(item.url).json()['dirette'] + onAir = current_session.get(onair).json()['on_air'] + for i, key in enumerate(json): + itemlist.append( + support.Item( + channel = item.channel, + title = support.typo(key['channel'], 'bold'), + fulltitle = key['channel'], + show = key['channel'], + thumbnail = key['transparent-icon'].replace("[RESOLUTION]", "256x-"), + fanart = getUrl(onAir[i]['currentItem']['image']), + url = key['video']['contentUrl'], + plot = support.typo(onAir[i]['currentItem']['name'],'bold')+ '\n\n' + onAir[i]['currentItem']['description'], + action = 'play' + )) + return itemlist + + def peliculas(item): support.log() itemlist = [] @@ -109,9 +160,12 @@ def peliculas(item): if not item.args: json_url = getUrl(json['contents'][-1]['contents'][-1]['path_id']) json = current_session.get(json_url).json()['contents'] + else: + json = json['contents'] for key in json: if len(json[key]) > 0: for key in json[key]: + support.log(key) if item.search.lower() in key['name'].lower(): keys.append(key) @@ -121,8 +175,7 @@ def peliculas(item): if pagination and i >= pag * pagination: break key_list.append(key) - if 'film' in item.url: item.contentType ='movie' - else: item.contentType = 'tvshow' + with futures.ThreadPoolExecutor() as executor: itlist = [executor.submit(addinfo, key, item) for key in key_list] for res in futures.as_completed(itlist): @@ -130,7 +183,6 @@ def peliculas(item): itemlist.append(res.result()) itemlist = sorted(itemlist, key=lambda it: it.title) - if len(keys) > pag * pagination and not item.search: itemlist.append( support.Item(channel=item.channel, @@ -154,14 +206,17 @@ def select(item): support.Item( channel = item.channel, title = support.typo(key['name'],'bold'), - fulltitle = key['name'], - show = key['name'], + fulltitle = item.fulltitle, + show = item.show, thumbnail = item.thumbnail, url = key['sets'], action = 'episodios', args = item.args )) - return itemlist + if len(itemlist) == 1: + return episodios(itemlist[0]) + else: + return itemlist def episodios(item): @@ -172,10 +227,12 @@ def episodios(item): if res.result(): itemlist += res.result() itemlist = sorted(itemlist, key=lambda it: it.title) + if itemlist[0].VL: support.videolibrary(itemlist, item) return itemlist def findvideos(item): + itemlist = [] if item.contentType == 'episode': url = item.url @@ -194,18 +251,18 @@ def findvideos(item): url = url, action = 'play' )) - return support.server(item, itemlist=itemlist) + return support.server(item, itemlist=itemlist, down_load=False) def getUrl(pathId): url = pathId.replace(" ", "%20") if url.startswith("/raiplay/"): - url = url.replace("/raiplay/","https://raiplay.it/") + url = url.replace("/raiplay/",host +'/') if url.startswith("//"): url = "https:" + url elif url.startswith("/"): - url = host[:-1] + url + url = host + url # fix old format of url for json if url.endswith(".html?json"): @@ -229,17 +286,21 @@ def addinfo(key, item): fanart = getUrl(key['images']['landscape']), url = getUrl(key['path_id']), plot = info['description'], - action = 'findvideos' if item.contentType == 'movies' else 'select') + contentType = 'movie' if key['layout'] == 'single' else 'tvshow', + action = 'findvideos' if key['layout'] == 'single' else 'select') return it def load_episodes(key, item): + support.log() itemlist=[] json = current_session.get(getUrl(key['path_id'])).json()['items'] for key in json: - # support.log(key) ep = support.match(key['subtitle'].encode('utf8'), patron=r'St\s*(\d+)\s*Ep\s*(\d+)').match - title = ep[0] + 'x' + ep[1].zfill(2) + support.re.sub(r'St\s*\d+\s*Ep\s*\d+','',key['subtitle'].encode('utf8')) + if ep: + title = ep[0] + 'x' + ep[1].zfill(2) + support.re.sub(r'St\s*\d+\s*Ep\s*\d+','',key['subtitle'].encode('utf8')) + else: + title = key['subtitle'] itemlist.append( support.Item( channel = item.channel, @@ -251,25 +312,9 @@ def load_episodes(key, item): url = key['video_url'], plot = key['description'], contentType = 'episode', - action = 'findvideos' + action = 'findvideos', + VL=True if ep else False )) return itemlist -def dirette(item): - itemlist = [] - json = current_session.get(channels).json()['dirette'] - for key in json: - itemlist.append( - support.Item( - channel = item.channel, - title = support.typo(key['channel'], 'bold'), - fulltitle = key['channel'], - show = key['channel'], - thumbnail = key['transparent-icon'].replace("[RESOLUTION]", "256x-"), - fanart = key['stillFrame'], - url = key['video']['contentUrl'], - plot = key['description'], - action = 'play' - )) - return itemlist \ No newline at end of file diff --git a/channelselector.py b/channelselector.py index a0804291..18a85004 100644 --- a/channelselector.py +++ b/channelselector.py @@ -357,7 +357,7 @@ def thumb(itemlist=[], genre=False, thumb=''): import re icon_dict = {'channels_movie':['film'], - 'channels_tvshow':['serie','tv','episodi','episodio'], + 'channels_tvshow':['serie','tv','episodi','episodio','fiction'], 'channels_documentary':['documentari','documentario', 'documentary'], 'channels_all':['tutti'], 'news':['novità', "novita'", 'aggiornamenti', 'nuovi', 'nuove'], @@ -385,12 +385,14 @@ def thumb(itemlist=[], genre=False, thumb=''): 'popular' : ['popolari','popolare', 'più visti'], 'thriller':['thriller'], 'top_rated' : ['fortunato', 'votati'], - 'on_the_air' : ['corso', 'onda'], + 'on_the_air' : ['corso', 'onda', 'diretta', 'dirette'], 'channels_western':['western'], 'channels_vos':['sub','sub-ita'], 'channels_romance':['romantico','sentimentale', 'romance'], 'channels_family':['famiglia','famiglie', 'family'], - 'channels_historical':['storico', 'history'], + 'channels_historical':['storico', 'history', 'storia'], + 'channels_az':['lettera','lista','alfabetico','a-z'], + 'channels_year':['anno', 'anni'], 'autoplay':[config.get_localized_string(60071)] } @@ -403,7 +405,7 @@ def thumb(itemlist=[], genre=False, thumb=''): search = ['cerca'] search_suffix ={'_movie':['film'], - '_tvshow':['serie','tv']} + '_tvshow':['serie','tv', 'fiction']} for item in itemlist: