Improved newznab offset code

This commit is contained in:
echel0n 2014-09-07 00:48:09 -07:00
parent ab16430b1a
commit ba4b408af3

View file

@ -263,38 +263,38 @@ class NewznabProvider(generic.NZBProvider):
params['apikey'] = self.key params['apikey'] = self.key
results = [] results = []
# get and set total items available
offset = total = 0 offset = total = 0
while total >= offset: while total >= offset:
search_url = self.url + 'api?' + urllib.urlencode(params) search_url = self.url + 'api?' + urllib.urlencode(params)
logger.log(u"Search url: " + search_url, logger.DEBUG) logger.log(u"Search url: " + search_url, logger.DEBUG)
data = self.cache.getRSSFeed(search_url) data = self.cache.getRSSFeed(search_url)
if data and 'entries' in data and self._checkAuthFromData(data): if not data or not self._checkAuthFromData(data):
for item in data.entries: break
(title, url) = self._get_title_and_url(item) for item in data.entries:
if title and url: (title, url) = self._get_title_and_url(item)
results.append(item)
else:
logger.log(
u"The data returned from the " + self.name + " is incomplete, this result is unusable",
logger.DEBUG)
# get total and offset attribs if title and url:
if total == 0: results.append(item)
total = int(data.feed.newznab_response['total'] or 0) else:
offset = int(data.feed.newznab_response['offset'] or 0) 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 # get total and offset attribs
params['offset'] += params['limit'] if total == 0:
total = int(data.feed.newznab_response['total'] or 0)
offset = int(data.feed.newznab_response['offset'] or 0)
logger.log(str( # if there are more items available then the amount given in one call, grab some more
total - offset) + " more items to be fetched from provider. Fetching another " + str( params['offset'] += params['limit']
params['limit']) + " items.", logger.DEBUG)
logger.log(str(
total - offset) + " more items to be fetched from provider. Fetching another " + str(
params['limit']) + " items.", logger.DEBUG)
return results return results