Fixed up code for searching indexers for show id which fixes a bug that was present in our post processing code

This commit is contained in:
echel0n 2014-03-25 19:41:28 -07:00
parent 381f2e9e1a
commit ab124158a4
3 changed files with 38 additions and 51 deletions

View file

@ -300,52 +300,39 @@ def searchDBForShow(regShowName, indexer_id=None):
return None return None
def searchIndexersForShow(regShowName, indexer=None, indexer_id=None): def searchIndexerForShowID(regShowName, indexer, indexer_id=None):
showNames = [re.sub('[. -]', ' ', regShowName), regShowName] showNames = [re.sub('[. -]', ' ', regShowName), regShowName]
# check for indexer preset
try:
indexers = [int(indexer)]
except:
indexers = sickbeard.indexerApi().indexers
# Query Indexers for each search term and build the list of results # Query Indexers for each search term and build the list of results
for indexer in indexers: lINDEXER_API_PARMS = {'indexer': indexer}
def searchShows(): lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI
lINDEXER_API_PARMS = {'indexer': indexer} t = sickbeard.indexerApi(**lINDEXER_API_PARMS)
lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI
t = sickbeard.indexerApi(**lINDEXER_API_PARMS)
for name in showNames: for name in showNames:
logger.log(u"Trying to find " + name + " on " + sickbeard.indexerApi(indexer).name, logger.DEBUG) logger.log(u"Trying to find " + name + " on " + sickbeard.indexerApi(indexer).name, logger.DEBUG)
try: try:
if indexer_id: if indexer_id:
search = t[indexer_id] search = t[indexer_id]
else: else:
search = t[name] search = t[name]
if isinstance(search, dict): if isinstance(search, dict):
search = [search] search = [search]
# add search results # add search results
for i in range(len(search)): for i in range(len(search)):
part = search[i] part = search[i]
seriesname = part['seriesname'].encode('UTF-8').lower() seriesname = part['seriesname'].encode('UTF-8').lower()
name = name.encode('UTF-8').lower() name = name.encode('UTF-8').lower()
if (seriesname == name) or (indexer_id is not None and part['id'] == indexer_id): if (seriesname == name) or (indexer_id is not None and part['id'] == indexer_id):
return [t.config['id'], part['id']] return [t.config['id'], part['id']]
except KeyError, e: except KeyError, e:
break break
except Exception, e:
continue
# search indexers for shows
found = searchShows()
if found: return found
except Exception, e:
continue
def sizeof_fmt(num): def sizeof_fmt(num):
''' '''

View file

@ -518,22 +518,20 @@ class PostProcessor(object):
self._log(u"Looking up " + cur_name + u" in the DB", logger.DEBUG) self._log(u"Looking up " + cur_name + u" in the DB", logger.DEBUG)
db_result = helpers.searchDBForShow(cur_name) db_result = helpers.searchDBForShow(cur_name)
if db_result: if db_result:
self._log(u"Lookup successful, using " + db_result[0] + " id " + str(db_result[1]), logger.DEBUG) self._log(u"Lookup successful, using " + sickbeard.indexerApi(db_result[0]).name + " id " + str(
db_result[1]),
logger.DEBUG)
_finalize(parse_result) _finalize(parse_result)
return (int(db_result[1]), season, episodes) return (int(db_result[1]), season, episodes)
# see if we can find the name on the Indexer # see if we can find the name on the Indexer
for cur_name in name_list: for cur_name in name_list:
foundInfo = helpers.searchIndexersForShow(cur_name, indexer=self.indexer) foundInfo = helpers.searchIndexerForShowID(cur_name, self.indexer)
if foundInfo: if foundInfo:
indexer_id = foundInfo[1] indexer_id = foundInfo[1]
self._log( self._log(
u"Lookup successful, using " + sickbeard.indexerApi(self.indexer).name + " id " + str(indexer_id), u"Lookup successful, using " + sickbeard.indexerApi(self.indexer).name + " id " + str(indexer_id),
logger.DEBUG) logger.DEBUG)
# return found results
_finalize(parse_result) _finalize(parse_result)
return (indexer_id, season, episodes) return (indexer_id, season, episodes)
@ -597,7 +595,6 @@ class PostProcessor(object):
if (showObj != None): if (showObj != None):
# set the language of the show # set the language of the show
indexer_lang = showObj.lang indexer_lang = showObj.lang
self.indexer = int(showObj.indexer)
except exceptions.MultipleShowObjectsException: except exceptions.MultipleShowObjectsException:
raise #TODO: later I'll just log this, for now I want to know about it ASAP raise #TODO: later I'll just log this, for now I want to know about it ASAP

View file

@ -2068,15 +2068,18 @@ class NewHomeAddShows:
# default to TVDB if indexer was not detected # default to TVDB if indexer was not detected
if show_name and (indexer is None or indexer_id is None): if show_name and (indexer is None or indexer_id is None):
found_info = helpers.searchIndexersForShow(show_name, indexer_id=indexer_id) for idx in sickbeard.indexerApi().indexers:
found_info = helpers.searchIndexerForShowID(show_name, idx, indexer_id)
if found_info:
# set indexer and indexer_id from found info
if indexer is None:
indexer = found_info[0]
if found_info: if indexer_id is None:
# set indexer and indexer_id from found info indexer_id = found_info[1]
if indexer is None:
indexer = found_info[0]
if indexer_id is None: # found our info so continue
indexer_id = found_info[1] break
cur_dir['existing_info'] = (indexer_id, show_name, indexer) cur_dir['existing_info'] = (indexer_id, show_name, indexer)