From f4db5f0d408754c2570f3f06814ffa88a8c3b0a8 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 6 Dec 2015 19:36:45 +0800 Subject: [PATCH] Change to generalize xem id fetching --- CHANGES.md | 2 +- sickbeard/indexers/indexer_api.py | 4 ++++ sickbeard/scene_exceptions.py | 17 +++++++---------- sickbeard/scene_numbering.py | 20 ++++++++++---------- sickbeard/show_queue.py | 6 ++---- sickbeard/webserve.py | 5 +++-- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f64e3f86..3c0dbdd0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ ### 0.12.0 (2015-xx-xx xx:xx:xx UTC) -* +* Change to generalize xem id fetching ### 0.11.0 (2015-xx-xx xx:xx:xx UTC) diff --git a/sickbeard/indexers/indexer_api.py b/sickbeard/indexers/indexer_api.py index cd6ddc9e..f2adff71 100644 --- a/sickbeard/indexers/indexer_api.py +++ b/sickbeard/indexers/indexer_api.py @@ -63,3 +63,7 @@ class indexerApi(object): @property def indexers(self): return dict((int(x['id']), x['name']) for x in indexerConfig.values()) + + +def get_xem_supported_indexers(): + return dict((key, value) for (key, value) in indexerConfig.items() if value['xem_origin']) diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index 52b25f89..e8ca621a 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -29,12 +29,12 @@ from sickbeard import name_cache from sickbeard import logger from sickbeard import db from sickbeard.classes import OrderedDefaultdict +from sickbeard.indexers.indexer_api import get_xem_supported_indexers exception_dict = {} anidb_exception_dict = {} xem_exception_dict = {} -xem_tvdb_ids_list = [] -xem_rage_ids_list = [] +xem_ids_list = defaultdict(list) exceptionsCache = {} exceptionsSeasonCache = {} @@ -346,12 +346,9 @@ def _xem_get_ids(indexer_name, xem_origin): def get_xem_ids(): - global xem_tvdb_ids_list - global xem_rage_ids_list + global xem_ids_list - xem_ids = _xem_get_ids('TheTVDB', 'tvdb') - if len(xem_ids): - xem_tvdb_ids_list = xem_ids - xem_ids = _xem_get_ids('TVRage', 'rage') - if len(xem_ids): - xem_rage_ids_list = xem_ids + for indexer in get_xem_supported_indexers().values(): + xem_ids = _xem_get_ids(indexer['name'], indexer['xem_origin']) + if len(xem_ids): + xem_ids_list[indexer['id']] = xem_ids diff --git a/sickbeard/scene_numbering.py b/sickbeard/scene_numbering.py index 8e0deec9..55f4910f 100644 --- a/sickbeard/scene_numbering.py +++ b/sickbeard/scene_numbering.py @@ -30,21 +30,21 @@ import sickbeard from sickbeard import logger from sickbeard import db from sickbeard.exceptions import ex -from sickbeard.indexers.indexer_config import INDEXER_TVDB +from sickbeard.scene_exceptions import xem_ids_list 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), - otherwise returns the xem numbering (if fallback_to_xem is set), otherwise + otherwise returns the xem numbering (if fallback_to_xem is set), otherwise returns the TVDB and TVRAGE numbering. (so the return values will always be set) - + @param indexer_id: int @param season: int @param episode: int @param fallback_to_xem: bool If set (the default), check xem for matches if there is no local scene numbering - @return: (int, int) a tuple with (season, episode) + @return: (int, int) a tuple with (season, episode) """ if None is indexer_id or None is season or None is episode: return season, episode @@ -193,7 +193,7 @@ def set_scene_numbering(indexer_id, indexer, season=None, episode=None, absolute """ Set scene numbering for a season/episode. To clear the scene numbering, leave both sceneSeason and sceneEpisode as None. - + """ if None is indexer_id: return @@ -224,7 +224,7 @@ def find_xem_numbering(indexer_id, indexer, season, episode): """ Returns the scene numbering, as retrieved from xem. Refreshes/Loads as needed. - + @param indexer_id: int @param season: int @param episode: int @@ -276,11 +276,11 @@ def find_xem_absolute_numbering(indexer_id, indexer, absolute_number): def get_indexer_numbering_for_xem(indexer_id, indexer, sceneSeason, sceneEpisode): """ Reverse of find_xem_numbering: lookup a tvdb season and episode using scene numbering - + @param indexer_id: int @param sceneSeason: int @param sceneEpisode: int - @return: (int, int) a tuple of (season, episode) + @return: (int, int) a tuple of (season, episode) """ if None is indexer_id or None is sceneSeason or None is sceneEpisode: return sceneSeason, sceneEpisode @@ -452,7 +452,7 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer): def xem_refresh(indexer_id, indexer, force=False): """ Refresh data from xem for a tv show - + @param indexer_id: int """ if None is indexer_id: @@ -461,7 +461,7 @@ def xem_refresh(indexer_id, indexer, force=False): indexer_id = int(indexer_id) indexer = int(indexer) - if not (indexer_id in sickbeard.scene_exceptions.xem_tvdb_ids_list if INDEXER_TVDB == indexer else sickbeard.scene_exceptions.xem_rage_ids_list): + if indexer_id not in xem_ids_list[indexer]: return # XEM API URL diff --git a/sickbeard/show_queue.py b/sickbeard/show_queue.py index 4bb0d76b..c2ff930b 100644 --- a/sickbeard/show_queue.py +++ b/sickbeard/show_queue.py @@ -29,7 +29,6 @@ from sickbeard import generic_queue from sickbeard import name_cache from sickbeard.exceptions import ex from sickbeard.blackandwhitelist import BlackAndWhiteList -from sickbeard.indexers.indexer_config import INDEXER_TVDB class ShowQueue(generic_queue.GenericQueue): @@ -471,8 +470,7 @@ class QueueItemAdd(ShowQueueItem): # Load XEM data to DB for show sickbeard.scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer, force=True) # check if show has XEM mapping and if user disabled scene numbering during add show, output availability to log - if not self.scene and self.show.indexerid in sickbeard.scene_exceptions.xem_tvdb_ids_list\ - + sickbeard.scene_exceptions.xem_rage_ids_list: + if not self.scene and self.show.indexerid in sickbeard.scene_exceptions.xem_ids_list[self.show.indexer]: logger.log(u'Alternative scene episode numbers were disabled during add show. Edit show to enable them for searching.') # update internal name cache @@ -509,7 +507,7 @@ class QueueItemRefresh(ShowQueueItem): self.show.populateCache() # Load XEM data to DB for show - if self.show.indexerid in sickbeard.scene_exceptions.xem_tvdb_ids_list if INDEXER_TVDB == self.show.indexer else sickbeard.scene_exceptions.xem_rage_ids_list: + if self.show.indexerid in sickbeard.scene_exceptions.xem_ids_list[self.show.indexer]: sickbeard.scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer) self.inProgress = False diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 1d66fc6e..236b8ef4 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -26,6 +26,7 @@ import datetime import dateutil.parser import random import traceback +import itertools from mimetypes import MimeTypes from Cheetah.Template import Template @@ -1276,7 +1277,7 @@ class Home(MainHandler): with showObj.lock: t.show = showObj - t.show_has_scene_map = showObj.indexerid in sickbeard.scene_exceptions.xem_tvdb_ids_list + sickbeard.scene_exceptions.xem_rage_ids_list + t.show_has_scene_map = showObj.indexerid in sickbeard.scene_exceptions.xem_ids_list[showObj.indexer] return t.respond() @@ -2281,7 +2282,7 @@ class NewHomeAddShows(Home): t.blacklist = [] t.groups = [] - t.show_scene_maps = sickbeard.scene_exceptions.xem_tvdb_ids_list + sickbeard.scene_exceptions.xem_rage_ids_list + t.show_scene_maps = list(itertools.chain(*sickbeard.scene_exceptions.xem_ids_list.values())) return t.respond()