# -*- coding: utf-8 -*- # ------------------------------------------------------------ # Canale film in tv # ------------------------------------------------------------ from datetime import datetime import glob, time, gzip, xbmc, sys from core import filetools, downloadtools, support, scrapertools from core.item import Item if sys.version_info[0] >= 3: from concurrent import futures else: from concurrent_py2 import futures host = "http://epg-guide.com/kltv.gz" blacklisted_genres = ['attualita', 'scienza', 'religione', 'cucina', 'notiziario', 'altro', 'soap opera', 'viaggi', 'economia', 'tecnologia', 'magazine', 'show', 'reality show', 'lifestyle', 'societa', 'wrestling', 'azione', 'Musica', 'real life', 'real adventure', 'dplay original', 'natura', 'news', 'food', 'sport', 'moda', 'arte e cultura', 'crime', 'box set e serie tv', 'casa', 'storia', 'talk show', 'motori', 'attualit\xc3\xa0 e inchiesta', 'documentari', 'musica', 'spettacolo', 'medical', 'talent show', 'sex and love', 'beauty and style', 'news/current affairs', "children's/youth programmes", 'leisure hobbies', 'social/political issues/economics', 'education/science/factual topics', 'undefined content', 'show/game show', 'music/ballet/dance', 'sports', 'arts/culture', 'biografico', 'informazione', 'documentario'] def mainlist(item): support.log() itemlist = [Item(title=support.typo('Film in onda oggi', 'bold'), channel=item.channel, action='category', contentType='movie', thumbnail=support.thumb(thumb='movie.png')), Item(title=support.typo('Serie Tv in onda oggi', 'bold'), channel=item.channel, action='peliculas', contentType='tvshow', thumbnail=support.thumb(thumb='tvshow.png')), Item(title=support.typo('Guida tv per canale', 'bold'), channel=item.channel, action='listaCanali', thumbnail=support.thumb(thumb='on_the_air.png')), Item(title=support.typo('Canali live', 'bold'), channel=item.channel, action='live', thumbnail=support.thumb(thumb='tvshow_on_the_air.png'))] return itemlist def getEpg(): now = datetime.now() fileName = support.config.get_temp_file('guidatv-') + now.strftime('%Y %m %d') archiveName = fileName + '.gz' xmlName = fileName + '.xml' if not filetools.exists(xmlName): support.log('downloading epg') # cancello quelli vecchi for f in glob.glob(support.config.get_temp_file('guidatv-') + '*'): filetools.remove(f, silent=True) # inmemory = io.BytesIO(httptools.downloadpage(host).data) downloadtools.downloadfile(host, archiveName) support.log('opening gzip and writing xml') with gzip.GzipFile(fileobj=filetools.file_open(archiveName, mode='rb', vfs=False)) as f: guide = f.read().replace('\n', ' ').replace('><', '>\n<') with open(xmlName, 'w') as f: f.write(guide) # else: guide = filetools.file_open(xmlName, vfs=False) return guide def category(item): itemlist = [Item(title="Tutti", all=True, channel=item.channel, action='peliculas', contentType=item.contentType)] category = ['Animazione', 'Avventura', 'Azione', 'Biografico', 'Brillante', 'Comico', 'Commedia', 'Crime', 'Documentario', 'Documentaristico', 'Drammatico', 'Famiglia', 'Fantascienza', 'Fantastico', 'Giallo', 'Guerra', 'Horror', 'Mistero', 'Musicale', 'Poliziesco', 'Sexy', 'Storico', 'Thriller', 'Western'] for cat in category: itemlist.append(Item(title=cat, category=cat, channel=item.channel, action='peliculas', contentType=item.contentType)) return support.thumb(itemlist) def peliculas(item, f=None, ): f = getEpg() titles = [item.lastTitle] if not item.titles else item.titles itemlist = [] pag = item.pag if item.pag else 0 channel = '' title = '' episode = '' plot = '' thumbnail = '' actors = [] director = '' year = '' genres = [] genre = '' country = '' skip = False f.seek(pag) line = True while line: line = f.readline() if '([^<]+?)(?: - (?:1\s*\^\s*TV|Prima\s*T[Vv]))?<') if not title or title in titles or title == 'EPG non disponibile': skip = True elif not skip and '(?:\[([^\]]+)\])?(S[0-9]+\s*Ep?[0-9]+)?(?:\s*-\s*)?([^<]+)') if plot: CY = scrapertools.find_single_match(plot, r'(\D{3}) (\d{4})') if CY: country, year = CY director = scrapertools.find_single_match(plot, r'Regia di ([^;|<]+)') if episode and item.contentType == 'movie': skip = True elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<') # actors.append([match[1], match[0]]) # elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<') # if item.contentType == 'movie': # skip = True # elif not skip and '= 40: itemlist.append(item.clone(title=support.typo(support.config.get_localized_string(30992), 'color kod bold'), pag= f.tell(), thumbnail=support.thumb(), lastTitle=titles[-1])) break support.tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True) f.close() return itemlist def listaCanali(item): itemlist = [] f = getEpg() thumbnail = None skip = False line = True while line: line = f.readline() if '([^<]+)<') elif not skip and '([^<]+?)<') if title == 'EPG non disponibile': skip = True elif not skip and '(?:\[([^\]]+)\])?(S[0-9]+\s*Ep?[0-9]+)?(?:\s*-\s*)?([^<]+)') if plot: CY = scrapertools.find_single_match(plot, r'(\D{3}) (\d{4})') if CY: country, year = CY director = scrapertools.find_single_match(plot, r'Regia di ([^;|<]+)') if genre: genres.append(genre) if episode and item.contentType == 'movie':skip = True elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<') # actors.append([match[1], match[0]]) # elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<')) # elif not skip and '([^<]+)<') # elif not skip and '([^<]+)<') # elif not skip and '