diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index bfe315c3..929187a7 100755 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -224,7 +224,7 @@ class NewznabProvider(generic.NZBProvider): base_params['apikey'] = api_key results = [] - total = 0 + total, cnt, search_url, exit_log = 0, len(results), '', False for mode in search_params.keys(): for i, params in enumerate(search_params[mode]): @@ -285,8 +285,13 @@ class NewznabProvider(generic.NZBProvider): except AttributeError: break - # No items found or cache mode, prevent from doing another search - if 0 == total or 'Cache' == mode: + # No items found, prevent from doing another search + if 0 == total: + break + + # Cache mode, prevent from doing another search + if 'Cache' == mode: + exit_log = True break if offset != request_params['offset']: @@ -295,6 +300,7 @@ class NewznabProvider(generic.NZBProvider): request_params['offset'] += request_params['limit'] if total <= request_params['offset']: + exit_log = True logger.log('%s item%s found that will be used for episode matching' % (total, helpers.maybe_plural(total)), logger.DEBUG) break @@ -304,15 +310,23 @@ class NewznabProvider(generic.NZBProvider): logger.log('%s more item%s to fetch from a batch of up to %s items.' % (items, helpers.maybe_plural(items), request_params['limit']), logger.DEBUG) - batch_count = len(results) - cnt - if batch_count: - self._log_search(mode, batch_count, search_url) + batch_count = self._log_result(results, mode, cnt, search_url) + + if exit_log: + self._log_result(results, mode, cnt, search_url) + exit_log = False if 'tvdbid' in request_params and len(results): break return results + def _log_result(self, results, mode, cnt, url): + count = len(results) - cnt + if count: + self._log_search(mode, count, url) + return count + class NewznabCache(tvcache.TVCache): diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 1d66fc6e..a9433e4e 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -4240,33 +4240,25 @@ class ConfigProviders(Config): return newProvider.get_id() + '|' + newProvider.config_str() def getNewznabCategories(self, name, url, key): - ''' + """ Retrieves a list of possible categories with category id's Using the default url/api?cat http://yournewznaburl.com/api?t=caps&apikey=yourapikey - ''' - error = '' - success = False + """ - if not name: - error += '\nNo Provider Name specified' - if not url: - error += '\nNo Provider Url specified' - if not key: - error += '\nNo Provider Api key specified' + error = not name and 'Name' or not url and 'Url' or not key and 'Apikey' or '' + if error: + error = '\nNo provider %s specified' % error + return json.dumps({'success': False, 'error': error}) - if error <> '': - return json.dumps({'success' : False, 'error': error}) + providers = dict(zip([x.get_id() for x in sickbeard.newznabProviderList], sickbeard.newznabProviderList)) + temp_provider = newznab.NewznabProvider(name, url, key) + if None is not key and starify(key, True): + temp_provider.key = providers[temp_provider.get_id()].key - #Get list with Newznabproviders - #providerDict = dict(zip([x.get_id() for x in sickbeard.newznabProviderList], sickbeard.newznabProviderList)) + success, tv_categories, error = temp_provider.get_newznab_categories() - #Get newznabprovider obj with provided name - tempProvider= newznab.NewznabProvider(name, url, key) - - success, tv_categories, error = tempProvider.get_newznab_categories() - - return json.dumps({'success' : success,'tv_categories' : tv_categories, 'error' : error}) + return json.dumps({'success': success, 'tv_categories': tv_categories, 'error': error}) def deleteNewznabProvider(self, nnid):