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,23 +127,27 @@ class RarbgProvider(TorrentProvider): ...@@ -127,23 +127,27 @@ class RarbgProvider(TorrentProvider):
search_params['search_string'] = search_string search_params['search_string'] = search_string
max_retries = retries = 5
while retries > 0:
backoff = 2 ** (max_retries - retries)
# Check if token is still valid before search # Check if token is still valid before search
if not self.login(): if not self.login():
continue break
# sleep 5 secs per request # sleep per request based on backoff variable
sleep(5) sleep(backoff)
resp = self.session.get(self.urls['api'], params=search_params, random_ua=True) resp = self.session.get(self.urls['api'], params=search_params, random_ua=True)
if not resp or not resp.content: if not resp or not resp.content:
sickrage.app.log.debug("No data returned from provider") sickrage.app.log.debug("No data returned from provider")
continue break
try: try:
data = resp.json() data = resp.json()
except ValueError: except ValueError:
sickrage.app.log.debug("No data returned from provider") sickrage.app.log.debug("No data returned from provider")
continue break
error = data.get('error') error = data.get('error')
error_code = data.get('error_code') error_code = data.get('error_code')
...@@ -152,18 +156,28 @@ class RarbgProvider(TorrentProvider): ...@@ -152,18 +156,28 @@ class RarbgProvider(TorrentProvider):
if error_code == 5: if error_code == 5:
# 5 = Too many requests per second # 5 = Too many requests per second
log_level = sickrage.app.log.INFO log_level = sickrage.app.log.INFO
elif error_code not in (4, 8, 10, 12, 14, 20): retries -= 1
# 4 = Invalid token. Use get_token for a new one! elif error_code not in (8, 10, 12, 14, 20):
# 8, 10, 12, 14 = Cant find * in database. Are you sure this * exists? # 8, 10, 12, 14 = Cant find * in database. Are you sure this * exists?
# 20 = No results found # 20 = No results found
log_level = sickrage.app.log.WARNING log_level = sickrage.app.log.WARNING
retries = 0
elif error_code not in (2, 4):
# 2, 4 = Invalid token. Use get_token for a new one!
log_level = sickrage.app.log.WARNING
retries -= 1
else: else:
log_level = sickrage.app.log.DEBUG log_level = sickrage.app.log.DEBUG
retries = 0
sickrage.app.log.log(log_level, '{msg} Code: {code}'.format(msg=error, code=error_code)) if retries:
continue continue
sickrage.app.log.log(log_level, '{msg} Code: {code}'.format(msg=error, code=error_code))
break
results += self.parse(data, mode) 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