test filmontv
This commit is contained in:
@@ -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 '<programme' in line:
|
||||
start, stop, channel = scrapertools.find_single_match(line,
|
||||
r'start="(\d+)[^"]*" stop="(\d+)[^"]*" channel="([^"]+)"')
|
||||
elif '<title' in line:
|
||||
title = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<desc' in line:
|
||||
plot = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<actor' in line:
|
||||
match = scrapertools.find_single_match(line, r'(?:role="([^"]*)")?>([^<]+)<')
|
||||
actors.append([match[1], match[0]])
|
||||
elif '<director' in line:
|
||||
director = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<date' in line:
|
||||
year = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<category' in line:
|
||||
genres.append(scrapertools.find_single_match(line, r'>([^<]+)<'))
|
||||
elif '<country' in line:
|
||||
country = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<episode-num' in line:
|
||||
episode = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<icon' in line:
|
||||
thumbnail = scrapertools.find_single_match(line, r'src="([^"]+)"')
|
||||
elif '</programme' in line and title not in titles and actors:
|
||||
titles.append(title)
|
||||
|
||||
itemlist.append(Item(
|
||||
channel=item.channel,
|
||||
action='new_search',
|
||||
title=title,
|
||||
search_text=title,
|
||||
mode=item.contentType,
|
||||
year=year if year else '-',
|
||||
thumbnail=thumbnail if thumbnail else '',
|
||||
contentType=item.contentType,
|
||||
infoLabels={
|
||||
'title': title,
|
||||
'plot': plot if plot else '',
|
||||
'casta': actors if actors else '',
|
||||
'genre': genres if genres else '',
|
||||
'country': country if country else ''
|
||||
}
|
||||
))
|
||||
|
||||
channel = ''
|
||||
title = ''
|
||||
episode = ''
|
||||
plot = ''
|
||||
thumbnail = ''
|
||||
actors = []
|
||||
director = ''
|
||||
year = ''
|
||||
genres = []
|
||||
country = ''
|
||||
start = ''
|
||||
stop = ''
|
||||
|
||||
if len(titles) >= 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 '<programme' in line: start, stop, channel = scrapertools.find_single_match(line, r'start="(\d+)[^"]*" stop="(\d+)[^"]*" channel="([^"]+)"')
|
||||
elif '<title' in line: title = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<desc' in line: plot = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<actor' in line:
|
||||
match = scrapertools.find_single_match(line, r'(?:role="([^"]*)")?>([^<]+)<')
|
||||
actors.append([match[1], match[0]])
|
||||
elif '<director' in line: director = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<date' in line: year = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<category' in line: genres.append(scrapertools.find_single_match(line, r'>([^<]+)<'))
|
||||
elif '<country' in line: country = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<episode-num' in line: episode = scrapertools.find_single_match(line, r'>([^<]+)<')
|
||||
elif '<icon' in line: thumbnail = scrapertools.find_single_match(line, r'src="([^"]+)"')
|
||||
elif '</programme' in line and title and title not in titles and actors:
|
||||
titles.append(title)
|
||||
if episode:
|
||||
t = channel_dict['tvshows']
|
||||
else:
|
||||
t = channel_dict['movies']
|
||||
t[title] = {}
|
||||
t[title]['infoLabels'] = {'castandrole':actors, 'director':director, 'genres':genres, 'country':country, 'year':year}
|
||||
t['start'] = start
|
||||
t['stop'] = stop
|
||||
t['episode'] = episode
|
||||
t[title]['title'] = title
|
||||
t[title]['channel_name'] = channel
|
||||
t[title]['thumbnail'] = thumbnail
|
||||
t[title]['plot'] = plot
|
||||
|
||||
channel = ''
|
||||
title = ''
|
||||
episode = ''
|
||||
plot = ''
|
||||
thumbnail = ''
|
||||
actors = []
|
||||
director = ''
|
||||
year = ''
|
||||
genres = []
|
||||
country = ''
|
||||
start = ''
|
||||
stop = ''
|
||||
|
||||
# f = json.dumps(channel_dict)
|
||||
with open(jsonName, 'w') as json_file:
|
||||
json_file.write(jsontools.dump(channel_dict, sort_keys=False))
|
||||
json_file.close()
|
||||
Reference in New Issue
Block a user