From de01fa1e37f873d308a1c33a3789ccf4fd4ff292 Mon Sep 17 00:00:00 2001 From: echel0n Date: Mon, 26 May 2014 11:07:10 -0700 Subject: [PATCH] Fix for scene name repeat bug when displaying show. Added scene exceptions feature, hover over the show name with your mouse to see ALL scene exceceptions currently set for the show. --- gui/slick/interfaces/default/displayShow.tmpl | 4 +- gui/slick/interfaces/default/inc_top.tmpl | 2 +- gui/slick/js/sceneExceptionsTooltip.js | 4 +- sickbeard/dailysearcher.py | 7 +- sickbeard/name_cache.py | 20 ++--- sickbeard/scene_exceptions.py | 84 +++++++++---------- 6 files changed, 57 insertions(+), 64 deletions(-) diff --git a/gui/slick/interfaces/default/displayShow.tmpl b/gui/slick/interfaces/default/displayShow.tmpl index 299b5d61..e19a0f26 100644 --- a/gui/slick/interfaces/default/displayShow.tmpl +++ b/gui/slick/interfaces/default/displayShow.tmpl @@ -22,7 +22,7 @@ - + @@ -54,7 +54,7 @@
-

$show.name

+

$show.name

#if not $show.imdbid ($show.startyear) - $show.runtime min diff --git a/gui/slick/interfaces/default/inc_top.tmpl b/gui/slick/interfaces/default/inc_top.tmpl index c6bb0589..fe1b6e90 100644 --- a/gui/slick/interfaces/default/inc_top.tmpl +++ b/gui/slick/interfaces/default/inc_top.tmpl @@ -305,4 +305,4 @@ a > i.icon-question-sign { background-image: url("$sbRoot/images/glyphicons-half #end for
- #end if + #end if \ No newline at end of file diff --git a/gui/slick/js/sceneExceptionsTooltip.js b/gui/slick/js/sceneExceptionsTooltip.js index b894e739..c1ad1131 100644 --- a/gui/slick/js/sceneExceptionsTooltip.js +++ b/gui/slick/js/sceneExceptionsTooltip.js @@ -1,5 +1,5 @@ $(function () { - $('.showTitle a').each(function () { + $('.title a').each(function () { match = $(this).parent().attr("id").match(/^scene_exception_(\d+)$/); $(this).qtip({ content: { @@ -32,7 +32,7 @@ $(function () { corner: true, method: 'polygon' }, - classes: 'ui-tooltip-rounded ui-tooltip-shadow ui-tooltip-sb' + classes: 'qtip-rounded qtip-shadow ui-tooltip-sb' } }); }); diff --git a/sickbeard/dailysearcher.py b/sickbeard/dailysearcher.py index 6e311508..2df7f78b 100644 --- a/sickbeard/dailysearcher.py +++ b/sickbeard/dailysearcher.py @@ -42,9 +42,6 @@ class DailySearcher(): self.amActive = True - # remove names from cache that link back to active shows that we watch - sickbeard.name_cache.syncNameCache() - logger.log(u"Searching for coming episodes and 1 weeks worth of previously WANTED episodes ...") fromDate = datetime.date.today() - datetime.timedelta(weeks=1) @@ -88,6 +85,10 @@ class DailySearcher(): if len(todaysEps): for show in todaysEps: segment = todaysEps[show] + + # remove show from name cache if marked invalid + sickbeard.name_cache.clearCache(show) + dailysearch_queue_item = sickbeard.search_queue.DailySearchQueueItem(show, segment) sickbeard.searchQueueScheduler.action.add_item(dailysearch_queue_item) #@UndefinedVariable else: diff --git a/sickbeard/name_cache.py b/sickbeard/name_cache.py index 3fb87ce4..a39e5192 100644 --- a/sickbeard/name_cache.py +++ b/sickbeard/name_cache.py @@ -59,20 +59,14 @@ def retrieveShowFromCache(name): if indexerid: return sickbeard.helpers.findCertainShow(sickbeard.showList, int(indexerid)) -def syncNameCache(): - cacheDB = db.DBConnection('cache.db') - - for curShow in sickbeard.showList: - for show_name in set(sickbeard.show_name_helpers.allPossibleShowNames(curShow)): - sqlResult = cacheDB.action("DELETE FROM scene_names WHERE name = ? and indexer_id = ?", [show_name, 0]) - if sqlResult.rowcount > 0: - logger.log(u"Removing invalid record for [" + show_name + "] from cache ...") - break - -def clearCache(): +def clearCache(show=None, season=-1, indexer_id=0): """ Deletes all "unknown" entries from the cache (names with indexer_id of 0). """ cacheDB = db.DBConnection('cache.db') - cacheDB.action("DELETE FROM scene_names WHERE indexer_id = ?", [0]) - + if show: + showNames = sickbeard.show_name_helpers.allPossibleShowNames(show, season=season) + for showName in showNames: + cacheDB.action("DELETE FROM scene_names WHERE name = ? and indexer_id = ?", [showName, indexer_id]) + else: + cacheDB.action("DELETE FROM scene_names WHERE indexer_id = ?", [indexer_id]) \ No newline at end of file diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index 0e1ccd25..9203c496 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -17,6 +17,7 @@ # along with SickRage. If not, see . import re +import threading import sickbeard from lib import adba @@ -38,13 +39,17 @@ def get_scene_exceptions(indexer_id, season=-1): if indexer_id not in exceptionCache or season not in exceptionCache[indexer_id]: myDB = db.DBConnection("cache.db") - exceptions = myDB.select("SELECT show_name FROM scene_exceptions WHERE indexer_id = ? and season = ?", [indexer_id, season]) - exceptionsList = [cur_exception["show_name"] for cur_exception in exceptions] - if not indexer_id in exceptionCache: - exceptionCache[indexer_id] = {} - exceptionCache[indexer_id][season] = exceptionsList + exceptions = myDB.select("SELECT show_name FROM scene_exceptions WHERE indexer_id = ? and season = ?", + [indexer_id, season]) + exceptionsList = list(set([cur_exception["show_name"] for cur_exception in exceptions])) + + if len(exceptionsList): + try: + exceptionCache[indexer_id][season] = exceptionsList + except: + exceptionCache[indexer_id] = {season:exceptionsList} else: - exceptionsList = exceptionCache[indexer_id][season] + exceptionsList = list(set(exceptionCache[indexer_id][season])) if season == 1: # if we where looking for season 1 we can add generic names exceptionsList += get_scene_exceptions(indexer_id, season=-1) @@ -70,14 +75,17 @@ def get_scene_seasons(indexer_id): global exceptionSeasonCache if indexer_id not in exceptionSeasonCache: myDB = db.DBConnection("cache.db") - sqlResults = myDB.select("SELECT DISTINCT(season) as season FROM scene_exceptions WHERE indexer_id = ?", [indexer_id]) + sqlResults = myDB.select("SELECT DISTINCT(season) as season FROM scene_exceptions WHERE indexer_id = ?", + [indexer_id]) exceptionSeasonCache[indexer_id] = [int(x["season"]) for x in sqlResults] return exceptionSeasonCache[indexer_id] + def get_scene_exception_by_name(show_name): return get_scene_exception_by_name_multiple(show_name)[0] + def get_scene_exception_by_name_multiple(show_name): """ Given a show name, return the indexerid of the exception, None if no exception @@ -87,7 +95,9 @@ def get_scene_exception_by_name_multiple(show_name): myDB = db.DBConnection("cache.db") # try the obvious case first - exception_result = myDB.select("SELECT indexer_id, season FROM scene_exceptions WHERE LOWER(show_name) = ? ORDER BY season ASC", [show_name.lower()]) + exception_result = myDB.select( + "SELECT indexer_id, season FROM scene_exceptions WHERE LOWER(show_name) = ? ORDER BY season ASC", + [show_name.lower()]) if exception_result: return [(int(x["indexer_id"]), int(x["season"])) for x in exception_result] @@ -99,7 +109,8 @@ def get_scene_exception_by_name_multiple(show_name): cur_indexer_id = int(cur_exception["indexer_id"]) cur_season = int(cur_exception["season"]) - if show_name.lower() in (cur_exception_name.lower(), sickbeard.helpers.sanitizeSceneName(cur_exception_name).lower().replace('.', ' ')): + if show_name.lower() in ( + cur_exception_name.lower(), sickbeard.helpers.sanitizeSceneName(cur_exception_name).lower().replace('.', ' ')): logger.log(u"Scene exception lookup got indexer id " + str(cur_indexer_id) + u", using that", logger.DEBUG) out.append((cur_indexer_id, cur_season)) if out: @@ -107,18 +118,21 @@ def get_scene_exception_by_name_multiple(show_name): else: return [(None, None)] + def retrieve_exceptions(): """ Looks up the exceptions on github, parses them into a dict, and inserts them into the scene_exceptions table in cache.db. Also clears the scene name cache. """ - global exceptionCache, exceptionSeasonCache + global exceptionCache, exceptionSeasonCache, exceptionIndexerCache exception_dict = {} + exceptionCache = {} + exceptionSeasonCache = {} + exceptionIndexerCache = {} # exceptions are stored on github pages - for indexer in sickbeard.indexerApi().indexers: logger.log(u"Checking for scene exception updates for " + sickbeard.indexerApi(indexer).name + "") @@ -135,7 +149,7 @@ def retrieve_exceptions(): # each exception is on one line with the format indexer_id: 'show name 1', 'show name 2', etc for cur_line in url_data.splitlines(): cur_line = cur_line.decode('utf-8') - indexer_id, sep, aliases = cur_line.partition(':') #@UnusedVariable + indexer_id, sep, aliases = cur_line.partition(':') # @UnusedVariable if not aliases: continue @@ -143,7 +157,7 @@ def retrieve_exceptions(): indexer_id = int(indexer_id) # regex out the list of shows, taking \' into account - #alias_list = [re.sub(r'\\(.)', r'\1', x) for x in re.findall(r"'(.*?)(?