diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index df386156..c871c3a6 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -300,52 +300,39 @@ def searchDBForShow(regShowName, indexer_id=None): return None -def searchIndexersForShow(regShowName, indexer=None, indexer_id=None): +def searchIndexerForShowID(regShowName, indexer, indexer_id=None): 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 - for indexer in indexers: - def searchShows(): - lINDEXER_API_PARMS = {'indexer': indexer} - lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI - t = sickbeard.indexerApi(**lINDEXER_API_PARMS) + lINDEXER_API_PARMS = {'indexer': indexer} + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + t = sickbeard.indexerApi(**lINDEXER_API_PARMS) - for name in showNames: - logger.log(u"Trying to find " + name + " on " + sickbeard.indexerApi(indexer).name, logger.DEBUG) - try: - if indexer_id: - search = t[indexer_id] - else: - search = t[name] + for name in showNames: + logger.log(u"Trying to find " + name + " on " + sickbeard.indexerApi(indexer).name, logger.DEBUG) + try: + if indexer_id: + search = t[indexer_id] + else: + search = t[name] - if isinstance(search, dict): - search = [search] + if isinstance(search, dict): + search = [search] - # add search results - for i in range(len(search)): - part = search[i] - seriesname = part['seriesname'].encode('UTF-8').lower() - name = name.encode('UTF-8').lower() + # add search results + for i in range(len(search)): + part = search[i] + seriesname = part['seriesname'].encode('UTF-8').lower() + name = name.encode('UTF-8').lower() - if (seriesname == name) or (indexer_id is not None and part['id'] == indexer_id): - return [t.config['id'], part['id']] + if (seriesname == name) or (indexer_id is not None and part['id'] == indexer_id): + return [t.config['id'], part['id']] - except KeyError, e: - break - - except Exception, e: - continue - - # search indexers for shows - found = searchShows() - if found: return found + except KeyError, e: + break + except Exception, e: + continue def sizeof_fmt(num): ''' diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 15e27276..bf18b8bf 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -518,22 +518,20 @@ class PostProcessor(object): self._log(u"Looking up " + cur_name + u" in the DB", logger.DEBUG) db_result = helpers.searchDBForShow(cur_name) 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) return (int(db_result[1]), season, episodes) # see if we can find the name on the Indexer for cur_name in name_list: - foundInfo = helpers.searchIndexersForShow(cur_name, indexer=self.indexer) - + foundInfo = helpers.searchIndexerForShowID(cur_name, self.indexer) if foundInfo: indexer_id = foundInfo[1] - self._log( u"Lookup successful, using " + sickbeard.indexerApi(self.indexer).name + " id " + str(indexer_id), logger.DEBUG) - - # return found results _finalize(parse_result) return (indexer_id, season, episodes) @@ -597,7 +595,6 @@ class PostProcessor(object): if (showObj != None): # set the language of the show indexer_lang = showObj.lang - self.indexer = int(showObj.indexer) except exceptions.MultipleShowObjectsException: raise #TODO: later I'll just log this, for now I want to know about it ASAP diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index ea86b4b0..44438deb 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -2068,15 +2068,18 @@ class NewHomeAddShows: # default to TVDB if indexer was not detected 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: - # set indexer and indexer_id from found info - if indexer is None: - indexer = found_info[0] + if indexer_id is None: + indexer_id = found_info[1] - if indexer_id is None: - indexer_id = found_info[1] + # found our info so continue + break cur_dir['existing_info'] = (indexer_id, show_name, indexer)