def write_to_db(self, result): if result: with self.add_to_datastore_sempahore: try: ResultDB.create( url=result.get('url'), title=result.get('title'), status_code=result.get('status_code'), h1_1=result.get('h1_1'), h1_2=result.get('h1_2'), h2=result.get('h2'), meta_description=result.get('meta_description'), word_count=result.get('word_count')) except Exception as e: print(e) finally: self.url_count += 1
class UnifiedSearch: def __init__(self): self.id = "plugin.video.unified.search" self.addon = xbmcaddon.Addon(self.id) # self.icon = self.addon.getAddonInfo('icon') self.path = self.addon.getAddonInfo("path") self.language = self.addon.getLocalizedString self.addons_dir = os.path.dirname(self.path) self.addon_db = os.path.join(os.path.dirname(os.path.dirname(self.path)), "userdata/Database/Addons15.db") self.supported_addons = self.get_supported_addons() self.result_db = ResultDB() self.search_db = SearchDB() self.debug = self.addon.getSetting("debug") == "true" def collect(self, results): # INFO: Update counter and compare with a number of supported_addons search_id = self.search_db.get_latest_search_id() counter = self.search_db.update_counter(search_id) self.log("Search counter => %d" % (counter)) # xbmc.sleep(100) if results: for result in results: if "is_playable" in result: self.result_db.create( search_id, result["title"].lstrip(), result["url"], result["image"], result["plugin"], result["is_playable"], ) else: self.result_db.create( search_id, result["title"].lstrip(), result["url"], result["image"], result["plugin"] ) if len(self.supported_addons) == counter: self.log("ALL DONE => %s of %d done" % (counter, len(self.supported_addons))) self.notify("Search", "Done") # xbmc.executebuiltin('XBMC.ReplaceWindow(10025, %s, return)' % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id)) xbmc.executebuiltin( "Container.Update(%s)" % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id) ) else: # self.log("Wait and do nothing => %s of %d done" % (counter, len(self.supported_addons))) return True else: if len(self.supported_addons) == counter: self.notify("Search", "Done") # INFO: Fix for ERROR: Control 50 in window 10025 has been asked to focus, but it can't. xbmc.executebuiltin( "Container.Update(%s)" % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id) ) else: self.log("!!! Nothing found !!!") return True def get_supported_addons(self): disabled_addons = self.get_disabled_addons() supported_addons = [] for addon in os.listdir(self.addons_dir): if ( os.path.isdir(os.path.join(self.addons_dir, addon)) and "plugin.video" in addon and addon not in disabled_addons ): try: if xbmcaddon.Addon(addon).getSetting("unified_search") == "true": supported_addons.append(addon) except Exception, e: self.error("Exception in get_supported_addons") continue return supported_addons
class UnifiedSearch(): def __init__(self): self.id = 'plugin.video.unified.search' self.addon = xbmcaddon.Addon(self.id) # self.icon = self.addon.getAddonInfo('icon') self.path = self.addon.getAddonInfo('path') self.language = self.addon.getLocalizedString self.debug = self.addon.getSetting("debug") == 'true' database_nc = xbmc.translatePath('special://database') try: database = os.path.normpath(database_nc.decode('utf-8')) except: database = os.path.normpath(database_nc) self.addons_dir = os.path.dirname(self.path) db_index = 27 while db_index > 0: db_name = 'Addons%d.db' % db_index db_path = os.path.join(database, db_name) self.log("db_path - %s" % (db_path)) db_index -= 1 if xbmcvfs.exists(db_path): self.addon_db = db_path break self.supported_addons = self.get_supported_addons() self.result_db = ResultDB() self.search_db = SearchDB() def collect(self, results): # INFO: Update counter and compare with a number of supported_addons search_id = self.search_db.get_latest_search_id() if results: for result in results: if 'is_playable' in result: self.result_db.create(search_id, result['title'].lstrip(), result['url'], result['image'], result['plugin'], result['is_playable']) else: self.result_db.create(search_id, result['title'].lstrip(), result['url'], result['image'], result['plugin']) # if len(self.supported_addons) == counter: # self.log("ALL DONE => %s of %d done" % (counter, len(self.supported_addons))) # self.notify("Search", "Done") # xbmc.executebuiltin('XBMC.ReplaceWindow(10025, %s, return)' % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id)) # xbmc.executebuiltin('Container.Update(%s)' % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id)) # else: # self.log("Wait and do nothing => %s of %d done" % (counter, len(self.supported_addons))) # return True # else: # if len(self.supported_addons) == counter: # self.notify("Search", "Done") # INFO: Fix for ERROR: Control 50 in window 10025 has been asked to focus, but it can't. # xbmc.executebuiltin('Container.Update(%s)' % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id)) # else: # self.log("!!! Nothing found !!!") # return True counter = self.search_db.update_counter(search_id) self.log("Search counter => %d" % (counter)) def get_supported_addons(self): disabled_addons = self.get_disabled_addons() self.log("disabled_addons - %s" % (str(disabled_addons))) supported_addons = [] for addon in os.listdir(self.addons_dir): if os.path.isdir( os.path.join(self.addons_dir, addon) ) and 'plugin.video' in addon and addon not in disabled_addons: try: if xbmcaddon.Addon(addon).getSetting( 'unified_search') == 'true': supported_addons.append(addon) except Exception, e: self.error("Exception in get_supported_addons") continue return supported_addons
class UnifiedSearch(): def __init__(self): self.id = 'plugin.video.unified.search' self.addon = xbmcaddon.Addon(self.id) # self.icon = self.addon.getAddonInfo('icon') self.path = self.addon.getAddonInfo('path') self.language = self.addon.getLocalizedString self.addons_dir = os.path.dirname(self.path) self.addon_db = os.path.join( os.path.dirname(os.path.dirname(self.path)), 'userdata/Database/Addons16.db') self.supported_addons = self.get_supported_addons() self.result_db = ResultDB() self.search_db = SearchDB() self.debug = self.addon.getSetting("debug") == 'true' def collect(self, results): # INFO: Update counter and compare with a number of supported_addons search_id = self.search_db.get_latest_search_id() counter = self.search_db.update_counter(search_id) self.log("Search counter => %d" % (counter)) # xbmc.sleep(100) if results: for result in results: if 'is_playable' in result: self.result_db.create(search_id, result['title'].lstrip(), result['url'], result['image'], result['plugin'], result['is_playable']) else: self.result_db.create(search_id, result['title'].lstrip(), result['url'], result['image'], result['plugin']) if len(self.supported_addons) == counter: self.log("ALL DONE => %s of %d done" % (counter, len(self.supported_addons))) self.notify("Search", "Done") # xbmc.executebuiltin('XBMC.ReplaceWindow(10025, %s, return)' % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id)) xbmc.executebuiltin('Container.Update(%s)' % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id)) else: # self.log("Wait and do nothing => %s of %d done" % (counter, len(self.supported_addons))) return True else: if len(self.supported_addons) == counter: self.notify("Search", "Done") # INFO: Fix for ERROR: Control 50 in window 10025 has been asked to focus, but it can't. xbmc.executebuiltin('Container.Update(%s)' % "plugin://%s/?mode=show&search_id=%d" % (self.id, search_id)) else: self.log("!!! Nothing found !!!") return True def get_supported_addons(self): disabled_addons = self.get_disabled_addons() supported_addons = [] for addon in os.listdir(self.addons_dir): if os.path.isdir( os.path.join(self.addons_dir, addon) ) and 'plugin.video' in addon and addon not in disabled_addons: try: if xbmcaddon.Addon(addon).getSetting( 'unified_search') == 'true': supported_addons.append(addon) except Exception, e: self.error("Exception in get_supported_addons") continue return supported_addons