Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EZTV provider search only finding the first 30 results #11775

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions medusa/providers/torrent/json/eztv.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __init__(self):
'api': urljoin(self.url, 'api/get-torrents')
}

# Set Max number of pages to get (about 6 (x 100) pages of new torrents per day)
self.max_pages = 6

# Proper Strings

# Miscellaneous Options
Expand All @@ -54,7 +57,9 @@ def search(self, search_strings, age=0, ep_obj=None, **kwargs):
results = []

# Search Params
search_params = {}
search_params = {
'limit': 100,
}

for mode in search_strings:
log.debug('Search mode: {0}', mode)
Expand All @@ -72,12 +77,44 @@ def search(self, search_strings, age=0, ep_obj=None, **kwargs):
continue

search_url = self.urls['api']
data = self.session.get_json(search_url, params=search_params)
if not data:
log.debug('No data returned from provider')
continue
page = 1

while page and page <= self.max_pages:
# log.warning('Searching page {0}', page)
search_params['page'] = page
response = self.session.get(search_url, params=search_params)
if not response or not response.content:
log.debug('No data returned from provider')
page = None
continue

try:
jdata = response.json()
except ValueError:
log.debug('No data returned from provider')
page = None
continue

error = jdata.get('error')
error_code = jdata.get('error_code')
if error:
log_level = logging.DEBUG
log.log(log_level, '{msg} Code: {code}', {'msg': error, 'code': error_code})
page = None
continue

results += self.parse(data, mode)
# check if we actually got something, if so, then parse it
torrent_rows = jdata.get('torrents', {})
if torrent_rows:
results += self.parse(jdata, mode)
page = page + 1
else:
if page == 1:
log.debug('Data returned from provider does not contain any torrents')
else:
log.debug('Page returned from provider does not contain any torrents')
page = None
continue

return results

Expand Down
Loading