From 03253ebe49b28981cc55da37db4e327e2d5ff141 Mon Sep 17 00:00:00 2001 From: Kingbox <37674310+lopezvg@users.noreply.github.com> Date: Wed, 19 Sep 2018 14:49:58 +0200 Subject: [PATCH] =?UTF-8?q?TodoPeliculas:=20redos=C3=B1o=20de=20canal.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.video.alfa/channels/todopeliculas.json | 40 +- plugin.video.alfa/channels/todopeliculas.py | 527 ++++++++++++++---- 2 files changed, 457 insertions(+), 110 deletions(-) diff --git a/plugin.video.alfa/channels/todopeliculas.json b/plugin.video.alfa/channels/todopeliculas.json index b32b7320..c444839e 100644 --- a/plugin.video.alfa/channels/todopeliculas.json +++ b/plugin.video.alfa/channels/todopeliculas.json @@ -3,13 +3,14 @@ "name": "TodoPeliculas", "active": true, "adult": false, - "language": ["cast"], + "language": ["cast", "lat"], "thumbnail": "http://www.todo-peliculas.com/images/logo.png", "banner": "", "version": 1, "categories": [ "movie", - "torrent" + "torrent", + "vos" ], "settings": [ { @@ -20,6 +21,14 @@ "enabled": false, "visible": false }, + { + "id": "modo_grafico", + "type": "bool", + "label": "Buscar información extra en TMDB", + "default": true, + "enabled": true, + "visible": true + }, { "id": "filter_languages", "type": "list", @@ -29,7 +38,11 @@ "visible": true, "lvalues": [ "No filtrar", - "Castellano" + "CAST", + "LAT", + "VO", + "VOS", + "VOSE" ] }, { @@ -55,6 +68,27 @@ "default": true, "enabled": true, "visible": true + }, + { + "id": "timeout_downloadpage", + "type": "list", + "label": "Timeout (segs.) en descarga de páginas o verificación de servidores", + "default": 5, + "enabled": true, + "visible": true, + "lvalues": [ + "None", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10" + ] } ] } \ No newline at end of file diff --git a/plugin.video.alfa/channels/todopeliculas.py b/plugin.video.alfa/channels/todopeliculas.py index b8cf488b..b10bcfda 100644 --- a/plugin.video.alfa/channels/todopeliculas.py +++ b/plugin.video.alfa/channels/todopeliculas.py @@ -1,176 +1,489 @@ # -*- coding: utf-8 -*- -# -*- Channel TodoPeliculas -*- -# -*- Created for Alfa-addon -*- -# -*- By the Alfa Develop Group -*- import re +import sys +import urllib +import urlparse +import time + +from channelselector import get_thumb from core import httptools from core import scrapertools +from core import servertools from core.item import Item +from platformcode import config, logger +from core import tmdb +from lib import generictools from channels import filtertools from channels import autoplay -from platformcode import config, logger -IDIOMAS = {'cast': 'Castellano'} +#IDIOMAS = {'CAST': 'Castellano', 'LAT': 'Latino', 'VO': 'Version Original'} +IDIOMAS = {'Castellano': 'CAST', 'Latino': 'LAT', 'Version Original': 'VO'} list_language = IDIOMAS.values() list_quality = [] list_servers = ['torrent'] host = 'http://www.todo-peliculas.com/' +channel = "todopeliculas" + +categoria = channel.capitalize() +__modo_grafico__ = config.get_setting('modo_grafico', channel) +timeout = config.get_setting('timeout_downloadpage', channel) def mainlist(item): logger.info() - + itemlist = [] + + thumb_cartelera = get_thumb("now_playing.png") + thumb_pelis = get_thumb("channels_movie.png") + thumb_pelis_hd = get_thumb("channels_movie_hd.png") + thumb_buscar = get_thumb("search.png") + thumb_separador = get_thumb("next.png") + thumb_settings = get_thumb("setting_0.png") + autoplay.init(item.channel, list_servers, list_quality) - - itemlist = list() - itemlist.append(item.clone(title="Ultimas", action="list_all", url=host+'torrents')) - itemlist.append(item.clone(title="Por Calidad", action="section", url=host)) - itemlist.append(item.clone(title="Buscar", action="search", url=host+'buscar?searchword=')) - - autoplay.show_option(item.channel, itemlist) + + itemlist.append(Item(channel=item.channel, title="Novedades", action="listado", url=host+'torrents', thumbnail=thumb_cartelera, extra="peliculas")) + itemlist.append(Item(channel=item.channel, title="Por Calidades", action="categorias", url=host, thumbnail=thumb_pelis_hd, extra="peliculas", extra2="categorias")) + itemlist.append(Item(channel=item.channel, title="Buscar...", action="search", url=host+'buscar?searchword=', thumbnail=thumb_buscar, extra="search")) + + itemlist.append(Item(channel=item.channel, url=host, title="[COLOR yellow]Configuración:[/COLOR]", folder=False, thumbnail=thumb_separador)) + + itemlist.append(Item(channel=item.channel, action="configuracion", title="Configurar canal", thumbnail=thumb_settings)) + + autoplay.show_option(item.channel, itemlist) #Activamos Autoplay return itemlist + + +def configuracion(item): + from platformcode import platformtools + ret = platformtools.show_channel_settings() + platformtools.itemlist_refresh() + return -def get_source(url): - logger.info() - data = httptools.downloadpage(url).data - data = re.sub(r'"|\n|\r|\t| |
|\s{2,}', "", data) - return data - - -def list_all(item): +def categorias(item): logger.info() + itemlist = [] + + data = '' + try: + data = re.sub(r"\n|\r|\t| |
|\s{2}|()", "", httptools.downloadpage(item.url, timeout=timeout).data) + data = unicode(data, "utf-8", errors="replace").encode("utf-8") + except: + pass + + patron = '
  • ') - if url_next_page: - itemlist.append(item.clone(title="Siguiente >>", url=host+url_next_page, action='list_all')) - return itemlist - -def section(item): - logger.info() - itemlist = [] - - data = get_source(host) - patron = '
  • <\/a>' + elif item.extra2 == 'categorias': + patron = '
    ' + else: + patron = '
    .*?src="([^"]+)" onload' + + matches = re.compile(patron, re.DOTALL).findall(data) + if not matches and not 'Total: 0 resultados encontrados' in data: #error + item = generictools.web_intervenida(item, data) #Verificamos que no haya sido clausurada + if item.intervencion: #Sí ha sido clausurada judicialmente + item, itemlist = generictools.post_tmdb_episodios(item, itemlist) #Llamamos al método para el pintado del error + return itemlist #Salimos + + logger.error("ERROR 02: LISTADO: Ha cambiado la estructura de la Web " + " / PATRON: " + patron + " / DATA: " + data) + itemlist.append(item.clone(action='', title=item.channel.capitalize() + ': ERROR 02: LISTADO: Ha cambiado la estructura de la Web. Reportar el error con el log')) + break #si no hay más datos, algo no funciona, pintamos lo que tenemos + + #logger.debug("PATRON: " + patron) + #logger.debug(matches) + #logger.debug(data) + + #Buscamos la url de paginado y la última página + patron = 'Siguiente<\/a>' + try: + next_page_url, curr_page = scrapertools.find_single_match(data, patron) + curr_page = int(curr_page) / len(matches) + except: #Si no lo encuentra, lo ponemos a 1 + #logger.error('ERROR 03: LISTADO: Al obtener la paginación: ' + patron + ' / ' + data) + fin = 0 #Forzamos a salir del WHILE al final del FOR + cnt_title = 0 #Evitamos pié de página + curr_page = 1 + next_page_url = item.url + next_page_url = urlparse.urljoin(host, next_page_url) + #logger.debug('curr_page: ' + str(curr_page) + ' / url: ' + next_page_url) + + #Empezamos el procesado de matches + for scrapedtitle, scrapedurl, scrapedthumb in matches: + if item.extra2 == 'categorias': #Cambia el orden de tres parámetros (Categorías) + title = scrapedthumb + url = urlparse.urljoin(host, scrapedtitle) + thumb = scrapedurl + else: #lo estándar + title = scrapedtitle + url = urlparse.urljoin(host, scrapedurl) + thumb = scrapedthumb + + + quality = scrapertools.find_single_match(title, '\[(.*?)\]') #capturamos quality + title = re.sub(r'\[.*?\]', '', title) #y lo borramos de title + + title = title.replace("á", "a").replace("é", "e").replace("í", "i").replace("ó", "o").replace("ú", "u").replace("ü", "u").replace("�", "ñ").replace("ñ", "ñ").replace("ã", "a").replace("&etilde;", "e").replace("ĩ", "i").replace("õ", "o").replace("ũ", "u").replace("ñ", "ñ").replace("’", "'") + + item_local = item.clone() #Creamos copia de Item para trabajar + if item_local.tipo: #... y limpiamos + del item_local.tipo + if item_local.totalItems: + del item_local.totalItems + if item_local.post_num: + del item_local.post_num + if item_local.intervencion: + del item_local.intervencion + if item_local.viewmode: + del item_local.viewmode + item_local.text_bold = True + del item_local.text_bold + item_local.text_color = True + del item_local.text_color + + title_subs = [] #creamos una lista para guardar info importante + item_local.language = [] #iniciamos Lenguaje + item_local.quality = quality #guardamos la calidad, si la hay + item_local.url = url #guardamos el thumb + item_local.thumbnail = thumb #guardamos el thumb + item_local.context = "['buscar_trailer']" + + item_local.contentType = "movie" #por defecto, son películas + item_local.action = "findvideos" + + #Ajustamos los idiomas + if ("-latino-" in url.lower() or "(latino)" in title.lower()) and "LAT" not in item_local.language: + item_local.language += ['LAT'] + elif ('-vos-' in url.lower() or '-vose-' in url.lower() or '(vos)' in title.lower() or '(vose)' in title.lower()) and "VOSE" not in item_local.language: + item_local.language += ['VOSE'] + elif ('-vo-' in url.lower() or '(vo)' in title.lower()) and "VO" not in item_local.language: + item_local.language += ['VO'] + + if item_local.language == []: + item_local.language = ['CAST'] #Por defecto + + title = re.sub(r'\(.*?\)', '', title) #Limpiamos del idioma de title + + #Detectamos info interesante a guardar para después de TMDB + if scrapertools.find_single_match(title, '[m|M].*?serie'): + title = re.sub(r'[m|M]iniserie', '', title) + title_subs += ["Miniserie"] + if scrapertools.find_single_match(title, '[s|S]aga'): + title = re.sub(r'[s|S]aga', '', title) + title_subs += ["Saga"] + if scrapertools.find_single_match(title, '[c|C]olecc'): + title = re.sub(r'[c|C]olecc...', '', title) + title_subs += ["Colección"] + + if "duolog" in title.lower(): + title_subs += ["[Saga]"] + title = title.replace(" Duologia", "").replace(" duologia", "").replace(" Duolog", "").replace(" duolog", "") + if "trilog" in title.lower(): + title_subs += ["[Saga]"] + title = title.replace(" Trilogia", "").replace(" trilogia", "").replace(" Trilog", "").replace(" trilog", "") + if "extendida" in title.lower() or "v.e." in title.lower()or "v e " in title.lower(): + title_subs += ["[V. Extendida]"] + title = title.replace("Version Extendida", "").replace("(Version Extendida)", "").replace("V. Extendida", "").replace("VExtendida", "").replace("V Extendida", "").replace("V.Extendida", "").replace("V Extendida", "").replace("V.E.", "").replace("V E ", "").replace("V:Extendida", "") + + item_local.infoLabels["year"] = '-' #Reseteamos el año para TMDB + + #Limpiamos el título de la basura innecesaria + title = re.sub(r'- $', '', title) + title = re.sub(r'TV|Online|Spanish|Torrent|en Espa\xc3\xb1ol|Español|Latino|Subtitulado|Blurayrip|Bluray rip|\[.*?\]|R2 Pal|\xe3\x80\x90 Descargar Torrent \xe3\x80\x91|Completa|Temporada|Descargar|Torren', '', title, flags=re.IGNORECASE) + + #Terminamos de limpiar el título + title = re.sub(r'\??\s?\d*?\&.*', '', title) + title = re.sub(r'[\(|\[]\s+[\)|\]]', '', title) + title = title.replace('()', '').replace('[]', '').strip().lower().title() + + item_local.from_title = title.strip().lower().title() #Guardamos esta etiqueta para posible desambiguación de título + + #Salvamos el título según el tipo de contenido + if item_local.contentType == "movie": + item_local.contentTitle = title.strip().lower().title() + else: + item_local.contentSerieName = title.strip().lower().title() + + item_local.title = title.strip().lower().title() #Guardamos el título + + #Guarda la variable temporal que almacena la info adicional del título a ser restaurada después de TMDB + item_local.title_subs = title_subs + + #Ahora se filtra por idioma, si procede, y se pinta lo que vale + if config.get_setting('filter_languages', channel) > 0: #Si hay idioma seleccionado, se filtra + itemlist = filtertools.get_link(itemlist, item_local, list_language) + else: + itemlist.append(item_local.clone()) #Si no, pintar pantalla + + cnt_title = len(itemlist) #Contador de líneas añadidas + + #logger.debug(item_local) + + #Pasamos a TMDB la lista completa Itemlist + tmdb.set_infoLabels(itemlist, __modo_grafico__) + + #Llamamos al método para el maquillaje de los títulos obtenidos desde TMDB + item, itemlist = generictools.post_tmdb_listado(item, itemlist) + + # Si es necesario añadir paginacion + if cnt_title >= cnt_tot * cnt_pct: + + title = '%s' % curr_page + + itemlist.append(Item(channel=item.channel, action="listado", title=">> Página siguiente " + title, url=next_page_url, extra=item.extra, extra2=item.extra2)) return itemlist - + def findvideos(item): logger.info() - itemlist = [] - data = get_source(item.url) + itemlist_t = [] #Itemlist total de enlaces + itemlist_f = [] #Itemlist de enlaces filtrados + if not item.language: + item.language = ['CAST'] #Castellano por defecto - second_url = scrapertools.find_single_match(data, '

    )| ", "", httptools.downloadpage(item.url, timeout=timeout).data) + data = unicode(data, "utf-8", errors="replace").encode("utf-8") + except: + pass + + if not data: + logger.error("ERROR 01: FINDVIDEOS: La Web no responde o la URL es erronea: " + item.url) + itemlist.append(item.clone(action='', title=item.channel.capitalize() + ': ERROR 01: FINDVIDEOS:. La Web no responde o la URL es erronea. Si la Web está activa, reportar el error con el log')) + return itemlist #si no hay más datos, algo no funciona, pintamos lo que tenemos - if url != '': - quality = item.quality - title = 'Torrent [%s]' % quality - itemlist.append(item.clone(title=title, url=url, quality=quality, action='play', server='torrent', - language='cast')) + matches = re.compile(patron, re.DOTALL).findall(data) + if not matches: #error + logger.error("ERROR 02: FINDVIDEOS: No hay enlaces o ha cambiado la estructura de la Web " + " / PATRON: " + patron + data) + itemlist.append(item.clone(action='', title=item.channel.capitalize() + ': ERROR 02: FINDVIDEOS: No hay enlaces o ha cambiado la estructura de la Web. Verificar en la Web esto último y reportar el error con el log')) + return itemlist #si no hay más datos, algo no funciona, pintamos lo que tenemos + + #logger.debug("PATRON: " + patron) + #logger.debug(matches) + #logger.debug(data) + + #Llamamos al método para crear el título general del vídeo, con toda la información obtenida de TMDB + item, itemlist = generictools.post_tmdb_findvideos(item, itemlist) - # Requerido para FilterTools + #Ahora tratamos los enlaces .torrent + for scrapedurl in matches: #leemos los torrents con la diferentes calidades + if 'javascript' in scrapedurl: #evitamos la basura + continue + + url = urlparse.urljoin(host, scrapedurl) + #Leemos la siguiente página, que es de verdad donde está el magnet/torrent + try: + data = re.sub(r"\n|\r|\t|\s{2}|()| ", "", httptools.downloadpage(url, timeout=timeout).data) + data = unicode(data, "utf-8", errors="replace").encode("utf-8") + except: + pass + + patron = "window.open\('([^']+)'" + url = scrapertools.find_single_match(data, patron) + if not url: #error + logger.error("ERROR 02: FINDVIDEOS: No hay enlaces o ha cambiado la estructura de la Web " + " / PATRON: " + patron + data) + itemlist.append(item.clone(action='', title=item.channel.capitalize() + ': ERROR 02: FINDVIDEOS: No hay enlaces o ha cambiado la estructura de la Web. Verificar en la Web esto último y reportar el error con el log')) + continue #si no hay más datos, algo no funciona, pasamos al siguiente + + #Generamos una copia de Item para trabajar sobre ella + item_local = item.clone() + + item_local.url = urlparse.urljoin(host, url) + + #Buscamos si ya tiene tamaño, si no, los buscamos en el archivo .torrent + size = scrapertools.find_single_match(item_local.quality, '\s\[(\d+,?\d*?\s\w\s?[b|B])\]') + if not size: + size = generictools.get_torrent_size(item_local.url) #Buscamos el tamaño en el .torrent + if size: + item_local.title = re.sub(r'\s\[\d+,?\d*?\s\w[b|B]\]', '', item_local.title) #Quitamos size de título, si lo traía + item_local.title = '%s [%s]' % (item_local.title, size) #Agregamos size al final del título + size = size.replace('GB', 'G B').replace('Gb', 'G b').replace('MB', 'M B').replace('Mb', 'M b') + item_local.quality = re.sub(r'\s\[\d+,?\d*?\s\w\s?[b|B]\]', '', item_local.quality) #Quitamos size de calidad, si lo traía + item_local.quality = '%s [%s]' % (item_local.quality, size) #Agregamos size al final de la calidad + + #Ahora pintamos el link del Torrent + item_local.title = '[COLOR yellow][?][/COLOR] [COLOR yellow][Torrent][/COLOR] [COLOR limegreen][%s][/COLOR] [COLOR red]%s[/COLOR]' % (item_local.quality, str(item_local.language)) + + #Preparamos título y calidad, quitamos etiquetas vacías + item_local.title = re.sub(r'\s?\[COLOR \w+\]\[\[?\s?\]?\]\[\/COLOR\]', '', item_local.title) + item_local.title = re.sub(r'\s?\[COLOR \w+\]\s?\[\/COLOR\]', '', item_local.title) + item_local.title = item_local.title.replace("--", "").replace("[]", "").replace("()", "").replace("(/)", "").replace("[/]", "").strip() + item_local.quality = re.sub(r'\s?\[COLOR \w+\]\[\[?\s?\]?\]\[\/COLOR\]', '', item_local.quality) + item_local.quality = re.sub(r'\s?\[COLOR \w+\]\s?\[\/COLOR\]', '', item_local.quality).strip() + item_local.quality = item_local.quality.replace("--", "").replace("[]", "").replace("()", "").replace("(/)", "").replace("[/]", "").strip() - itemlist = filtertools.get_links(itemlist, item, list_language) + item_local.alive = "??" #Calidad del link sin verificar + item_local.action = "play" #Visualizar vídeo + item_local.server = "torrent" #Servidor Torrent + + itemlist_t.append(item_local.clone()) #Pintar pantalla, si no se filtran idiomas + + # Requerido para FilterTools + if config.get_setting('filter_languages', channel) > 0: #Si hay idioma seleccionado, se filtra + itemlist_f = filtertools.get_link(itemlist_f, item_local, list_language) #Pintar pantalla, si no está vacío + + #logger.debug("TORRENT: " + scrapedurl + " / title gen/torr: " + item.title + " / " + item_local.title + " / calidad: " + item_local.quality + " / content: " + item_local.contentTitle + " / " + item_local.contentSerieName) + + #logger.debug(item_local) + + if len(itemlist_f) > 0: #Si hay entradas filtradas... + itemlist.extend(itemlist_f) #Pintamos pantalla filtrada + else: + if config.get_setting('filter_languages', channel) > 0 and len(itemlist_t) > 0: #Si no hay entradas filtradas ... + thumb_separador = get_thumb("next.png") #... pintamos todo con aviso + itemlist.append(Item(channel=item.channel, url=host, title="[COLOR red][B]NO hay elementos con el idioma seleccionado[/B][/COLOR]", thumbnail=thumb_separador)) + itemlist.extend(itemlist_t) #Pintar pantalla con todo si no hay filtrado # Requerido para AutoPlay - - autoplay.start(itemlist, item) - - if config.get_videolibrary_support() and len(itemlist) > 0 and item.extra != 'findvideos': - itemlist.append( - Item(channel=item.channel, title='[COLOR yellow]Añadir esta pelicula a la videoteca[/COLOR]', url=item.url, - action="add_pelicula_to_library", extra="findvideos", contentTitle=item.contentTitle)) - + autoplay.start(itemlist, item) #Lanzamos Autoplay + return itemlist +def actualizar_titulos(item): + logger.info() + + item = generictools.update_title(item) #Llamamos al método que actualiza el título con tmdb.find_and_set_infoLabels + + #Volvemos a la siguiente acción en el canal + return item + + def search(item, texto): logger.info() texto = texto.replace(" ", "+") - item.url = item.url + texto - item.type = 'buscar' + + try: + item.url = item.url + texto - if texto != '': - return list_all(item) - else: + if texto != '': + return listado(item) + except: + import sys + for line in sys.exc_info(): + logger.error("{0}".format(line)) return [] - - + + def newest(categoria): logger.info() itemlist = [] item = Item() + try: if categoria in ['torrent', 'peliculas']: - item.url = host+'torrents' + item.url = host + 'torrents' elif categoria == '4k': - item.url = 'http://www.todo-peliculas.com/tags/4k' - item.type='section' - itemlist = list_all(item) + item.url = host + 'tags/4k' + item.extra2 = 'categorias' + item.extra = "peliculas" + item.channel = channel + item.category_new= 'newest' - if itemlist[-1].title == 'Siguiente >>': + itemlist = listado(item) + if ">> Página siguiente" in itemlist[-1].title: itemlist.pop() + + # Se captura la excepción, para no interrumpir al canal novedades si un canal falla except: import sys for line in sys.exc_info(): logger.error("{0}".format(line)) return [] - return itemlist + return itemlist \ No newline at end of file