Qualche aggiunta a filmontv

This commit is contained in:
Alhaziel01
2020-06-26 18:26:31 +02:00
parent f58288ae73
commit 4c6ca4e0c3
+146 -129
View File
@@ -2,43 +2,38 @@
# ------------------------------------------------------------ # ------------------------------------------------------------
# Canale film in tv # Canale film in tv
# ------------------------------------------------------------ # ------------------------------------------------------------
import datetime from datetime import datetime, timedelta
import glob import glob, time, gzip, xbmc
import time
import xml.etree.ElementTree as ET
from core import filetools, downloadtools, support, scrapertools from core import filetools, downloadtools, support, scrapertools
from core.item import Item from core.item import Item
from platformcode import logger, config
import gzip
host = "http://www.epgitalia.tv/xml/guide2.gzip" host = "http://www.epgitalia.tv/xml/guide2.gzip"
def mainlist(item): def mainlist(item):
logger.info(" mainlist") support.log()
itemlist = []
itemlist.append(Item(title='Film in onda oggi', channel=item.channel, action='peliculas', contentType='movie')) itemlist = [Item(title=support.typo('Film in onda oggi','bold'), channel=item.channel, action='peliculas', contentType='movie'),
itemlist.append(Item(title='Serie Tv in onda oggi', channel=item.channel, action='peliculas', contentType='tvshow')) Item(title=support.typo('Serie Tv in onda oggi','bold'), channel=item.channel, action='peliculas', contentType='tvshow'),
itemlist.append(Item(title='Guida tv per canale', channel=item.channel, action='listaCanali')) Item(title=support.typo('Guida tv per canale','bold'), channel=item.channel, action='listaCanali'),
itemlist.append(Item(title='Canali live (Rai Play)', channel=item.channel, action='live')) Item(title=support.typo('Canali live (Rai Play)','bold'), channel=item.channel, action='live')]
return itemlist return itemlist
def getEpg(): def getEpg():
now = datetime.datetime.now() now = datetime.now()
fileName = config.get_temp_file('guidatv-') + now.strftime('%Y %m %d') fileName = support.config.get_temp_file('guidatv-') + now.strftime('%Y %m %d')
archiveName = fileName + '.gz' archiveName = fileName + '.gz'
xmlName = fileName + '.xml' xmlName = fileName + '.xml'
if not filetools.exists(archiveName): if not filetools.exists(archiveName):
logger.info('downloading epg') support.log('downloading epg')
# cancello quelli vecchi # cancello quelli vecchi
for f in glob.glob(config.get_temp_file('guidatv-') + '*'): for f in glob.glob(support.config.get_temp_file('guidatv-') + '*'):
filetools.remove(f, silent=True) filetools.remove(f, silent=True)
# inmemory = io.BytesIO(httptools.downloadpage(host).data) # inmemory = io.BytesIO(httptools.downloadpage(host).data)
downloadtools.downloadfile(host, archiveName) downloadtools.downloadfile(host, archiveName)
logger.info('opening gzip and writing xml') support.log('opening gzip and writing xml')
fStream = gzip.GzipFile(archiveName, mode='rb') fStream = gzip.GzipFile(archiveName, mode='rb')
guide = fStream.read() guide = fStream.read()
with open(xmlName, 'w') as f: with open(xmlName, 'w') as f:
@@ -47,10 +42,115 @@ def getEpg():
guide = open(xmlName).read() guide = open(xmlName).read()
return guide return guide
def peliculas(item): def peliculas(item, f=None, ):
f = getEpg() f = getEpg()
titles = [] titles = [item.lastTitle] if not item.titles else item.titles
itemlist = [] itemlist = []
pag = item.pag if item.pag else 0
channel = ''
title = ''
episode = ''
plot = ''
thumbnail = ''
actors = []
director = ''
year = ''
genres = []
country = ''
for i, line in enumerate(f.splitlines()):
if i >= pag:
if '<programme' in line:
channel = scrapertools.find_single_match(line, r'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 or 'Film' in genres):
titles.append(title)
if (item.contentType == 'movie' and not episode) or (item.contentType == 'tvshow' and episode):
itemlist.append(Item(
channel=item.channel,
action='new_search',
title=support.typo(title + (' - ' + episode if episode else ''), 'bold'),
fulltitle=title,
search_text=title,
mode=item.contentType,
thumbnail=thumbnail if thumbnail else item.thumbnail,
contentType=item.contentType,
channel_name=channel,
infoLabels={
'title': title,
'plot': plot,
'castandrole': actors,
'director': director,
'genre': genres,
'country': country,
'year': year
}
))
channel = ''
title = ''
episode = ''
plot = ''
thumbnail = ''
actors = []
director = ''
year = ''
genres = []
country = ''
if len(itemlist) >= 40:
itemlist.append(item.clone(title=support.typo(support.config.get_localized_string(30992), 'color kod bold'), pag= i + 1, thumbnail=support.thumb(), lastTitle=titles[-1]))
break
support.tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True)
return itemlist
def listaCanali(item):
itemlist = []
f = getEpg()
for line in f.splitlines():
if '<channel' in line:
channel = scrapertools.find_single_match(line, r'id="([^"]+)"')
elif '<icon' in line:
thumbnail = scrapertools.find_single_match(line, r'src="([^"]+)"')
elif '<programme' in line:
break
if '</channel' in line and thumbnail:
itemlist.append(Item(
channel=item.channel,
action='guidatv',
title=support.typo(channel, 'bold'),
channelName=channel,
thumbnail=thumbnail
))
# return itemlist
return sorted(itemlist, key=lambda x: x.title)
def guidatv(item):
itemlist = []
f = getEpg()
days = []
for day in range(11, 18):days.append(xbmc.getLocalizedString(day))
channel = '' channel = ''
title = '' title = ''
@@ -67,8 +167,7 @@ def peliculas(item):
for line in f.splitlines(): for line in f.splitlines():
if '<programme' in line: if '<programme' in line:
start, stop, channel = scrapertools.find_single_match(line, start, stop, channel = scrapertools.find_single_match(line,r'start="([^"]*)" stop="([^"]*)" channel="([^"]+)"')
r'start="(\d+)[^"]*" stop="(\d+)[^"]*" channel="([^"]+)"')
elif '<title' in line: elif '<title' in line:
title = scrapertools.find_single_match(line, r'>([^<]+)<') title = scrapertools.find_single_match(line, r'>([^<]+)<')
elif '<desc' in line: elif '<desc' in line:
@@ -88,26 +187,31 @@ def peliculas(item):
episode = scrapertools.find_single_match(line, r'>([^<]+)<') episode = scrapertools.find_single_match(line, r'>([^<]+)<')
elif '<icon' in line: elif '<icon' in line:
thumbnail = scrapertools.find_single_match(line, r'src="([^"]+)"') thumbnail = scrapertools.find_single_match(line, r'src="([^"]+)"')
elif '</programme' in line and title not in titles and actors: elif '</programme' in line:
titles.append(title) if item.channelName in channel:
start = time.strptime(str(int(start.split(' ')[0]) + int(start.split('+')[1])), '%Y%m%d%H%M%S')
itemlist.append(Item( stop = time.strptime(str(int(stop.split(' ')[0]) + int(stop.split('+')[1])), '%Y%m%d%H%M%S')
channel=item.channel, duration = days[start.tm_wday] + ' alle ' + str(start.tm_hour).zfill(2) + ':' + str(start.tm_min).zfill(2) + ' - ' + str(stop.tm_hour).zfill(2) + ':' + str(stop.tm_min).zfill(2) + ' - '
action='new_search', itemlist.append(Item(
title=title, channel=item.channel,
search_text=title, action='new_search',
mode=item.contentType, title=duration + support.typo(title + (' - ' + episode if episode else ''), 'bold'),
year=year if year else '-', fulltitle=title,
thumbnail=thumbnail if thumbnail else '', search_text=title,
contentType=item.contentType, mode=item.contentType,
infoLabels={ thumbnail=thumbnail if thumbnail else item.thumbnail,
'title': title, contentType=item.contentType,
'plot': plot if plot else '', channel_name=channel,
'casta': actors if actors else '', infoLabels={
'genre': genres if genres else '', 'title': title,
'country': country if country else '' 'plot': plot,
} 'castandrole': actors,
)) 'director': director,
'genre': genres,
'country': country,
'year': year
}
))
channel = '' channel = ''
title = '' title = ''
@@ -121,99 +225,12 @@ def peliculas(item):
country = '' country = ''
start = '' start = ''
stop = '' stop = ''
if len(titles) >= 20:
break
return itemlist
def listaCanali(item):
itemlist = []
xml = getEpg()
for ch in xml.iter('channel'):
name = ch.attrib['id']
try:
icon = ch.find('icon').attrib['src']
itemlist.append(Item(
channel=item.channel,
action='guidatv',
title=name,
thumbnail=icon
))
except:
pass
return sorted(itemlist, key=lambda x: x.title)
def guidatv(item):
itemlist = []
xml = getEpg()
import calendar
weekday = dict(enumerate(calendar.day_name))
for prog in xml.findall("programme[@channel='" + item.title + "']"):
start = time.strptime(prog.attrib['start'].split(' ')[0], '%Y%m%d%H%M%S')
stop = time.strptime(prog.attrib['stop'].split(' ')[0], '%Y%m%d%H%M%S')
title = prog.find('title')
if title is not None:
title = title.text
episode = prog.find('episode-num')
if episode is not None:
episode = ' (' + episode.text + ')'
else:
episode = ''
desc = prog.find('desc')
if desc is not None:
desc = desc.text
actors = prog.find('credits')
if actors is not None:
actors = [(actor.text, actor.attrib['role'] if 'role' in actor.attrib else '') for actor in actors]
date = prog.find('date')
if date is not None:
date = date.text
genres = prog.find('category')
if genres is not None:
genres = ','.join([cat.text for cat in genres])
thumbnail = prog.find('icon')
if thumbnail is not None:
thumbnail = thumbnail.attrib['src']
country = prog.find('country')
if country is not None:
country = country.text
if episode:
content = 'tvshow'
elif actors:
content = 'movie'
else:
content = ''
itemlist.append(Item(
channel=item.channel,
action='new_search',
search_text=title,
mode='all',
title=title + episode + '\n' + weekday[start.tm_wday] + ' alle ' + str(start.tm_hour).zfill(2) + ':' + str(start.tm_min).zfill(
2) + ' - ' + str(
stop.tm_hour).zfill(2) + ':' + str(stop.tm_min).zfill(2),
year=date if date else '-',
thumbnail=thumbnail if thumbnail else '',
contentType=content,
infoLabels={
'title': title,
'plot': desc if desc else '',
'casta': actors if actors else '',
'genre': genres if genres else '',
'country': country if country else ''
}
))
return itemlist return itemlist
def new_search(item): def new_search(item):
from specials import search from specials import search
item.channel = 'search'
return search.new_search(item) return search.new_search(item)