def channel_search(queue, channel_parameters, category, tecleado): try: search_results = [] title_search = urllib.unquote_plus(tecleado) exec "from channels import " + channel_parameters[ "channel"] + " as module" mainlist = module.mainlist(Item(channel=channel_parameters["channel"])) for item in mainlist: if item.action != "search" or category and item.extra != category: continue for res_item in module.search(item.clone(), tecleado): title = res_item.fulltitle # Clean up a bit the returned title to improve the fuzzy matching title = re.sub(r'\(.*\)', '', title) # Anything within () title = re.sub(r'\[.*\]', '', title) # Anything within [] # Check if the found title fuzzy matches the searched one if fuzz.WRatio(title_search, title) > 85: res_item.title = "[COLOR azure]" + res_item.title + "[/COLOR][COLOR orange] su [/COLOR][COLOR green]" + channel_parameters[ "title"] + "[/COLOR]" search_results.append(res_item) queue.put(search_results) except: logger.error("No se puede buscar en: " + channel_parameters["title"]) import traceback logger.error(traceback.format_exc())
def search(item, texto): logger.info("[RedAnimeDatabase.py]==> " + item.url + " search " + texto) item.url = "%s/?t=53406771" % host try: itemlist = [] data = httptools.downloadpage(item.url, headers=headers).data patron = r'<a\s*href="(\?t=\d+)"[^>]*?><span[^>]*?><b>([^>]+)</b></span></a>' matches = re.compile(patron, re.DOTALL).findall(data) for scrapedurl, scrapedtitle in matches: scrapedtitle = scrapertools.decodeHtmlentities( scrapedtitle.strip()) # Clean up a bit the returned title to improve the fuzzy matching title_search = re.sub(r'\(.*\)', '', scrapedtitle) # Anything within () title_search = re.sub(r'\[.*\]', '', title_search) # Anything within [] # Check if the found title fuzzy matches the searched one if fuzz.WRatio(texto, title_search) > 85: scrapedurl = urlparse.urljoin(item.url, scrapedurl) itemlist.append( Item(channel=__channel__, action="episodios", title=scrapedtitle, fulltitle=scrapedtitle, url=scrapedurl, thumbnail="", show=scrapedtitle, folder=True)) return itemlist # Continua la ricerca in caso di errore except: import sys for line in sys.exc_info(): logger.error("%s" % line) return []
def do_search(item): logger.info("streamondemand.channels.buscador do_search") tecleado = item.extra mostra = item.fulltitle itemlist = [] channels_path = os.path.join(config.get_runtime_path(), "channels", '*.xml') logger.info("streamondemand.channels.buscador channels_path=" + channels_path) channel_language = config.get_setting("channel_language") logger.info("streamondemand.channels.buscador channel_language=" + channel_language) if channel_language == "": channel_language = "all" logger.info("streamondemand.channels.buscador channel_language=" + channel_language) if config.is_xbmc(): show_dialog = True try: import xbmcgui progreso = xbmcgui.DialogProgressBG() progreso.create("Ricerca di " + mostra) except: show_dialog = False def worker(infile, queue): channel_result_itemlist = [] try: basename_without_extension = os.path.basename(infile)[:-4] # http://docs.python.org/library/imp.html?highlight=imp#module-imp obj = imp.load_source(basename_without_extension, infile[:-4] + ".py") logger.info("streamondemand.channels.buscador cargado " + basename_without_extension + " de " + infile) channel_result_itemlist.extend( obj.search(Item(extra='movie'), tecleado)) for item in channel_result_itemlist: item.title = " [COLOR azure] " + item.title + " [/COLOR] [COLOR orange]su[/COLOR] [COLOR orange]" + basename_without_extension + "[/COLOR]" item.viewmode = "list" except: import traceback logger.error(traceback.format_exc()) queue.put(channel_result_itemlist) channel_files = glob.glob(channels_path) channel_files_tmp = [] for infile in channel_files: basename_without_extension = os.path.basename(infile)[:-4] channel_parameters = channeltools.get_channel_parameters( basename_without_extension) # Non cercare se il canale e inattivo if channel_parameters["active"] != "true": continue # Non Cercare se in canale e escluso dalla ricerca globale if channel_parameters["include_in_global_search"] != "true": continue # Non cercare se il canale e per adulti e se la modalita adulti e disabilitata if channel_parameters["adult"] == "true" and config.get_setting( "adult_mode") == "false": continue # Non cercare se il canale e in una lingua filtrata if channel_language != "all" and channel_parameters[ "language"] != channel_language: continue channel_files_tmp.append(infile) channel_files = channel_files_tmp result = Queue.Queue() threads = [ threading.Thread(target=worker, args=(infile, result)) for infile in channel_files ] start_time = int(time.time()) for t in threads: t.daemon = True # NOTE: setting dameon to True allows the main thread to exit even if there are threads still running t.start() number_of_channels = len(channel_files) completed_channels = 0 while completed_channels < number_of_channels: delta_time = int(time.time()) - start_time if len(itemlist) <= 0: timeout = None # No result so far,lets the thread to continue working until a result is returned elif delta_time >= TIMEOUT_TOTAL: break # At least a result matching the searched title has been found, lets stop the search else: timeout = TIMEOUT_TOTAL - delta_time # Still time to gather other results if show_dialog: progreso.update(completed_channels * 100 / number_of_channels) try: result_itemlist = result.get(timeout=timeout) completed_channels += 1 except: # Expired timeout raise an exception break for item in result_itemlist: title = item.fulltitle # Clean up a bit the returned title to improve the fuzzy matching title = re.sub(r'\(.*\)', '', title) # Anything within () title = re.sub(r'\[.*\]', '', title) # Anything within [] # Check if the found title fuzzy matches the searched one if fuzz.WRatio(mostra, title) > 85: itemlist.append(item) if show_dialog: progreso.close() itemlist = sorted(itemlist, key=lambda item: item.fulltitle) return itemlist
def do_search(item): logger.info("streamondemand.channels.buscador do_search") tecleado = item.extra mostra = item.fulltitle itemlist = [] import os import glob import imp from lib.fuzzywuzzy import fuzz import threading import Queue import time import re master_exclude_data_file = os.path.join(config.get_runtime_path(), "resources", "sodsearch.txt") logger.info("streamondemand.channels.buscador master_exclude_data_file=" + master_exclude_data_file) channels_path = os.path.join(config.get_runtime_path(), "channels", '*.py') logger.info("streamondemand.channels.buscador channels_path=" + channels_path) excluir = "" if os.path.exists(master_exclude_data_file): logger.info( "streamondemand.channels.buscador Encontrado fichero exclusiones") fileexclude = open(master_exclude_data_file, "r") excluir = fileexclude.read() fileexclude.close() else: logger.info( "streamondemand.channels.buscador No encontrado fichero exclusiones" ) excluir = "seriesly\nbuscador\ntengourl\n__init__" if config.is_xbmc(): show_dialog = True try: import xbmcgui progreso = xbmcgui.DialogProgressBG() progreso.create("Ricerca di " + mostra) except: show_dialog = False def worker(infile, queue): channel_result_itemlist = [] try: basename_without_extension = os.path.basename(infile)[:-3] # http://docs.python.org/library/imp.html?highlight=imp#module-imp obj = imp.load_source(basename_without_extension, infile) logger.info("streamondemand.channels.buscador cargado " + basename_without_extension + " de " + infile) channel_result_itemlist.extend(obj.search(Item(), tecleado)) for item in channel_result_itemlist: item.title = " [COLOR azure] " + item.title + " [/COLOR] [COLOR orange]su[/COLOR] [COLOR green]" + basename_without_extension + "[/COLOR]" item.viewmode = "list" except: import traceback logger.error(traceback.format_exc()) queue.put(channel_result_itemlist) channel_files = [ infile for infile in glob.glob(channels_path) if os.path.basename(infile)[:-3] not in excluir ] result = Queue.Queue() threads = [ threading.Thread(target=worker, args=(infile, result)) for infile in channel_files ] start_time = int(time.time()) for t in threads: t.daemon = True # NOTE: setting dameon to True allows the main thread to exit even if there are threads still running t.start() number_of_channels = len(channel_files) completed_channels = 0 while completed_channels < number_of_channels: delta_time = int(time.time()) - start_time if len(itemlist) <= 0: timeout = None # No result so far,lets the thread to continue working until a result is returned elif delta_time >= TIMEOUT_TOTAL: break # At least a result matching the searched title has been found, lets stop the search else: timeout = TIMEOUT_TOTAL - delta_time # Still time to gather other results if show_dialog: progreso.update(completed_channels * 100 / number_of_channels) try: result_itemlist = result.get(timeout=timeout) completed_channels += 1 except: # Expired timeout raise an exception break for item in result_itemlist: title = item.fulltitle # Clean up a bit the returned title to improve the fuzzy matching title = re.sub(r'\(.*\)', '', title) # Anything within () title = re.sub(r'\[.*\]', '', title) # Anything within [] # Check if the found title fuzzy matches the searched one if fuzz.WRatio(mostra, title) > 85: itemlist.append(item) if show_dialog: progreso.close() itemlist = sorted(itemlist, key=lambda item: item.fulltitle) return itemlist
def do_search(item): logger.info("streamondemand-pureita.channels.saghe do_search") tecleado = item.extra mostra = item.fulltitle itemlist = [] channels_path = os.path.join(config.get_runtime_path(), "channels", '*.xml') logger.info("streamondemand-pureita.channels.buscador channels_path=" + channels_path) channel_language = config.get_setting("channel_language") logger.info("streamondemand-pureita.channels.buscador channel_language=" + channel_language) if channel_language == "": channel_language = "all" logger.info( "streamondemand-pureita.channels.buscador channel_language=" + channel_language) if config.is_xbmc(): show_dialog = True try: import xbmcgui progreso = xbmcgui.DialogProgressBG() progreso.create("Ricerca di " + mostra) except: show_dialog = False def worker(infile, queue): channel_result_itemlist = [] try: basename_without_extension = os.path.basename(infile)[:-4] # http://docs.python.org/library/imp.html?highlight=imp#module-imp obj = imp.load_source(basename_without_extension, infile[:-4] + ".py") logger.info("streamondemand-pureita.channels.buscador cargado " + basename_without_extension + " de " + infile) channel_result_itemlist.extend(obj.search(Item(), tecleado)) for item in channel_result_itemlist: item.title = " [COLOR azure] " + item.title + " [/COLOR] [COLOR orange]su[/COLOR] [COLOR green]" + basename_without_extension + "[/COLOR]" item.viewmode = "list" except: import traceback logger.error(traceback.format_exc()) queue.put(channel_result_itemlist) channel_files = glob.glob(channels_path) channel_files_tmp = [] for infile in channel_files: basename_without_extension = os.path.basename(infile)[:-4] channel_parameters = channeltools.get_channel_parameters( basename_without_extension) # No busca si es un canal inactivo if channel_parameters["active"] != "true": continue # No busca si es un canal excluido de la busqueda global if channel_parameters["include_in_global_search"] != "true": continue # No busca si es un canal para adultos, y el modo adulto está desactivado if channel_parameters["adult"] == "true" and config.get_setting( "adult_mode") == "false": continue # No busca si el canal es en un idioma filtrado if channel_language != "all" and channel_parameters[ "language"] != channel_language: continue channel_files_tmp.append(infile) channel_files = channel_files_tmp result = Queue.Queue() threads = [ threading.Thread(target=worker, args=(infile, result)) for infile in channel_files ] for t in threads: t.start() number_of_channels = len(channel_files) for index, t in enumerate(threads): percentage = index * 100 / number_of_channels if show_dialog: progreso.update(percentage, ' Ricerca di "' + mostra + '"') t.join() itemlist.extend(result.get()) itemlist = sorted([ item for item in itemlist if fuzz.WRatio(mostra, item.fulltitle) > 85 ], key=lambda Item: Item.title) if show_dialog: progreso.close() return itemlist
def do_search(item): logger.info("streamondemand.channels.saghe do_search") tecleado = item.extra mostra = item.fulltitle itemlist = [] import os import glob import imp from lib.fuzzywuzzy import fuzz import threading import Queue master_exclude_data_file = os.path.join(config.get_runtime_path(), "resources", "sodsearch.txt") logger.info("streamondemand.channels.buscador master_exclude_data_file=" + master_exclude_data_file) channels_path = os.path.join(config.get_runtime_path(), "channels", '*.py') logger.info("streamondemand.channels.buscador channels_path=" + channels_path) excluir = "" if os.path.exists(master_exclude_data_file): logger.info( "streamondemand.channels.buscador Encontrado fichero exclusiones") fileexclude = open(master_exclude_data_file, "r") excluir = fileexclude.read() fileexclude.close() else: logger.info( "streamondemand.channels.buscador No encontrado fichero exclusiones" ) excluir = "seriesly\nbuscador\ntengourl\n__init__" if config.is_xbmc(): show_dialog = True try: import xbmcgui progreso = xbmcgui.DialogProgressBG() progreso.create("Ricerca di " + mostra) except: show_dialog = False def worker(infile, queue): channel_result_itemlist = [] try: basename_without_extension = os.path.basename(infile)[:-3] # http://docs.python.org/library/imp.html?highlight=imp#module-imp obj = imp.load_source(basename_without_extension, infile) logger.info("streamondemand.channels.buscador cargado " + basename_without_extension + " de " + infile) channel_result_itemlist.extend(obj.search(Item(), tecleado)) for item in channel_result_itemlist: item.title = " [COLOR azure] " + item.title + " [/COLOR] [COLOR orange]su[/COLOR] [COLOR green]" + basename_without_extension + "[/COLOR]" item.viewmode = "list" except: import traceback logger.error(traceback.format_exc()) queue.put(channel_result_itemlist) channel_files = [ infile for infile in glob.glob(channels_path) if os.path.basename(infile)[:-3] not in excluir ] result = Queue.Queue() threads = [ threading.Thread(target=worker, args=(infile, result)) for infile in channel_files ] for t in threads: t.start() number_of_channels = len(channel_files) for index, t in enumerate(threads): percentage = index * 100 / number_of_channels if show_dialog: progreso.update(percentage, ' Sto cercando "' + mostra + '"') t.join() itemlist.extend(result.get()) itemlist = sorted([ item for item in itemlist if fuzz.WRatio(mostra, item.fulltitle) > 85 ], key=lambda Item: Item.title) if show_dialog: progreso.close() return itemlist