def buildNameCache(self, show=None): """Build internal name cache :param show: Specify show to build name cache for, if None, just do all shows """ if self.shouldUpdate(): if not show: retrieve_exceptions() for show in sickrage.srCore.SHOWLIST: self.buildNameCache(show) else: self.lastUpdate = datetime.fromtimestamp( int(time.mktime(datetime.today().timetuple()))) sickrage.srLogger.debug( "Building internal name cache for [{}]".format(show.name)) self.clearCache(show.indexerid) for curSeason in [-1] + get_scene_seasons(show.indexerid): for name in list( set( get_scene_exceptions(show.indexerid, season=curSeason) + [show.name])): name = full_sanitizeSceneName(name) if name not in self.cache: self.cache[name] = int(show.indexerid) sickrage.srLogger.debug( "Internal name cache for [{}] set to: [{}]".format( show.name, [ key for key, value in self.cache.items() if value == show.indexerid ][0]))
def get_show(self, name, tryIndexers=False): if not sickrage.srCore.SHOWLIST: return showObj = None fromCache = False if not name: return showObj try: # check cache for show cache = sickrage.srCore.NAMECACHE.retrieveNameFromCache(name) if cache: fromCache = True showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(cache)) # try indexers if not showObj and tryIndexers: showObj = findCertainShow(sickrage.srCore.SHOWLIST, searchIndexerForShowID(full_sanitizeSceneName(name), ui=ShowListUI)[2]) # try scene exceptions if not showObj: ShowID = get_scene_exception_by_name(name)[0] if ShowID: showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(ShowID)) # add show to cache if showObj and not fromCache: sickrage.srCore.NAMECACHE.addNameToCache(name, showObj.indexerid) except Exception as e: sickrage.srLogger.debug("Error when attempting to find show: %s in SiCKRAGE. Error: %r " % (name, repr(e))) return showObj
def buildNameCache(self, show=None): """Build internal name cache :param show: Specify show to build name cache for, if None, just do all shows """ if self.shouldUpdate(): if not show: retrieve_exceptions() for show in sickrage.srCore.SHOWLIST: self.buildNameCache(show) else: self.lastUpdate = datetime.fromtimestamp(int(time.mktime(datetime.today().timetuple()))) sickrage.srLogger.debug("Building internal name cache for [{}]".format(show.name)) self.clearCache(show.indexerid) for curSeason in [-1] + get_scene_seasons(show.indexerid): for name in list(set(get_scene_exceptions( show.indexerid, season=curSeason) + [show.name])): name = full_sanitizeSceneName(name) if name not in self.cache: self.cache[name] = int(show.indexerid) sickrage.srLogger.debug("Internal name cache for [{}] set to: [{}]".format( show.name, [key for key, value in self.cache.items() if value == show.indexerid][0]))
def retrieveNameFromCache(self, name): """ Looks up the given name in the scene_names table in cache.db. :param name: The show name to look up. :return: the TVDB id that resulted from the cache lookup or None if the show wasn't found in the cache """ name = full_sanitizeSceneName(name) if name in self.cache: return int(self.cache[name])
def check_against_names(nameInQuestion, show, season=-1): showNames = [] if season in [-1, 1]: showNames = [show.name] showNames.extend(get_scene_exceptions(show.indexerid, season=season)) for showName in showNames: nameFromList = full_sanitizeSceneName(showName) if nameFromList == nameInQuestion: return True return False
def addNameToCache(self, name, indexer_id=0): """ Adds the show & tvdb id to the scene_names table in cache.db. :param name: The show name to cache :param indexer_id: the TVDB id that this show should be cached with (can be None/0 for unknown) """ # standardize the name we're using to account for small differences in providers name = full_sanitizeSceneName(name) if name not in self.cache: self.cache[name] = int(indexer_id) cache_db.CacheDB().action("INSERT OR REPLACE INTO scene_names (indexer_id, name) VALUES (?, ?)", [indexer_id, name])
def addNameToCache(self, name, indexer_id=0): """ Adds the show & tvdb id to the scene_names table in cache.db. :param name: The show name to cache :param indexer_id: the TVDB id that this show should be cached with (can be None/0 for unknown) """ # standardize the name we're using to account for small differences in providers name = full_sanitizeSceneName(name) if name not in self.cache: self.cache[name] = int(indexer_id) cache_db.CacheDB().action( "INSERT OR REPLACE INTO scene_names (indexer_id, name) VALUES (?, ?)", [indexer_id, name])