def get_video_id_from_scraper(serie, ask=False, video_type="tv"): """ Hace una busqueda con el scraper seleccionado *tmdb por defecto* por el nombre (y año si esta presente) y presenta una 'ventana' para seleccionar uno. Retorna el item pasado como parametro con algunos infoLabels actualizados @type serie: item @param serie: video para obtener identificar @type ask: bool @param ask: muestra la ventana de información para seleccionar el titulo correcto de la serie/pelicula. @type video_type: str @param video_type: tipo de video para buscar, 'tv' o 'movie' @rtype serie: item @return: devuelve el item 'serie' con la información seteada. """ logger.info("pelisalacarta.platformcode.library get_video_id_from_scraper") from core import tmdb otmdb = tmdb.Tmdb(texto_buscado=serie.infoLabels['title'], tipo=video_type, year=serie.infoLabels.get('year', '')) if ask: select = platformtools.show_video_info(otmdb.get_list_resultados(), caption="[{0}]: Selecciona la serie correcta". format(serie.infoLabels['title']), callback='cb_select_from_tmdb') if select: serie.infoLabels.update(select) logger.debug(tmdb.infoLabels_tostring(serie)) else: if len(otmdb.get_list_resultados()) == 0: return serie # Fijamos los infoLabels serie.infoLabels.update(otmdb.get_list_resultados()[0]) serie.infoLabels['id_Tmdb'] = otmdb.get_list_resultados()[0]['id'] serie.infoLabels['title'] = otmdb.get_list_resultados()[0]['name'].strip() # Si fuesen movies seria title return serie
def find_and_set_infoLabels(item): logger.info() # logger.info("item es %s" % item) p_dialog = None if not item.contentSeason: p_dialog = platformtools.dialog_progress_bg( config.get_localized_string(60296), config.get_localized_string(60293)) global otvdb_global tvdb_result = None title = item.contentSerieName # Si el titulo incluye el (año) se lo quitamos year = scrapertools.find_single_match(title, "^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] if not item.infoLabels.get("tvdb_id"): if not item.infoLabels.get("imdb_id"): otvdb_global = Tvdb(search=title, year=item.infoLabels['year']) else: otvdb_global = Tvdb(imdb_id=item.infoLabels.get("imdb_id")) elif not otvdb_global or otvdb_global.get_id( ) != item.infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=item.infoLabels['tvdb_id']) if not item.contentSeason: p_dialog.update(50, config.get_localized_string(60296), config.get_localized_string(60295)) results, info_load = otvdb_global.get_list_results() logger.debug("results es %s" % results) if not item.contentSeason: p_dialog.update(100, config.get_localized_string(60296), config.get_localized_string(60297) % len(results)) p_dialog.close() if len(results) > 1: tvdb_result = platformtools.show_video_info( results, item=item, scraper=Tvdb, caption=config.get_localized_string(60298) % title) elif len(results) > 0: tvdb_result = results[0] # todo revisar if isinstance(item.infoLabels, InfoLabels): logger.debug("es instancia de infoLabels") infoLabels = item.infoLabels else: logger.debug("NO ES instancia de infoLabels") infoLabels = InfoLabels() if tvdb_result: infoLabels['tvdb_id'] = tvdb_result['id'] infoLabels['url_scraper'] = [ "http://thetvdb.com/index.php?tab=series&id=%s" % infoLabels['tvdb_id'] ] if not info_load: if otvdb_global.get_id() != infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=infoLabels['tvdb_id']) otvdb_global.get_images(infoLabels['tvdb_id'], image="poster") otvdb_global.get_images(infoLabels['tvdb_id'], image="fanart") otvdb_global.get_tvshow_cast(infoLabels['tvdb_id']) item.infoLabels = infoLabels set_infoLabels_item(item) return True else: item.infoLabels = infoLabels return False
def find_and_set_infoLabels(item): logger.info() # logger.info("item es %s" % item) p_dialog = None if not item.contentSeason: p_dialog = platformtools.dialog_progress_bg("Buscando información de la serie", "Espere por favor...") global otvdb_global tvdb_result = None title = item.contentSerieName # Si el titulo incluye el (año) se lo quitamos year = scrapertools.find_single_match(title, "^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] if not item.infoLabels.get("tvdb_id"): if not item.infoLabels.get("imdb_id"): otvdb_global = Tvdb(search=title, year=item.infoLabels['year']) else: otvdb_global = Tvdb(imdb_id=item.infoLabels.get("imdb_id")) elif not otvdb_global or otvdb_global.get_id() != item.infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=item.infoLabels['tvdb_id']) # , tipo=tipo_busqueda, idioma_busqueda="es") if not item.contentSeason: p_dialog.update(50, "Buscando información de la serie", "Obteniendo resultados...") results, info_load = otvdb_global.get_list_results() logger.debug("results es %s" % results) if not item.contentSeason: p_dialog.update(100, "Buscando información de la serie", "Encontrados %s posibles coincidencias" % len(results)) p_dialog.close() if len(results) > 1: tvdb_result = platformtools.show_video_info(results, item=item, scraper=Tvdb, caption="[%s]: Selecciona la serie correcta" % title) elif len(results) > 0: tvdb_result = results[0] # todo revisar if isinstance(item.infoLabels, InfoLabels): logger.debug("es instancia de infoLabels") infoLabels = item.infoLabels else: logger.debug("NO ES instancia de infoLabels") infoLabels = InfoLabels() if tvdb_result: infoLabels['tvdb_id'] = tvdb_result['id'] infoLabels['url_scraper'] = ["http://thetvdb.com/index.php?tab=series&id=%s" % infoLabels['tvdb_id']] if not info_load: if otvdb_global.get_id() != infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=infoLabels['tvdb_id']) otvdb_global.get_images(infoLabels['tvdb_id'], image="poster") otvdb_global.get_images(infoLabels['tvdb_id'], image="fanart") otvdb_global.get_tvshow_cast(infoLabels['tvdb_id']) item.infoLabels = infoLabels set_infoLabels_item(item) return True else: item.infoLabels = infoLabels return False
def find_and_set_infoLabels(item): logger.info() # logger.info("item es %s" % item) p_dialog = None if not item.contentSeason: p_dialog = platformtools.dialog_progress_bg( "Cercando informazioni della serie", "Attendere prego...") global otvdb_global tvdb_result = None title = item.contentSerieName # Si el titulo incluye el (año) se lo quitamos year = scrapertools.find_single_match(title, "^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] if not item.infoLabels.get("tvdb_id"): if not item.infoLabels.get("imdb_id"): otvdb_global = Tvdb(search=title, year=item.infoLabels['year']) else: otvdb_global = Tvdb(imdb_id=item.infoLabels.get("imdb_id")) elif not otvdb_global or otvdb_global.get_id( ) != item.infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=item.infoLabels['tvdb_id'] ) # , tipo=tipo_busqueda, idioma_busqueda="es") if not item.contentSeason: p_dialog.update(50, "Cercando informazioni della serie", "Ottenendo risultati...") results = otvdb_global.get_list_results() logger.debug("results es %s" % results) if not item.contentSeason: p_dialog.update(100, "Cercando informazioni della serie", "Trovate %s possibili corrispondenze" % len(results)) p_dialog.close() if len(results) > 1: tvdb_result = platformtools.show_video_info( results, item=item, scraper=Tvdb, caption="[%s]: Selezionare la serie corretta" % title) elif len(results) > 0: tvdb_result = results[0] # todo revisar if isinstance(item.infoLabels, InfoLabels): logger.debug("es instancia de infoLabels") infoLabels = item.infoLabels else: logger.debug("NO ES instancia de infoLabels") infoLabels = InfoLabels() if tvdb_result: infoLabels['tvdb_id'] = tvdb_result['id'] infoLabels['url_scraper'] = [ "http://thetvdb.com/index.php?tab=series&id=%s" % infoLabels['tvdb_id'] ] if not info_load: if otvdb_global.get_id() != infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=infoLabels['tvdb_id']) otvdb_global.get_images(infoLabels['tvdb_id'], image="poster") otvdb_global.get_images(infoLabels['tvdb_id'], image="fanart") otvdb_global.get_tvshow_cast(infoLabels['tvdb_id']) item.infoLabels = infoLabels set_infoLabels_item(item) return True else: item.infoLabels = infoLabels return False
def find_and_set_infoLabels(item): """ función que se llama para buscar y setear los infolabels :param item: :return: """ global scraper_global logger.debug("item:\n" + item.tostring('\n')) params = {} if item.contentType == "movie": tipo_contenido = "pelicula" title = item.contentTitle # get scraper pelis scraper = Tmdb() # para tmdb tipo_busqueda = "movie" else: tipo_contenido = "serie" title = item.contentSerieName # get scraper series scraper = Tmdb() # para tmdb tipo_busqueda = "tv" # esto ya está en el scraper tmdb # title = re.sub('\[\\\?(B|I|COLOR)\s?[^\]]*\]', '', title) # Si el titulo incluye el (año) se lo quitamos year = scrapertools.find_single_match(title, "^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] scraper_result = None results = [] while not scraper_result: # para tmdb if isinstance(scraper, Tmdb): logger.debug("scraper es Tmbdb") params["texto_buscado"] = title params["tipo"] = tipo_busqueda params["year"] = item.infoLabels['year'] if not results: if not item.infoLabels.get("tmdb_id"): if not item.infoLabels.get("imdb_id"): scraper_global = scraper(**params) else: logger.info("tiene imdb") # para tmdb if isinstance(scraper, Tmdb): params["external_id"] = item.infoLabels.get("imdb_id") params["external_source"] = "imdb_id" scraper_global = scraper(**params) elif not scraper_global or scraper_global.result.get("id") != item.infoLabels['tmdb_id']: # para tmdb if isinstance(scraper, Tmdb): params["id_Tmdb"] = item.infoLabels['tmdb_id'] params["idioma_busqueda"] = "es" scraper_global = scraper(**params) results = scraper_global.get_list_resultados() if len(results) > 1: scraper_result = platformtools.show_video_info(results, item=item, scraper=scraper, caption="[%s]: Selecciona la %s correcta" % (title, tipo_contenido)) elif len(results) > 0: scraper_result = results[0] if scraper_result is None: index = -1 if tipo_contenido == "serie": # Si no lo encuentra la serie por si solo, presentamos una lista de opciones opciones = ["Introducir otro nombre", "Buscar en TheTvDB.com"] index = platformtools.dialog_select("%s no encontrada" % tipo_contenido.capitalize(), opciones) elif platformtools.dialog_yesno("Película no encontrada", "No se ha encontrado la película:", title, '¿Desea introducir otro nombre?'): index = 0 if index < 0: logger.debug("he pulsado 'cancelar' en la ventana '%s no encontrada'" % tipo_contenido.capitalize()) break if index == 0: # "Introducir otro nombre" # Pregunta el titulo it = platformtools.dialog_input(title, "Introduzca el nombre de la %s a buscar" % tipo_contenido) if it is not None: title = it item.infoLabels['year'] = "" # reseteamos los resultados results = [] else: logger.debug("he pulsado 'cancelar' en la ventana 'introduzca el nombre correcto'") break if index == 1: # "Buscar en TheTvDB.com" results = tvdb_series_by_title(title) if isinstance(item.infoLabels, InfoLabels): infoLabels = item.infoLabels else: infoLabels = InfoLabels() if scraper_result: if 'id' in scraper_result: # resultados obtenidos de tmdb infoLabels['tmdb_id'] = scraper_result['id'] infoLabels['url_scraper'] = "https://www.themoviedb.org/tv/%s" % infoLabels['tmdb_id'] item.infoLabels = infoLabels tmdb.set_infoLabels_item(item) elif 'tvdb_id' in scraper_result: # resultados obtenidos de tvdb infoLabels.update(scraper_result) item.infoLabels = infoLabels # logger.debug("item:\n" + item.tostring('\n')) return True else: item.infoLabels = infoLabels return False
def find_and_set_infoLabels(item): logger.info() global omal_global mal_result = None tipos_busqueda_validos = ["ova", "ona", "special", "movie", "tv"] if item.contentType in tipos_busqueda_validos: tipo_busqueda = item.contentType elif item.contentType in ["tvshow"]: tipo_busqueda = "tv" else: tipo_busqueda = "" if tipo_busqueda in ["movie", "special"] or item.contentTitle: tipo_contenido = config.get_localized_string(70283) title = item.contentTitle elif tipo_busqueda in ["tv"] or item.contentSerieName: tipo_contenido = config.get_localized_string(60245) title = item.contentSerieName else: tipo_contenido = "" title = item.title # Si el titulo incluye el (año) se lo quitamos year = scrapertools.find_single_match(title, "^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] # Si no tenemos ID de MAL, buscamos por texto if not item.infoLabels.get("mal_id"): omal_global = MAL(texto_buscado=title, tipo=tipo_busqueda, year=item.infoLabels['year']) # Si hay ID de MAL pero no se ha buscado o el ID de MAL no coincide con el del resultado, buscamos por ID elif not omal_global or str(omal_global.result.get("mal_id")) != item.infoLabels['mal_id']: omal_global = MAL(id_mal=item.infoLabels['mal_id']) results = omal_global.get_results_list() # Si hay más de un resultado, preguntamos cuál es el correcto # Esta acción ocurrirá siempre que no se provea un mal_id (por el contenido relacionado que devuelve) if len(results) > 1: from platformcode import platformtools mal_result = platformtools.show_video_info(results, item=item, caption=config.get_localized_string(60247) % (title, tipo_contenido)) # Si solo hay un resultado, lo seleccionamos elif len(results) > 0: mal_result = results[0] # Comprobaciones if isinstance(item.infoLabels, InfoLabels): infoLabels = item.infoLabels else: infoLabels = InfoLabels() if mal_result: infoLabels['mal_id'] = mal_result['mal_id'] item.infoLabels = infoLabels set_infoLabels_item(item) return True else: item.infoLabels = infoLabels return False
def find_and_set_infoLabels(item): logger.debug() # from core.support import dbg;dbg() # logger.debug("item es %s" % item) p_dialog = None if not item.contentSeason: p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(60296), config.get_localized_string(60293)) global otvdb_global tvdb_result = None title = item.contentSerieName # If the title includes the (year) we will remove it year = scrapertools.find_single_match(title, r"^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] if item.infoLabels.get("tvdb_id", '') in ['', 'None']: if item.infoLabels['year']: otvdb_global = Tvdb(search=title, year=item.infoLabels['year']) elif item.infoLabels.get("imdb_id"): otvdb_global = Tvdb(imdb_id=item.infoLabels.get("imdb_id")) else: otvdb_global = Tvdb(search=title) elif not otvdb_global or otvdb_global.get_id() != item.infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=item.infoLabels['tvdb_id']) if not item.contentSeason: p_dialog.update(50, config.get_localized_string(60296) + '\n' + config.get_localized_string(60295)) results, info_load = otvdb_global.get_list_results() logger.debug("results: %s" % results) if not item.contentSeason: p_dialog.update(100, config.get_localized_string(60296) + '\n' + config.get_localized_string(60297) % len(results)) p_dialog.close() if len(results) > 1: tvdb_result = platformtools.show_video_info(results, item=item, scraper=Tvdb, caption=config.get_localized_string(60298) % title) # if not tvdb_result: # res = platformtools.dialog_info(item, 'tvdb') # if not res.exit: return find_and_set_infoLabels(res) elif len(results) > 0: tvdb_result = results[0] # else: # res = platformtools.dialog_info(item, 'tvdb') # if not res.exit: return find_and_set_infoLabels(res) # todo revisar if isinstance(item.infoLabels, InfoLabels): logger.debug("is an instance of infoLabels") infoLabels = item.infoLabels else: logger.debug("NOT an instance of infoLabels") infoLabels = InfoLabels() if tvdb_result: infoLabels['tvdb_id'] = tvdb_result['id'] infoLabels['url_scraper'] = ["http://thetvdb.com/index.php?tab=series&id=%s" % infoLabels['tvdb_id']] if not info_load: if otvdb_global.get_id() != infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=infoLabels['tvdb_id']) otvdb_global.get_images(infoLabels['tvdb_id'], image="poster") otvdb_global.get_images(infoLabels['tvdb_id'], image="fanart") otvdb_global.get_tvshow_cast(infoLabels['tvdb_id']) item.infoLabels = infoLabels set_infoLabels_item(item) return True else: item.infoLabels = infoLabels return False
def find_and_set_infoLabels(item): logger.info() logger.info("item es %s" % item) if not item.contentSeason: from platformcode import platformtools p_dialog = platformtools.dialog_progress_bg( "Buscando información de la serie", "Espere por favor...") global otvdb_global tvdb_result = None title = item.contentSerieName # Si el titulo incluye el (año) se lo quitamos year = scrapertools.find_single_match(title, "^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] if not item.infoLabels.get("tvdb_id"): if not item.infoLabels.get("imdb_id"): otvdb_global = Tvdb(search=title, year=item.infoLabels['year']) else: otvdb_global = Tvdb(imdb_id=item.infoLabels.get("imdb_id")) elif not otvdb_global or otvdb_global.result.get( "id") != item.infoLabels['tvdb_id']: otvdb_global = Tvdb(tvdb_id=item.infoLabels['tvdb_id'] ) # , tipo=tipo_busqueda, idioma_busqueda="es") if not item.contentSeason: p_dialog.update(50, "Buscando información de la serie", "Obteniendo resultados...") results = otvdb_global.get_list_results() logger.debug("results es %s" % results) if not item.contentSeason: p_dialog.update(100, "Buscando información de la serie", "Encontrados %s posibles coincidencias" % len(results)) p_dialog.close() if len(results) > 1: tvdb_result = platformtools.show_video_info( results, item=item, scraper=Tvdb, caption="[%s]: Selecciona la serie correcta" % title) elif len(results) > 0: tvdb_result = results[0] # todo revisar if isinstance(item.infoLabels, InfoLabels): logger.debug("es instancia de infoLabels") infoLabels = item.infoLabels else: logger.debug("NO ES instancia de infoLabels") infoLabels = InfoLabels() if tvdb_result: infoLabels['tvdb_id'] = tvdb_result['id'] item.infoLabels = infoLabels set_infoLabels_item(item) return True else: item.infoLabels = infoLabels return False
def find_and_set_infoLabels(item): """ función que se llama para buscar y setear los infolabels :param item: :return: """ global scraper_global logger.debug("item:\n" + item.tostring('\n')) params = {} if item.contentType == "movie": tipo_contenido = "pelicula" title = item.contentTitle # get scraper pelis scraper = Tmdb() # para tmdb tipo_busqueda = "movie" else: tipo_contenido = "serie" title = item.contentSerieName # get scraper series scraper = Tmdb() # para tmdb tipo_busqueda = "tv" # esto ya está en el scraper tmdb # title = re.sub('\[\\\?(B|I|COLOR)\s?[^\]]*\]', '', title) # Si el titulo incluye el (año) se lo quitamos year = scrapertools.find_single_match(title, "^.+?\s*(\(\d{4}\))$") if year: title = title.replace(year, "").strip() item.infoLabels['year'] = year[1:-1] scraper_result = None results = [] while not scraper_result: # para tmdb if isinstance(scraper, Tmdb): logger.debug("scraper es Tmbdb") params["texto_buscado"] = title params["tipo"] = tipo_busqueda params["year"] = item.infoLabels['year'] if not results: if not item.infoLabels.get("tmdb_id"): if not item.infoLabels.get("imdb_id"): scraper_global = scraper(**params) else: logger.info("tiene imdb") # para tmdb if isinstance(scraper, Tmdb): params["external_id"] = item.infoLabels.get("imdb_id") params["external_source"] = "imdb_id" scraper_global = scraper(**params) elif not scraper_global or scraper_global.result.get( "id") != item.infoLabels['tmdb_id']: # para tmdb if isinstance(scraper, Tmdb): params["id_Tmdb"] = item.infoLabels['tmdb_id'] params["idioma_busqueda"] = "es" scraper_global = scraper(**params) results = scraper_global.get_list_resultados() if len(results) > 1: scraper_result = platformtools.show_video_info( results, item=item, scraper=scraper, caption="[%s]: Selecciona la %s correcta" % (title, tipo_contenido)) elif len(results) > 0: scraper_result = results[0] if scraper_result is None: index = -1 if tipo_contenido == "serie": # Si no lo encuentra la serie por si solo, presentamos una lista de opciones opciones = ["Introducir otro nombre", "Buscar en TheTvDB.com"] index = platformtools.dialog_select( "%s no encontrada" % tipo_contenido.capitalize(), opciones) elif platformtools.dialog_yesno( "Película no encontrada", "No se ha encontrado la película:", title, '¿Desea introducir otro nombre?'): index = 0 if index < 0: logger.debug( "he pulsado 'cancelar' en la ventana '%s no encontrada'" % tipo_contenido.capitalize()) break if index == 0: # "Introducir otro nombre" # Pregunta el titulo it = platformtools.dialog_input( title, "Introduzca el nombre de la %s a buscar" % tipo_contenido) if it is not None: title = it item.infoLabels['year'] = "" # reseteamos los resultados results = [] else: logger.debug( "he pulsado 'cancelar' en la ventana 'introduzca el nombre correcto'" ) break if index == 1: # "Buscar en TheTvDB.com" results = tvdb_series_by_title(title) if isinstance(item.infoLabels, InfoLabels): infoLabels = item.infoLabels else: infoLabels = InfoLabels() if scraper_result: if 'id' in scraper_result: # resultados obtenidos de tmdb infoLabels['tmdb_id'] = scraper_result['id'] infoLabels[ 'url_scraper'] = "https://www.themoviedb.org/tv/%s" % infoLabels[ 'tmdb_id'] item.infoLabels = infoLabels tmdb.set_infoLabels_item(item) elif 'tvdb_id' in scraper_result: # resultados obtenidos de tvdb infoLabels.update(scraper_result) item.infoLabels = infoLabels # logger.debug("item:\n" + item.tostring('\n')) return True else: item.infoLabels = infoLabels return False