mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 11:32:20 -05:00
Improved newznab offset code
This commit is contained in:
parent
20c0b4ea72
commit
ab16430b1a
@ -264,7 +264,10 @@ class NewznabProvider(generic.NZBProvider):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
while True:
|
# get and set total items available
|
||||||
|
|
||||||
|
offset = total = 0
|
||||||
|
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)
|
||||||
@ -281,37 +284,17 @@ class NewznabProvider(generic.NZBProvider):
|
|||||||
u"The data returned from the " + self.name + " is incomplete, this result is unusable",
|
u"The data returned from the " + self.name + " is incomplete, this result is unusable",
|
||||||
logger.DEBUG)
|
logger.DEBUG)
|
||||||
|
|
||||||
# attempt to grab the total and offset newznab responses
|
# get total and offset attribs
|
||||||
try:
|
if total == 0:
|
||||||
total = int(data.feed.newznab_response['total'])
|
total = int(data.feed.newznab_response['total'] or 0)
|
||||||
offset = int(data.feed.newznab_response['offset'])
|
offset = int(data.feed.newznab_response['offset'] or 0)
|
||||||
except (AttributeError, TypeError):
|
|
||||||
break
|
|
||||||
|
|
||||||
# sanity check - limiting at 10 at getting 1000 results in-case incorrect total parameter is reported
|
|
||||||
if params['limit'] > 1000:
|
|
||||||
logger.log("Excessive results for search, ending search", logger.WARNING)
|
|
||||||
break
|
|
||||||
|
|
||||||
# sanity check - total should remain constant
|
|
||||||
if offset != 0 and total != initial_total:
|
|
||||||
logger.log("Total number of items on newznab response changed, ending search", logger.DEBUG)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
initial_total = total
|
|
||||||
|
|
||||||
# if there are more items available then the amount given in one call, grab some more
|
# if there are more items available then the amount given in one call, grab some more
|
||||||
if (total - params['limit']) > offset == params['offset']:
|
|
||||||
params['offset'] += params['limit']
|
params['offset'] += params['limit']
|
||||||
|
|
||||||
logger.log(str(
|
logger.log(str(
|
||||||
total - params['offset']) + " more items to be fetched from provider. Fetching another " + str(
|
total - offset) + " more items to be fetched from provider. Fetching another " + str(
|
||||||
params['limit']) + " items.", logger.DEBUG)
|
params['limit']) + " items.", logger.DEBUG)
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user