mirror of https://github.com/morpheus65535/bazarr
Fixed timeout and error handling in OpenSubtitles.com provider.
This commit is contained in:
parent
99055fe154
commit
b1dd190663
|
@ -156,7 +156,7 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
||||||
r = self.session.post(self.server_url + 'login',
|
r = self.session.post(self.server_url + 'login',
|
||||||
json={"username": self.username, "password": self.password},
|
json={"username": self.username, "password": self.password},
|
||||||
allow_redirects=False,
|
allow_redirects=False,
|
||||||
timeout=10)
|
timeout=30)
|
||||||
except (ConnectionError, Timeout, ReadTimeout):
|
except (ConnectionError, Timeout, ReadTimeout):
|
||||||
raise ServiceUnavailable('Unknown Error, empty response: %s: %r' % (r.status_code, r))
|
raise ServiceUnavailable('Unknown Error, empty response: %s: %r' % (r.status_code, r))
|
||||||
else:
|
else:
|
||||||
|
@ -194,16 +194,14 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
||||||
parameters = {'query': title}
|
parameters = {'query': title}
|
||||||
logging.debug('Searching using this title: {}'.format(title))
|
logging.debug('Searching using this title: {}'.format(title))
|
||||||
|
|
||||||
results = self.session.get(self.server_url + 'features', params=parameters, timeout=10)
|
results = self.session.get(self.server_url + 'features', params=parameters, timeout=30)
|
||||||
results.raise_for_status()
|
|
||||||
|
|
||||||
if results.status_code == 401:
|
if results.status_code == 401:
|
||||||
logging.debug('Authentification failed: clearing cache and attempting to login.')
|
logging.debug('Authentification failed: clearing cache and attempting to login.')
|
||||||
region.delete("oscom_token")
|
region.delete("oscom_token")
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
results = self.session.get(self.server_url + 'features', params=parameters, timeout=10)
|
results = self.session.get(self.server_url + 'features', params=parameters, timeout=30)
|
||||||
results.raise_for_status()
|
|
||||||
|
|
||||||
if results.status_code == 429:
|
if results.status_code == 429:
|
||||||
raise TooManyRequests()
|
raise TooManyRequests()
|
||||||
|
@ -258,14 +256,13 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
||||||
'episode_number': self.video.episode,
|
'episode_number': self.video.episode,
|
||||||
'season_number': self.video.season,
|
'season_number': self.video.season,
|
||||||
'moviehash': hash},
|
'moviehash': hash},
|
||||||
timeout=10)
|
timeout=30)
|
||||||
else:
|
else:
|
||||||
res = self.session.get(self.server_url + 'subtitles',
|
res = self.session.get(self.server_url + 'subtitles',
|
||||||
params={'id': title_id,
|
params={'id': title_id,
|
||||||
'languages': langs,
|
'languages': langs,
|
||||||
'moviehash': hash},
|
'moviehash': hash},
|
||||||
timeout=10)
|
timeout=30)
|
||||||
res.raise_for_status()
|
|
||||||
|
|
||||||
if res.status_code == 429:
|
if res.status_code == 429:
|
||||||
raise TooManyRequests()
|
raise TooManyRequests()
|
||||||
|
@ -326,9 +323,7 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
||||||
res = self.session.post(self.server_url + 'download',
|
res = self.session.post(self.server_url + 'download',
|
||||||
json={'file_id': subtitle.file_id, 'sub_format': 'srt'},
|
json={'file_id': subtitle.file_id, 'sub_format': 'srt'},
|
||||||
headers=headers,
|
headers=headers,
|
||||||
timeout=10)
|
timeout=30)
|
||||||
res.raise_for_status()
|
|
||||||
|
|
||||||
if res.status_code == 429:
|
if res.status_code == 429:
|
||||||
raise TooManyRequests()
|
raise TooManyRequests()
|
||||||
elif res.status_code == 406:
|
elif res.status_code == 406:
|
||||||
|
@ -339,8 +334,7 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ProviderError('Invalid JSON returned by provider')
|
raise ProviderError('Invalid JSON returned by provider')
|
||||||
else:
|
else:
|
||||||
r = self.session.get(subtitle.download_link, timeout=10)
|
r = self.session.get(subtitle.download_link, timeout=30)
|
||||||
r.raise_for_status()
|
|
||||||
|
|
||||||
if res.status_code == 429:
|
if res.status_code == 429:
|
||||||
raise TooManyRequests()
|
raise TooManyRequests()
|
||||||
|
|
Loading…
Reference in New Issue