»\s?(.*?)\s?«<\/a>' matches = re.compile(patron, re.DOTALL).findall(data) - for capitulo, url in matches: - s = servertools.findvideos(url, skip=True) - if s: - itemlist.append(item.clone(url=s[0][1], action="play", folder=False, server=s[0][2], - title="Ver %s en %s%s" % ( - capitulo.strip(), s[0][2].capitalize(), idioma), - thumbnail2=item.thumbnail, - thumbnail=get_thumb("server_" + s[0][2] + ".png"), - language = idioma)) - else: - import os - for s in servertools.findvideos(data): - itemlist.append(item.clone(url=s[1], action="play", folder=False, server=s[2], - title="Ver en %s%s" % (s[2].capitalize(), idioma), - thumbnail2=item.thumbnail, - thumbnail=os.path.join(config.get_runtime_path(), "resources", "media", - "servers", "server_" + s[2] + ".png"), - language = idioma)) + + if not data or not matches: + logger.error("ERROR 02: FINDVIDEOS: El archivo Torrent no existe o ha cambiado la estructura de la Web " + " / PATRON: " + patron + " / URL: " + item_local.url + " / DATA: " + data) + continue #si no hay más datos, algo no funciona, pasamos a Ver Online + + #logger.debug(patron) + #logger.debug(matches) + #logger.debug(data) + + for scrapedtorrent, scrapedtitle in matches: + quality = item_local.quality + qualityscraped = '' + if not item_local.contentEpisodeNumber and item_local.contentType == 'episode': + item_local.contentEpisodeNumber = 0 + + #Si son episodios múltiples, los listamos con sus títulos + if len(matches) > 1 or len(itemlist_alt) > 1: + if item_local.contentType == 'episode' or item_local.contentType == 'season': + if scrapertools.find_single_match(scrapedtitle, '(\d+[x|X]\d+(?:-\d{1,2})?)'): + qualityscraped = '%s' % scrapertools.find_single_match(scrapedtitle, '(\d+[x|X]\d+(?:-\d{1,2})?)') + if scrapertools.find_single_match(scrapedtitle, '\d+[x|X](\d+)'): + item_local.contentEpisodeNumber = int(scrapertools.find_single_match(scrapedtitle, '\d+[x|X](\d+)')) + elif scrapertools.find_single_match(scrapedtitle, '[c|C]ap.*?(\d+)'): + item_local.contentEpisodeNumber = int(scrapertools.find_single_match(scrapedtitle, '[c|C]ap.*?(\d+)')) + elif scrapertools.find_single_match(scrapedtorrent, '[s|S]\d{1,2}[e|E](\d{1,2})'): + item_local.contentEpisodeNumber = int(scrapertools.find_single_match(scrapedtorrent, '[s|S]\d{1,2}[e|E](\d{1,2})')) + if not qualityscraped: + qualityscraped = '%sx%s' % (str(item_local.contentSeason), str(item_local.contentEpisodeNumber).zfill(2)) + else: + qualityscraped = '%s' % scrapedtitle + + #Si todavía no sabemos el num de Episodio, lo buscamos + if not item_local.contentEpisodeNumber and item_local.contentType == 'episode': + try: + if scrapertools.find_single_match(scrapedtitle, '(\d+)[x|X](\d+)'): + item_local.contentSeason, item_local.contentEpisodeNumber = scrapertools.find_single_match(scrapedtitle, '(\d+)[x|X](\d+)') + qualityscraped = '%sx%s' % (str(item_local.contentSeason), str(item_local.contentEpisodeNumber).zfill(2)) + except: + pass + + #Buscamos calidades + if scrapertools.find_single_match(scrapedtitle, '(\d+p)'): + qualityscraped += ' ' + scrapertools.find_single_match(scrapedtitle, '(\d+p)') + if qualityscraped: + quality = '[%s] %s' % (qualityscraped, item_local.quality) - # Insertar items "Buscar trailer" y "Añadir a la videoteca" - if itemlist and item.extra == "movie": - if item.contentQuality: - title = "%s [%s]" % (item.contentTitle, item.contentQuality) - else: - title = item.contentTitle + #Ahora pintamos el link del Torrent + item_local.url = host + scrapedtorrent + item_local.title = '[COLOR yellow][?][/COLOR] [COLOR yellow][Torrent][/COLOR] [COLOR limegreen][%s][/COLOR] [COLOR red]%s[/COLOR]' % (quality, str(item_local.language)) #Preparamos título de Torrent + item_local.title = re.sub(r'\s\[COLOR \w+\]\[\[?\]?\]\[\/COLOR\]', '', item_local.title) #Quitamos etiquetas vacías + item_local.title = re.sub(r'\s\[COLOR \w+\]\[\/COLOR\]', '', item_local.title) #Quitamos colores vacíos + item_local.alive = "??" #Calidad del link sin verificar + item_local.action = "play" #Visualizar vídeo + item_local.server = "torrent" #Seridor Torrent + + itemlist_alt.append(item_local.clone(quality=quality)) #Pintar pantalla - itemlist.insert(0, item.clone(channel="trailertools", action="buscartrailer", - text_color=color3, title=title, viewmode="list")) + #logger.debug("TORRENT: " + scrapedtorrent + " / title gen/torr: " + item.title + " / " + item_local.title + " / calidad: " + item_local.quality + " / tamaño: " + scrapedsize + " / content: " + item_local.contentTitle + " / " + item_local.contentSerieName) + #logger.debug(item_local) + + #Si son múltiples episodios, ordenamos + if len(itemlist_alt) > 1 and (item.contentType == 'episode' or item.contentType == 'season'): + itemlist_alt = sorted(itemlist_alt, key=lambda it: (int(it.contentSeason), int(it.contentEpisodeNumber))) #clasificamos + tmdb.set_infoLabels(itemlist_alt, True) #TMDB de la lista de episodios + itemlist.extend(itemlist_alt) - if config.get_videolibrary_support(): - itemlist.append(Item(channel=item.channel, title="Añadir película a la videoteca", - action="add_pelicula_to_library", url=item.url, text_color="green", - contentTitle=item.contentTitle, extra="library", thumbnail=thumbnail_host)) + #Ahora tratamos los servidores directo + itemlist_alt = [] + if matches_directo: + for scrapedurl, scrapedquality, scrapedlang in matches_directo: #leemos los torrents con la diferentes calidades + #Generamos una copia de Item para trabajar sobre ella + item_local = item.clone() + + item_local.url = scrapedurl #Guardamos la url intermedia + + if scrapedquality: + item_local.quality = scrapedquality + + if scrapertools.find_single_match(item.quality, '(\[\d+:\d+ h\])'): #Salvamos la duración + item_local.quality += ' [COLOR white]%s' % scrapertools.find_single_match(item.quality, '(\[\d+:\d+ h\])') #Copiamos la duración + + if scrapedlang in IDIOMAS: + item_local.language = ["%s" % IDIOMAS[scrapedlang]] #Salvamos el idioma, si lo hay + + #Leemos la página con el enlace al Servidor + try: + data = re.sub(r"\n|\r|\t|\s{2}|()", "", httptools.downloadpage(item_local.url, timeout=timeout).data) + except: + pass + + patron = '
1 or len(itemlist_alt) > 1) and not servidor in scrapedtitle: + if not capitulo and (item_local.contentType == 'episode' or item_local.contentType == 'season'): + if scrapertools.find_single_match(scrapedtitle, '(\d+[x|X]\d+(?:-\d{1,2})?)'): + qualityscraped = '%s' % scrapertools.find_single_match(scrapedtitle, '(\d+[x|X]\d+(?:-\d{1,2})?)') + if scrapertools.find_single_match(scrapedtitle, '\d+[x|X](\d+)'): + item_local.contentEpisodeNumber = int(scrapertools.find_single_match(scrapedtitle, '\d+[x|X](\d+)')) + elif scrapertools.find_single_match(scrapedtitle, '[c|C]ap.*?(\d+)'): + item_local.contentEpisodeNumber = int(scrapertools.find_single_match(scrapedtitle, '[c|C]ap.*?(\d+)')) + elif scrapertools.find_single_match(scrapedtorrent, '[s|S]\d{1,2}[e|E](\d{1,2})'): + item_local.contentEpisodeNumber = int(scrapertools.find_single_match(scrapedtorrent, '[s|S]\d{1,2}[e|E](\d{1,2})')) + if not qualityscraped: + qualityscraped = '%sx%s' % (str(item_local.contentSeason), str(item_local.contentEpisodeNumber).zfill(2)) + elif capitulo: + if scrapertools.find_single_match(capitulo, '\d+[x|X](\d+)'): + item_local.contentEpisodeNumber = int(scrapertools.find_single_match(scrapedtitle, '\d+[x|X](\d+)')) + qualityscraped = '%s' % capitulo + else: + qualityscraped = '%s' % scrapedtitle + + #Si todavía no sabemos el num de Episodio, lo buscamos + if not item_local.contentEpisodeNumber and item_local.contentType == 'episode': + try: + if scrapertools.find_single_match(scrapedtitle, '(\d+)[x|X](\d+)'): + item_local.contentSeason, item_local.contentEpisodeNumber = scrapertools.find_single_match(scrapedtitle, '(\d+)[x|X](\d+)') + qualityscraped = '%sx%s' % (str(item_local.contentSeason), str(item_local.contentEpisodeNumber).zfill(2)) + except: + pass + + #Buscamos calidades + if scrapertools.find_single_match(scrapedenlace, '(\d+p)'): + qualityscraped += ' ' + scrapertools.find_single_match(scrapedenlace, '(\d+p)') + if qualityscraped: + quality = '[%s] %s' % (qualityscraped, item_local.quality) + + if scrapertools.find_single_match(item.url, '(\d+x\d+.*?\d+x\d+)') and not capitulo and not qualityscraped: + quality = '[%s] %s' % (scrapertools.find_single_match(scrapedenlace, '(\d+x\d+)'), quality) + elif capitulo and not qualityscraped: + quality = '[%s] %s' % (capitulo, quality) + + #Verificamos el si el enlace del servidor está activo + if config.get_setting("hidepremium"): #Si no se aceptan servidore premium, se ignoran + mostrar_server = servertools.is_server_enabled(servidor) + + try: #Obtenemos el enlace + if mostrar_server: + devuelve = servertools.findvideosbyserver(scrapedenlace, servidor) #existe el link ? + if devuelve: + enlace = devuelve[0][1] #Se guarda el link + if not enlace: + continue + + item_local.alive = servertools.check_video_link(enlace, servidor, timeout=timeout) #activo el link ? + #Si el link no está activo se ignora + if item_local.alive == "??": #dudoso + item_local.title = '[COLOR yellow][?][/COLOR] [COLOR yellow][%s][/COLOR] [COLOR limegreen][%s][/COLOR] [COLOR red]%s[/COLOR]' % (servidor.capitalize(), quality, str(item_local.language)) + elif item_local.alive.lower() == "no": #No está activo. Lo preparo, pero no lo pinto + item_local.title = '[COLOR red][%s][/COLOR] [COLOR yellow][%s][/COLOR] [COLOR limegreen][%s][/COLOR] [COLOR red]%s[/COLOR]' % (item_local.alive, servidor.capitalize(), quality, str(item_local.language)) + logger.debug(item_local.alive + ": ALIVE / " + servidor + " / " + enlace) + raise + else: #Sí está activo + item_local.title = '[COLOR yellow][%s][/COLOR] [COLOR limegreen][%s][/COLOR] [COLOR red]%s[/COLOR]' % (servidor.capitalize(), quality, str(item_local.language)) + + #Ahora pintamos el link Directo + item_local.url = enlace + item_local.title = '[COLOR yellow][%s][/COLOR] [COLOR yellow][%s][/COLOR] [COLOR limegreen][%s][/COLOR] [COLOR red]%s[/COLOR]' % (item_local.alive, servidor.capitalize(), quality, str(item_local.language)) #Preparamos título de Directo + item_local.title = re.sub(r'\s\[COLOR \w+\]\[\[?\]?\]\[\/COLOR\]', '', item_local.title) #Quitamos etiquetas vacías + item_local.title = re.sub(r'\s\[COLOR \w+\]\[\/COLOR\]', '', item_local.title) #Quitamos colores vacíos + item_local.action = "play" #Visualizar vídeo + item_local.server = servidor #Seridor Directo + + itemlist_alt.append(item_local.clone(quality=quality)) #Pintar pantalla + except: + pass + + #logger.debug("DIRECTO: " + scrapedenlace + " / title gen/torr: " + item.title + " / " + item_local.title + " / calidad: " + item_local.quality + " / tamaño: " + scrapedsize + " / content: " + item_local.contentTitle + " / " + item_local.contentSerieName) + #logger.debug(item_local) + + #Si son múltiples episodios, ordenamos + if len(itemlist_alt) > 1 and (item.contentType == 'episode' or item.contentType == 'season'): + itemlist_alt = sorted(itemlist_alt, key=lambda it: (int(it.contentSeason), int(it.contentEpisodeNumber))) #clasificamos + tmdb.set_infoLabels(itemlist_alt, True) #TMDB de la lista de episodios + itemlist.extend(itemlist_alt) return itemlist - -def play(item): + +def episodios(item): logger.info() itemlist = [] + + #logger.debug(item) + + curr_page = 1 # Página inicial + last_page = 99999 # Última página inicial + if item.curr_page: + curr_page = int(item.curr_page) # Si viene de una pasada anterior, lo usamos + del item.curr_page # ... y lo borramos + if item.last_page: + last_page = int(item.last_page) # Si viene de una pasada anterior, lo usamos + del item.last_page # ... y lo borramos + url_item = item.url.replace('1-.fx', '%s-.fx').replace('-1.fx', '-%s.fx') + if item.from_title: + item.title = item.from_title + + #Limpiamos num. Temporada y Episodio que ha podido quedar por Novedades + season_display = 0 + if item.contentSeason: + if item.season_colapse: #Si viene del menú de Temporadas... + season_display = item.contentSeason #... salvamos el num de sesión a pintar + item.from_num_season_colapse = season_display + del item.season_colapse + item.contentType = "tvshow" + if item.from_title_season_colapse: + item.title = item.from_title_season_colapse + del item.from_title_season_colapse + if item.infoLabels['title']: + del item.infoLabels['title'] + del item.infoLabels['season'] + if item.contentEpisodeNumber: + del item.infoLabels['episode'] + if season_display == 0 and item.from_num_season_colapse: + season_display = item.from_num_season_colapse - # Cambiamos el thumbnail del server por el de la pelicula - itemlist.append(item.clone(thumbnail=item.thumbnail2)) + # Obtener la información actualizada de la Serie. TMDB es imprescindible para Videoteca + if not item.infoLabels['tmdb_id']: + tmdb.set_infoLabels(item, True) + + modo_ultima_temp_alt = modo_ultima_temp + if item.ow_force == "1": #Si hay un traspaso de canal o url, se actualiza todo + modo_ultima_temp_alt = False + + max_temp = 1 + if item.infoLabels['number_of_seasons']: + max_temp = item.infoLabels['number_of_seasons'] + y = [] + if modo_ultima_temp_alt and item.library_playcounts: #Averiguar cuantas temporadas hay en Videoteca + patron = 'season (\d+)' + matches = re.compile(patron, re.DOTALL).findall(str(item.library_playcounts)) + for x in matches: + y += [int(x)] + max_temp = max(y) + + while curr_page <= last_page: + + # Descarga la página + data = '' + url = url_item % curr_page #Inserto en num de página en la url + try: + data = re.sub(r"\n|\r|\t|\s{2}|()| ", "", httptools.downloadpage(url, timeout=timeout).data) + data = unicode(data, "iso-8859-1", errors="replace").encode("utf-8") + except: #Algún error de proceso, salimos + pass + + if not data: + logger.error("ERROR 01: EPISODIOS: La Web no responde o la URL es erronea" + item.url) + itemlist.append(item.clone(action='', title=item.channel.capitalize() + ': ERROR 01: EPISODIOS:. La Web no responde o la URL es erronea. Si la Web está activa, reportar el error con el log')) + return itemlist + + curr_page += 1 #Apunto ya a la página siguiente + + #Usamos el mismo patrón que en listado + patron = '