From 1614191d70db1812cae9a7fc69a5d7f03a194531 Mon Sep 17 00:00:00 2001 From: mac12m99 <10120390+mac12m99@users.noreply.github.com> Date: Sat, 1 May 2021 17:07:42 +0200 Subject: [PATCH] Migliorie ricerca globale --- channels/cineblog01.py | 2 +- platformcode/platformtools.py | 2 +- .../resource.language.en_gb/strings.po | 2 +- specials/globalsearch.py | 59 ++++++++++--------- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/channels/cineblog01.py b/channels/cineblog01.py index 8ec3df0c..2f8e91b6 100644 --- a/channels/cineblog01.py +++ b/channels/cineblog01.py @@ -75,7 +75,7 @@ def newest(categoria): def search(item, text): logger.info("search", text) - if item.contentType == 'tvshow': item.url = host + '/serietv/' + if item.contentType == 'tvshow': item.url = host + '/serietv' else: item.url = host try: item.url = item.url + "/search/" + text.replace(' ', '+') diff --git a/platformcode/platformtools.py b/platformcode/platformtools.py index be976c9b..446cc382 100644 --- a/platformcode/platformtools.py +++ b/platformcode/platformtools.py @@ -602,7 +602,7 @@ def set_context_commands(item, item_url, parent_item, **kwargs): if parent_item.channel == 'globalsearch': context_commands.append( (config.get_localized_string(30155), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({'channel': "favorites", 'action': "addFavourite", 'from_channel': item.channel, 'from_action': item.action})))) # Search in other channels - if item.contentTitle and item.contentType in ['movie', 'tvshow'] and parent_item.channel != 'search' and item.action not in ['play'] and parent_item.action != 'mainlist': + if item.contentTitle and item.contentType in ['movie', 'tvshow'] and parent_item.channel not in ['search', 'globalsearch'] and item.action not in ['play'] and parent_item.action != 'mainlist': # Search in other channels if item.contentSerieName != '': diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index fb0adeb1..39947634 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1838,7 +1838,7 @@ msgstr "" msgctxt "#60422" msgid "Channels search" -msgstr "Ricerca canali" +msgstr "" msgctxt "#60423" msgid "Search" diff --git a/specials/globalsearch.py b/specials/globalsearch.py index 56321ac3..fa8d768e 100644 --- a/specials/globalsearch.py +++ b/specials/globalsearch.py @@ -90,8 +90,8 @@ class SearchWindow(xbmcgui.WindowXML): self.items = [] self.search_threads = [] - if not searchActions: - self.thActions = Thread(target=self.getActions) + if not thActions: + self.thActions = Thread(target=self.getActionsThread()) self.thActions.start() else: self.thActions = thActions @@ -119,17 +119,37 @@ class SearchWindow(xbmcgui.WindowXML): save_search(self.item.text) - def getActions(self): + def getActionsThread(self): logger.debug() - count = 0 self.channelsList = self.get_channels() for channel in self.channelsList: - self.getModule(channel) - count += 1 - percent = (float(count) / len(self.channelsList)) * 100 - if self.thread or self.selected: # window started - self.PROGRESS.setPercent(percent) - self.COUNT.setText('%s/%s' % (count, len(self.channelsList))) + logger.debug(channel) + try: + module = __import__('channels.%s' % channel, fromlist=["channels.%s" % channel]) + mainlist = getattr(module, 'mainlist')(Item(channel=channel, global_search=True)) + action = [elem for elem in mainlist if elem.action == "search" and ( + self.item.mode in ['all', 'person'] or elem.contentType in [self.item.mode, 'undefined'])] + self.moduleDict[channel] = module + self.searchActions += action + except: + import traceback + logger.error('error importing/getting search items of ' + channel) + logger.error(traceback.format_exc()) + + def getActions(self): + # return immediately all actions that are already loadead + for action in self.searchActions: + yield action + + # wait and return as getActionsThread load + lastLen = len(self.searchActions) + while self.thActions.is_alive(): + while len(self.searchActions) == lastLen: + if not self.thActions.is_alive(): + return + time.sleep(0.1) + yield self.searchActions[lastLen] + lastLen = len(self.searchActions) def select(self): logger.debug() @@ -269,7 +289,7 @@ class SearchWindow(xbmcgui.WindowXML): n = list_cat.index('anime') list_cat[n] = 'tvshow' - if self.item.mode == 'all' or self.item.mode in list_cat or self.item.type in list_cat: + if self.item.mode in ['all', 'person'] or self.item.mode in list_cat or self.item.type in list_cat: if config.get_setting("include_in_global_search", channel) and ch_param.get("active", False): channels_list.append(channel) @@ -277,19 +297,6 @@ class SearchWindow(xbmcgui.WindowXML): return channels_list - def getModule(self, channel): - logger.debug() - try: - module = __import__('channels.%s' % channel, fromlist=["channels.%s" % channel]) - mainlist = getattr(module, 'mainlist')(Item(channel=channel, global_search=True)) - action = [elem for elem in mainlist if elem.action == "search" and (self.item.mode == 'all' or elem.contentType in [self.item.mode, 'undefined'])] - self.moduleDict[channel] = module - self.searchActions += action - except: - import traceback - logger.error('error importing/getting search items of ' + channel) - logger.error(traceback.format_exc()) - def timer(self): while self.searchActions: if self.exit: return @@ -316,13 +323,11 @@ class SearchWindow(xbmcgui.WindowXML): logger.debug() self.count = 0 self.LOADING.setVisible(True) - if self.thActions: - self.thActions.join() Thread(target=self.timer).start() try: with futures.ThreadPoolExecutor(max_workers=set_workers()) as executor: - for searchAction in self.searchActions: + for searchAction in self.getActions(): if self.exit: return self.search_threads.append(executor.submit(self.get_channel_results, searchAction)) for ch in futures.as_completed(self.search_threads):