Migliorie ricerca globale

This commit is contained in:
mac12m99
2021-05-01 17:07:42 +02:00
parent a52d24edec
commit 1614191d70
4 changed files with 35 additions and 30 deletions

View File

@@ -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(' ', '+')

View File

@@ -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 != '':

View File

@@ -1838,7 +1838,7 @@ msgstr ""
msgctxt "#60422"
msgid "Channels search"
msgstr "Ricerca canali"
msgstr ""
msgctxt "#60423"
msgid "Search"

View File

@@ -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):