Commit dc461654 authored by echel0n's avatar echel0n
Browse files

added retries for rarbg search provider

parent 2f4b4478
...@@ -112,6 +112,8 @@ def change_gui_lang(language): ...@@ -112,6 +112,8 @@ def change_gui_lang(language):
# System default language # System default language
gettext.install('messages', sickrage.LOCALE_DIR, codeset='UTF-8', names=["ngettext"]) gettext.install('messages', sickrage.LOCALE_DIR, codeset='UTF-8', names=["ngettext"])
sickrage.app.config.gui.gui_lang = language
def change_unrar_tool(unrar_tool): def change_unrar_tool(unrar_tool):
# Check for failed unrar attempt, and remove it # Check for failed unrar attempt, and remove it
......
...@@ -127,43 +127,57 @@ class RarbgProvider(TorrentProvider): ...@@ -127,43 +127,57 @@ class RarbgProvider(TorrentProvider):
search_params['search_string'] = search_string search_params['search_string'] = search_string
# Check if token is still valid before search max_retries = retries = 5
if not self.login(): while retries > 0:
continue backoff = 2 ** (max_retries - retries)
# sleep 5 secs per request # Check if token is still valid before search
sleep(5) if not self.login():
break
resp = self.session.get(self.urls['api'], params=search_params, random_ua=True)
if not resp or not resp.content: # sleep per request based on backoff variable
sickrage.app.log.debug("No data returned from provider") sleep(backoff)
continue
resp = self.session.get(self.urls['api'], params=search_params, random_ua=True)
try: if not resp or not resp.content:
data = resp.json() sickrage.app.log.debug("No data returned from provider")
except ValueError: break
sickrage.app.log.debug("No data returned from provider")
continue try:
data = resp.json()
error = data.get('error') except ValueError:
error_code = data.get('error_code') sickrage.app.log.debug("No data returned from provider")
if error: break
# List of errors: https://github.com/rarbg/torrentapi/issues/1#issuecomment-114763312
if error_code == 5: error = data.get('error')
# 5 = Too many requests per second error_code = data.get('error_code')
log_level = sickrage.app.log.INFO if error:
elif error_code not in (4, 8, 10, 12, 14, 20): # List of errors: https://github.com/rarbg/torrentapi/issues/1#issuecomment-114763312
# 4 = Invalid token. Use get_token for a new one! if error_code == 5:
# 8, 10, 12, 14 = Cant find * in database. Are you sure this * exists? # 5 = Too many requests per second
# 20 = No results found log_level = sickrage.app.log.INFO
log_level = sickrage.app.log.WARNING retries -= 1
else: elif error_code not in (8, 10, 12, 14, 20):
log_level = sickrage.app.log.DEBUG # 8, 10, 12, 14 = Cant find * in database. Are you sure this * exists?
# 20 = No results found
sickrage.app.log.log(log_level, '{msg} Code: {code}'.format(msg=error, code=error_code)) log_level = sickrage.app.log.WARNING
continue retries = 0
elif error_code not in (2, 4):
results += self.parse(data, mode) # 2, 4 = Invalid token. Use get_token for a new one!
log_level = sickrage.app.log.WARNING
retries -= 1
else:
log_level = sickrage.app.log.DEBUG
retries = 0
if retries:
continue
sickrage.app.log.log(log_level, '{msg} Code: {code}'.format(msg=error, code=error_code))
break
results += self.parse(data, mode)
break
return results return results
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment