summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAntoine Aflalo <[email protected]>2022-10-29 18:13:56 -0400
committerGitHub <[email protected]>2022-10-29 18:13:56 -0400
commitbe34b8fddd1e1400087cec946ca7c6bf48b31808 (patch)
treec0c53ac01bb501425d2f53caf98fff8eaeb9c672
parent78f769d743f6d5413d3a3c0c1c09570d8ee9cb2b (diff)
downloadbazarr-be34b8fddd1e1400087cec946ca7c6bf48b31808.tar.gz
bazarr-be34b8fddd1e1400087cec946ca7c6bf48b31808.zip
Gestdown Provider: Use ShowId to find subtitles. Fixes issue with Slash in show name. (#1979)
This way, if a show has a slash (/) inside its name, we can still find subtitles for it.
-rw-r--r--libs/subliminal_patch/providers/gestdown.py15
-rw-r--r--tests/subliminal_patch/test_gestdown.py8
2 files changed, 14 insertions, 9 deletions
diff --git a/libs/subliminal_patch/providers/gestdown.py b/libs/subliminal_patch/providers/gestdown.py
index 6af9920ea..c5adbadb9 100644
--- a/libs/subliminal_patch/providers/gestdown.py
+++ b/libs/subliminal_patch/providers/gestdown.py
@@ -83,9 +83,9 @@ class GestdownProvider(Provider):
def terminate(self):
self._session.close()
- def _subtitles_search(self, video, language: Language):
+ def _subtitles_search(self, video, language: Language, show_id):
lang = self._converter.convert(language.alpha3)
- response = self._session.get(f"{_BASE_URL}/subtitles/find/{lang}/{video.series}/{video.season}/{video.episode}")
+ response = self._session.get(f"{_BASE_URL}/subtitles/get/{show_id}/{video.season}/{video.episode}/{lang}")
# TODO: implement rate limiting
response.raise_for_status()
@@ -104,27 +104,28 @@ class GestdownProvider(Provider):
logger.debug("Found subtitle: %s", sub)
yield sub
- def _show_exists(self, video):
+ def _search_show(self, video):
try:
response = self._session.get(f"{_BASE_URL}/shows/search/{video.series}")
response.raise_for_status()
- return True
+ return response.json()["shows"][0]
except HTTPError as error:
if error.response.status_code == 404:
- return False
+ return None
raise
@_retry_on_423
def list_subtitles(self, video, languages):
subtitles = []
- if not self._show_exists(video):
+ show = self._search_show(video)
+ if show is None:
logger.debug("Couldn't find the show")
return subtitles
for language in languages:
try:
- subtitles += self._subtitles_search(video, language)
+ subtitles += self._subtitles_search(video, language, show["id"])
except HTTPError as error:
if error.response.status_code == 404:
logger.debug("Couldn't find the show or its season/episode")
diff --git a/tests/subliminal_patch/test_gestdown.py b/tests/subliminal_patch/test_gestdown.py
index edef2e5fa..117430a1d 100644
--- a/tests/subliminal_patch/test_gestdown.py
+++ b/tests/subliminal_patch/test_gestdown.py
@@ -78,9 +78,13 @@ def test_subtitle_download(subtitle):
def test_list_subtitles_423(episodes, requests_mock, mocker):
mocker.patch("time.sleep")
- requests_mock.get("https://api.gestdown.info/shows/search/Breaking%20Bad", status_code=200)
requests_mock.get(
- f"{_BASE_URL}/subtitles/find/English/Breaking%20Bad/1/1", status_code=423
+ "https://api.gestdown.info/shows/search/Breaking%20Bad",
+ status_code=200,
+ text='{"shows":[{"id":"cd880e2e-ef44-47cd-9f3d-a03b343ba2d0","name":"Breaking Bad","nbSeasons":5,"seasons":[1,2,3,4,5]}]}'
+ )
+ requests_mock.get(
+ f"{_BASE_URL}/subtitles/get/cd880e2e-ef44-47cd-9f3d-a03b343ba2d0/1/1/English", status_code=423
)
with GestdownProvider() as provider: