Change to generalize xem id fetching

This commit is contained in:
Adam 2015-12-06 19:36:45 +08:00
parent d9445c6c99
commit f4db5f0d40
6 changed files with 27 additions and 27 deletions

View file

@ -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)

View file

@ -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'])

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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()