diff options
author | vitiko98 <[email protected]> | 2022-05-23 23:27:04 -0400 |
---|---|---|
committer | vitiko98 <[email protected]> | 2022-05-23 23:27:04 -0400 |
commit | 0e98880494149801ac40821a4b0e89a7e2cb10b8 (patch) | |
tree | 6267f9c6f66e7b61e626efef53769e18e926ffab /libs | |
parent | 848836c5bb66ae4baa5edac3decfe65de4cb9e62 (diff) | |
download | bazarr-0e98880494149801ac40821a4b0e89a7e2cb10b8.tar.gz bazarr-0e98880494149801ac40821a4b0e89a7e2cb10b8.zip |
Gestdown provider: implement retries on 423 status codes
Diffstat (limited to 'libs')
-rw-r--r-- | libs/subliminal_patch/providers/gestdown.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libs/subliminal_patch/providers/gestdown.py b/libs/subliminal_patch/providers/gestdown.py index 56b922b6d..f66809864 100644 --- a/libs/subliminal_patch/providers/gestdown.py +++ b/libs/subliminal_patch/providers/gestdown.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import logging +import time from requests import HTTPError from requests import Session @@ -37,6 +38,28 @@ class GestdownSubtitle(Subtitle): return self._id +def _retry_on_423(method): + def retry(self, *args, **kwargs): + retries = 0 + while 5 > retries: + try: + yield from method(self, *args, **kwargs) + except HTTPError as error: + if error.response.status_code != 423: + raise + + retries += 1 + + logger.debug("423 returned. Retrying in 30 seconds") + time.sleep(30) + else: + break + + logger.debug("Retries limit exceeded. Ignoring query") + + return retry + + class GestdownProvider(Provider): provider_name = "gestdown" @@ -61,6 +84,7 @@ class GestdownProvider(Provider): def terminate(self): self._session.close() + @_retry_on_423 def _subtitles_search(self, video, language: Language): json_data = { "search": f"{video.series} S{video.season:02}E{video.episode:02}", |