From ba4b408af315e126bd9bd3403563878d6cd1c7dc Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 7 Sep 2014 00:48:09 -0700 Subject: [PATCH] Improved newznab offset code --- sickbeard/providers/newznab.py | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index 24a662b1..f6802008 100755 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -263,38 +263,38 @@ class NewznabProvider(generic.NZBProvider): params['apikey'] = self.key results = [] - - # get and set total items available - offset = total = 0 + while total >= offset: search_url = self.url + 'api?' + urllib.urlencode(params) logger.log(u"Search url: " + search_url, logger.DEBUG) data = self.cache.getRSSFeed(search_url) - if data and 'entries' in data and self._checkAuthFromData(data): - for item in data.entries: + if not data or not self._checkAuthFromData(data): + break - (title, url) = self._get_title_and_url(item) + for item in data.entries: - if title and url: - results.append(item) - else: - logger.log( - u"The data returned from the " + self.name + " is incomplete, this result is unusable", - logger.DEBUG) + (title, url) = self._get_title_and_url(item) - # get total and offset attribs - if total == 0: - total = int(data.feed.newznab_response['total'] or 0) - offset = int(data.feed.newznab_response['offset'] or 0) + if title and url: + results.append(item) + else: + logger.log( + u"The data returned from the " + self.name + " is incomplete, this result is unusable", + logger.DEBUG) - # if there are more items available then the amount given in one call, grab some more - params['offset'] += params['limit'] + # get total and offset attribs + if total == 0: + total = int(data.feed.newznab_response['total'] or 0) + offset = int(data.feed.newznab_response['offset'] or 0) - logger.log(str( - total - offset) + " more items to be fetched from provider. Fetching another " + str( - params['limit']) + " items.", logger.DEBUG) + # if there are more items available then the amount given in one call, grab some more + params['offset'] += params['limit'] + + logger.log(str( + total - offset) + " more items to be fetched from provider. Fetching another " + str( + params['limit']) + " items.", logger.DEBUG) return results