From f58288ae730725413f6e0e3dce2c66366a57b8f0 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 25 Jun 2020 23:04:59 +0200 Subject: [PATCH] test filmontv --- specials/filmontv.py | 197 +++++++++++++++++++------------------------ 1 file changed, 89 insertions(+), 108 deletions(-) diff --git a/specials/filmontv.py b/specials/filmontv.py index 57b1f577..d93e7b9e 100644 --- a/specials/filmontv.py +++ b/specials/filmontv.py @@ -5,18 +5,13 @@ import datetime import glob import time -# import xml.etree.ElementTree as ET -from core import filetools, downloadtools, jsontools, scrapertools +import xml.etree.ElementTree as ET +from core import filetools, downloadtools, support, scrapertools from core.item import Item from platformcode import logger, config import gzip -host = "http://www.epgitalia.tv/xml/guide.gzip" -now = datetime.datetime.now() -fileName = config.get_temp_file('guidatv-') + now.strftime('%Y %m %d') -archiveName = fileName + '.gz' -# xmlName = fileName + '.xml' -jsonName = fileName + '.json' +host = "http://www.epgitalia.tv/xml/guide2.gzip" def mainlist(item): @@ -25,13 +20,17 @@ def mainlist(item): itemlist.append(Item(title='Film in onda oggi', channel=item.channel, action='peliculas', contentType='movie')) itemlist.append(Item(title='Serie Tv in onda oggi', channel=item.channel, action='peliculas', contentType='tvshow')) - # itemlist.append(Item(title='Guida tv per canale', channel=item.channel, action='listaCanali')) + itemlist.append(Item(title='Guida tv per canale', channel=item.channel, action='listaCanali')) itemlist.append(Item(title='Canali live (Rai Play)', channel=item.channel, action='live')) return itemlist def getEpg(): + now = datetime.datetime.now() + fileName = config.get_temp_file('guidatv-') + now.strftime('%Y %m %d') + archiveName = fileName + '.gz' + xmlName = fileName + '.xml' if not filetools.exists(archiveName): logger.info('downloading epg') # cancello quelli vecchi @@ -39,43 +38,93 @@ def getEpg(): filetools.remove(f, silent=True) # inmemory = io.BytesIO(httptools.downloadpage(host).data) downloadtools.downloadfile(host, archiveName) - if filetools.exists(archiveName) and not filetools.exists(jsonName): - logger.info('opening gzip and writing Json') + logger.info('opening gzip and writing xml') fStream = gzip.GzipFile(archiveName, mode='rb') guide = fStream.read() - write_json(guide) - - with open(jsonName) as f: - json = jsontools.load(f.read()) - return json + with open(xmlName, 'w') as f: + f.write(guide) + guide = open(xmlName).read() + return guide def peliculas(item): + f = getEpg() + titles = [] itemlist = [] - start = time.time() - json_file = getEpg() - logger.info('PARSE TIME: ' + str(time.time() - start)) - start = time.time() - if item.contentType == 'movie': - json = json_file['movies'] - else: - json = json_file['tvshows'] - for title, value in json.items(): - if 'infoLabels' in value: - infoLabels = value['infoLabels'] - itemlist.append(Item( - channel=item.channel, - search_text=title, - title=title + (' - ' + value['episode'] if 'episode' in value else ''), - plot=value['plot'], - thumbnail=value['thumbnail'], - contentType=item.contentType, - infoLabels=infoLabels - )) - logger.info('BUILD ITEMLIST: ' + str(time.time() - start)) - # tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True) - return itemlist + channel = '' + title = '' + episode = '' + plot = '' + thumbnail = '' + actors = [] + director = '' + year = '' + genres = [] + country = '' + start = '' + stop = '' + + for line in f.splitlines(): + if '([^<]+)<') + elif '([^<]+)<') + elif '([^<]+)<') + actors.append([match[1], match[0]]) + elif '([^<]+)<') + elif '([^<]+)<') + elif '([^<]+)<')) + elif '([^<]+)<') + elif '([^<]+)<') + elif '= 20: + break + return itemlist def listaCanali(item): itemlist = [] @@ -154,7 +203,7 @@ def guidatv(item): infoLabels={ 'title': title, 'plot': desc if desc else '', - 'castandrole': tuple(actors) if actors else '', + 'casta': actors if actors else '', 'genre': genres if genres else '', 'country': country if country else '' } @@ -171,71 +220,3 @@ def new_search(item): def live(item): from channels import raiplay return raiplay.dirette(raiplay.mainlist(Item())[0]) - -def write_json(f): - - titles = [] - channel_dict = {} - channel_dict['movies'] = {} - channel_dict['tvshows'] = {} - - channel = '' - title = '' - episode = '' - plot = '' - thumbnail = '' - actors = [] - director = '' - year = '' - genres = [] - country = '' - start = '' - stop = '' - - - for line in f.splitlines(): - if '([^<]+)<') - elif '([^<]+)<') - elif '([^<]+)<') - actors.append([match[1], match[0]]) - elif '([^<]+)<') - elif '([^<]+)<') - elif '([^<]+)<')) - elif '([^<]+)<') - elif '([^<]+)<') - elif '