From cfafc0a39f99ddd182437e48e31a1cb7f3c4b11f Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 31 May 2014 23:44:44 -0700 Subject: [PATCH] Scene exceptions for anidb and xem now update once a day, thanks zoggy for pointing that out :) --- sickbeard/databases/cache_db.py | 10 ++++- sickbeard/scene_exceptions.py | 77 +++++++++++++++++++++++++-------- sickbeard/scene_numbering.py | 1 - 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/sickbeard/databases/cache_db.py b/sickbeard/databases/cache_db.py index 52a9d8c4..3f047bc6 100644 --- a/sickbeard/databases/cache_db.py +++ b/sickbeard/databases/cache_db.py @@ -80,4 +80,12 @@ class AddSceneExceptionsCustom(AddSceneExceptionsSeasons): return self.hasColumn("scene_exceptions", "custom") def execute(self): - self.addColumn("scene_exceptions", "custom", "NUMERIC", 0) \ No newline at end of file + self.addColumn("scene_exceptions", "custom", "NUMERIC", 0) + +class AddSceneExceptionsRefresh(AddSceneExceptionsCustom): + def test(self): + return self.hasTable("scene_exceptions_refresh") + + def execute(self): + self.connection.action( + "CREATE TABLE scene_exceptions_refresh (list TEXT, last_refreshed INTEGER)") \ No newline at end of file diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index fd06412b..e89ae6d1 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -17,7 +17,7 @@ # along with SickRage. If not, see . import re -import threading +import time import sickbeard from lib import adba @@ -26,6 +26,9 @@ from sickbeard import name_cache from sickbeard import logger from sickbeard import db +MAX_XEM_AGE_SECS = 86400 # 1 day +MAX_ANIDB_AGE_SECS = 86400 # 1 day + exceptionCache = {} exceptionSeasonCache = {} exceptionIndexerCache = {} @@ -228,35 +231,71 @@ def update_scene_exceptions(indexer_id, scene_exceptions): name_cache.clearCache() def _retrieve_anidb_mainnames(): + global MAX_ANIDB_AGE_SECS + + success = False + anidb_mainNames = {} - for show in sickbeard.showList: - if show.is_anime and show.indexer == 1: - try: - anime = adba.Anime(None, name=show.name, tvdbid=show.indexerid, autoCorrectName=True) - except: - continue - else: - if anime.name and anime.name != show.name: - anidb_mainNames[show.indexerid] = [{anime.name: -1}] + + cacheDB = db.DBConnection('cache.db') + + rows = cacheDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?", + ['anidb']) + if rows: + refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_ANIDB_AGE_SECS) + else: + refresh = True + + if refresh: + for show in sickbeard.showList: + if show.is_anime and show.indexer == 1: + try: + anime = adba.Anime(None, name=show.name, tvdbid=show.indexerid, autoCorrectName=True) + except: + continue + else: + success = True + + if anime.name and anime.name != show.name: + anidb_mainNames[show.indexerid] = [{anime.name: -1}] + + if success: + cacheDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)", + ['anidb', time.time()]) return anidb_mainNames def _xem_excpetions_fetcher(indexer): + global MAX_XEM_AGE_SECS + exception_dict = {} - url = "http://thexem.de/map/allNames?origin=%s&seasonNumbers=1" % sickbeard.indexerApi(indexer).config['xem_origin'] + cacheDB = db.DBConnection('cache.db') - url_data = helpers.getURL(url, json=True) - if url_data is None: - logger.log(u"Check scene exceptions update failed. Unable to get URL: " + url, logger.ERROR) - return exception_dict + rows = cacheDB.select("SELECT last_refreshed FROM scene_exceptions_refresh WHERE list = ?", + ['xem']) + if rows: + refresh = time.time() > (int(rows[0]['last_refreshed']) + MAX_XEM_AGE_SECS) + else: + refresh = True - if url_data['result'] == 'failure': - return exception_dict + if refresh: + url = "http://thexem.de/map/allNames?origin=%s&seasonNumbers=1" % sickbeard.indexerApi(indexer).config['xem_origin'] - for indexerid, names in url_data['data'].items(): - exception_dict[int(indexerid)] = names + url_data = helpers.getURL(url, json=True) + if url_data is None: + logger.log(u"Check scene exceptions update failed. Unable to get URL: " + url, logger.ERROR) + return exception_dict + + if url_data['result'] == 'failure': + return exception_dict + + cacheDB.action("INSERT OR REPLACE INTO scene_exceptions_refresh (list, last_refreshed) VALUES (?,?)", + ['xem', time.time()]) + + for indexerid, names in url_data['data'].items(): + exception_dict[int(indexerid)] = names return exception_dict diff --git a/sickbeard/scene_numbering.py b/sickbeard/scene_numbering.py index 4cc05c48..648adf9f 100644 --- a/sickbeard/scene_numbering.py +++ b/sickbeard/scene_numbering.py @@ -41,7 +41,6 @@ from lib import requests MAX_XEM_AGE_SECS = 86400 # 1 day - def get_scene_numbering(indexer_id, indexer, season, episode, fallback_to_xem=True): """ Returns a tuple, (season, episode), with the scene numbering (if there is one),