From 20bc92650bbf9f00139964511c8f308c4008040a Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 1 May 2014 03:00:05 -0700 Subject: [PATCH] Fix for issues relating to adding existing shows and nothing happens. --- sickbeard/helpers.py | 48 +++++++++++++++++++++++-------------------- sickbeard/webserve.py | 18 +++++++--------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 4cf00bf7..d67164af 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -283,7 +283,7 @@ def makeDir(path): def searchDBForShow(regShowName): - showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName])) + showNames = list({re.sub('[. -]', ' ', regShowName), regShowName}) myDB = db.DBConnection() @@ -309,36 +309,40 @@ def searchDBForShow(regShowName): return (int(sqlResults[0]["indexer"]), int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"]) def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=None): - showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName])) + showNames = list({re.sub('[. -]', ' ', regShowName), regShowName}) # Query Indexers for each search term and build the list of results - for indexer in sickbeard.indexerApi().indexers if not indexer else [int(indexer)]: + for i in sickbeard.indexerApi().indexers if not indexer else int(indexer or []): # Query Indexers for each search term and build the list of results - lINDEXER_API_PARMS = sickbeard.indexerApi(indexer).api_params.copy() - if ui: lINDEXER_API_PARMS['custom_ui'] = ui - t = sickbeard.indexerApi(indexer).indexer(**lINDEXER_API_PARMS) + lINDEXER_API_PARMS = sickbeard.indexerApi(i).api_params.copy() + if ui is not None: lINDEXER_API_PARMS['custom_ui'] = ui + t = sickbeard.indexerApi(i).indexer(**lINDEXER_API_PARMS) 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(i).name, logger.DEBUG) + + search = t[indexer_id] if indexer_id else t[name] try: - search = t[indexer_id] if indexer_id else t[name] + seriesname = search.seriesname + except: + seriesname = None + try: + series_id = search.id + except: + series_id = None - # add search results - for i in range(len(search)): - part = search[i] - seriesname = part['seriesname'].lower() - - if str(name).lower() == seriesname or (indexer_id and part['id'] == indexer_id): - return [sickbeard.indexerApi(indexer).config['id'], part['id']] - - except KeyError: - if indexer: - break - else: - continue - except Exception: + if not (seriesname and series_id): continue + if str(name).lower() == str(seriesname).lower and not indexer_id: + return (seriesname, int(sickbeard.indexerApi(i).config['id']), int(series_id)) + elif int(indexer_id) == int(series_id): + return (seriesname, int(sickbeard.indexerApi(i).config['id']), int(indexer_id)) + + if indexer: + break + + return (None, None, None) def sizeof_fmt(num): ''' diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index fd9d842c..b4fff86b 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -2072,19 +2072,15 @@ class NewHomeAddShows: if show_name: break # default to TVDB if indexer was not detected - if show_name and (indexer is None or indexer_id is None): - for idx in sickbeard.indexerApi().indexers: - found_info = helpers.searchIndexerForShowID(show_name, idx, indexer_id, ui=classes.ShowListUI) - if found_info: - # set indexer and indexer_id from found info - if indexer is None: - indexer = found_info[0] + if show_name and not (indexer and indexer_id): + (sn,idx,id) = helpers.searchIndexerForShowID(show_name, indexer, indexer_id) - if indexer_id is None: - indexer_id = found_info[1] + # set indexer and indexer_id from found info + if indexer is None and idx: + indexer = idx - # found our info so continue - break + if indexer_id is None and id: + indexer_id = id cur_dir['existing_info'] = (indexer_id, show_name, indexer)