Fix ricerca globale

This commit is contained in:
mac12m99
2021-10-23 16:29:24 +02:00
parent 0976a8581b
commit 9734b92502
+24 -18
View File
@@ -20,6 +20,8 @@ info_language = ["de", "en", "es", "fr", "it", "pt"] # from videolibrary.json
def_lang = info_language[config.get_setting("info_language", "videolibrary")] def_lang = info_language[config.get_setting("info_language", "videolibrary")]
close_action = False close_action = False
update_lock = threading.Lock() update_lock = threading.Lock()
moduleDict = {}
searchActions = []
def busy(state): def busy(state):
@@ -73,7 +75,7 @@ EPISODESLIST = 200
SERVERLIST = 300 SERVERLIST = 300
class SearchWindow(xbmcgui.WindowXML): class SearchWindow(xbmcgui.WindowXML):
def start(self, item, moduleDict={}, searchActions=[], thActions=None): def start(self, item, thActions=None):
logger.debug() logger.debug()
self.exit = False self.exit = False
self.item = item self.item = item
@@ -142,16 +144,17 @@ class SearchWindow(xbmcgui.WindowXML):
# return immediately all actions that are already loadead # return immediately all actions that are already loadead
for action in self.searchActions: for action in self.searchActions:
yield action yield action
# wait and return as getActionsThread load # wait and return as getActionsThread load
lastLen = len(self.searchActions) lastLen = len(self.searchActions)
while self.thActions.is_alive(): logger.debug('LAST LEN:', lastLen)
while self.thActions.is_alive() or lastLen < len(self.searchActions):
while len(self.searchActions) == lastLen: while len(self.searchActions) == lastLen:
if not self.thActions.is_alive(): if not self.thActions.is_alive():
return return
time.sleep(0.1) # time.sleep(0.1)
yield self.searchActions[lastLen - 1] yield self.searchActions[lastLen - 1]
lastLen = len(self.searchActions) lastLen = len(self.searchActions)
logger.debug(lastLen)
def select(self): def select(self):
logger.debug() logger.debug()
@@ -308,7 +311,7 @@ class SearchWindow(xbmcgui.WindowXML):
percent = 0 percent = 0
self.PROGRESS.setPercent(percent) self.PROGRESS.setPercent(percent)
self.COUNT.setText('%s/%s [%s"]' % (self.count, len(self.searchActions), int(time.time() - self.time))) self.COUNT.setText('%s/%s [%s"]' % (self.count, len(self.searchActions), int(time.time() - self.time)))
if percent == 100: if percent == 100 and not self.thActions.is_alive():
self.channels = [] self.channels = []
self.moduleDict = {} self.moduleDict = {}
self.searchActions = [] self.searchActions = []
@@ -334,11 +337,11 @@ class SearchWindow(xbmcgui.WindowXML):
for searchAction in self.getActions(): for searchAction in self.getActions():
if self.exit: break if self.exit: break
self.search_threads.append(executor.submit(self.get_channel_results, searchAction)) self.search_threads.append(executor.submit(self.get_channel_results, searchAction))
for res in futures.as_completed(self.search_threads): # for res in futures.as_completed(self.search_threads):
if self.exit: break # if self.exit: break
if res.result(): # if res.result():
channel, valid, results = res.result() # channel, valid, results = res.result()
self.update(channel, valid, results) # self.update(channel, valid, results)
# if results: # if results:
# name = results[0].channel # name = results[0].channel
@@ -380,6 +383,7 @@ class SearchWindow(xbmcgui.WindowXML):
try: try:
results, valid, other = search(self.item.text) results, valid, other = search(self.item.text)
if self.exit: return
# if we are on movie search but no valid results is found, and there's a lot of results (more pages), try # if we are on movie search but no valid results is found, and there's a lot of results (more pages), try
# to add year to search text for better filtering # to add year to search text for better filtering
@@ -388,6 +392,7 @@ class SearchWindow(xbmcgui.WindowXML):
logger.debug('retring adding year on channel ' + channel) logger.debug('retring adding year on channel ' + channel)
dummy, valid, dummy = search(self.item.text + " " + str(self.item.infoLabels['year'])) dummy, valid, dummy = search(self.item.text + " " + str(self.item.infoLabels['year']))
if self.exit: return
# some channels may use original title # some channels may use original title
if self.item.mode != 'all' and not valid and self.item.infoLabels.get('originaltitle'): if self.item.mode != 'all' and not valid and self.item.infoLabels.get('originaltitle'):
logger.debug('retring with original title on channel ' + channel) logger.debug('retring with original title on channel ' + channel)
@@ -396,13 +401,12 @@ class SearchWindow(xbmcgui.WindowXML):
import traceback import traceback
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
if self.exit: if self.exit: return
return update_lock.acquire()
# update_lock.acquire()
self.count += 1 self.count += 1
return channel, valid, other if other else results # return channel, valid, other if other else results
# self.update(channel, valid, other if other else results) self.update(channel, valid, other if other else results)
# update_lock.release() update_lock.release()
def makeItem(self, url): def makeItem(self, url):
item = Item().fromurl(url) item = Item().fromurl(url)
@@ -563,6 +567,7 @@ class SearchWindow(xbmcgui.WindowXML):
self.CHANNELS.selectItem(pos) self.CHANNELS.selectItem(pos)
elif action in [LEFT, RIGHT, MOUSEMOVE] and focus in [CHANNELS] and self.CHANNELS.isVisible(): elif action in [LEFT, RIGHT, MOUSEMOVE] and focus in [CHANNELS] and self.CHANNELS.isVisible():
update_lock.acquire()
items = [] items = []
name = self.CHANNELS.getSelectedItem().getLabel() name = self.CHANNELS.getSelectedItem().getLabel()
subpos = int(self.CHANNELS.getSelectedItem().getProperty('position')) subpos = int(self.CHANNELS.getSelectedItem().getProperty('position'))
@@ -572,6 +577,7 @@ class SearchWindow(xbmcgui.WindowXML):
self.RESULTS.reset() self.RESULTS.reset()
self.RESULTS.addItems(items) self.RESULTS.addItems(items)
self.RESULTS.selectItem(subpos) self.RESULTS.selectItem(subpos)
update_lock.release()
elif (action in [DOWN] and focus in [BACK, CLOSE, MENU]) or focus not in [BACK, CLOSE, MENU, SERVERLIST, EPISODESLIST, RESULTS, CHANNELS]: elif (action in [DOWN] and focus in [BACK, CLOSE, MENU]) or focus not in [BACK, CLOSE, MENU, SERVERLIST, EPISODESLIST, RESULTS, CHANNELS]:
if self.SERVERS.isVisible(): self.setFocusId(SERVERLIST) if self.SERVERS.isVisible(): self.setFocusId(SERVERLIST)
@@ -634,7 +640,7 @@ class SearchWindow(xbmcgui.WindowXML):
self.actors() self.actors()
elif search == 'persons': elif search == 'persons':
item = self.item.clone(mode='person_', discovery=self.persons[pos]) item = self.item.clone(mode='person_', discovery=self.persons[pos])
Search(item, self.moduleDict, self.searchActions, self.thActions) Search(item, self.thActions)
if close_action: if close_action:
self.close() self.close()
else: else:
@@ -642,7 +648,7 @@ class SearchWindow(xbmcgui.WindowXML):
if self.item.mode == 'movie': item.contentTitle = self.RESULTS.getSelectedItem().getLabel() if self.item.mode == 'movie': item.contentTitle = self.RESULTS.getSelectedItem().getLabel()
else: item.contentSerieName = self.RESULTS.getSelectedItem().getLabel() else: item.contentSerieName = self.RESULTS.getSelectedItem().getLabel()
Search(item, self.moduleDict, self.searchActions, self.thActions) Search(item, self.thActions)
if close_action: if close_action:
self.close() self.close()