summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2023-05-09 13:00:12 -0400
committermorpheus65535 <[email protected]>2023-05-09 13:00:12 -0400
commit98c7364ce0d8f65e4cdd7223df0d00ccd916c8d4 (patch)
treeb1535a6d3fc7f51c940cd2bbff74bedfe99f0ad2
parenta6ecbb43154d6f57bcab4ea3be17467b487eea3f (diff)
parent0907269377401b64a52589a54431e4ab75a2587a (diff)
downloadbazarr-98c7364ce0d8f65e4cdd7223df0d00ccd916c8d4.tar.gz
bazarr-98c7364ce0d8f65e4cdd7223df0d00ccd916c8d4.zip
Merge remote-tracking branch 'origin/development' into development
-rw-r--r--bazarr/subtitles/manual.py3
-rw-r--r--libs/subliminal_patch/providers/utils.py45
-rw-r--r--libs/subliminal_patch/providers/zimuku.py8
-rw-r--r--tests/subliminal_patch/test_supersubtitles.py24
4 files changed, 57 insertions, 23 deletions
diff --git a/bazarr/subtitles/manual.py b/bazarr/subtitles/manual.py
index 868918889..45ff4e12b 100644
--- a/bazarr/subtitles/manual.py
+++ b/bazarr/subtitles/manual.py
@@ -87,8 +87,7 @@ def manual_search(path, profile_id, providers, sceneName, title, media_type):
logging.debug(f"BAZARR Skipping {s}, because it doesn't match our series/episode")
except TypeError:
logging.debug("BAZARR Ignoring invalid subtitles")
- finally:
- continue
+ continue
initial_hi = None
initial_hi_match = False
diff --git a/libs/subliminal_patch/providers/utils.py b/libs/subliminal_patch/providers/utils.py
index ea8e411e6..f06f75e34 100644
--- a/libs/subliminal_patch/providers/utils.py
+++ b/libs/subliminal_patch/providers/utils.py
@@ -121,6 +121,33 @@ def is_episode(content):
return "episode" in guessit(content, {"type": "episode"})
+_ENCS = ("utf-8", "ascii", "iso-8859-1", "iso-8859-2", "iso-8859-5", "cp1252")
+
+
+def _zip_from_subtitle_file(content):
+ with tempfile.NamedTemporaryFile(prefix="spsub", suffix=".srt") as tmp_f:
+ tmp_f.write(content)
+ sub = None
+ for enc in _ENCS:
+ try:
+ logger.debug("Trying %s encoding", enc)
+ sub = pysubs2.load(tmp_f.name, encoding=enc)
+ except Exception as error:
+ logger.debug("%s: %s", type(error).__name__, error)
+ continue
+ else:
+ break
+
+ if sub is not None:
+ logger.debug("Identified subtitle file: %s", sub)
+ zip_obj = zipfile.ZipFile(io.BytesIO(), mode="x")
+ zip_obj.write(tmp_f.name, os.path.basename(tmp_f.name))
+ return zip_obj
+
+ logger.debug("Couldn't load subtitle file")
+ return None
+
+
def get_archive_from_bytes(content: bytes):
"""Get RarFile/ZipFile object from bytes. A ZipFile instance will be returned
if a subtitle-like stream is found. Return None if something else is found."""
@@ -134,23 +161,7 @@ def get_archive_from_bytes(content: bytes):
return zipfile.ZipFile(archive_stream)
logger.debug("No compression format found. Trying with subtitle-like files")
-
- # If the file is a subtitle-like file
- with tempfile.NamedTemporaryFile(prefix="spsub", suffix=".srt") as tmp_f:
- try:
- tmp_f.write(content)
- sub = pysubs2.load(tmp_f.name)
- except Exception as error:
- logger.debug("Couldn't load file: '%s'", error)
- else:
- if sub is not None:
- logger.debug("Identified subtitle file: %s", sub)
- zip_obj = zipfile.ZipFile(io.BytesIO(), mode="x")
- zip_obj.write(tmp_f.name, os.path.basename(tmp_f.name))
- return zip_obj
-
- logger.debug("Nothing found")
- return None
+ return _zip_from_subtitle_file(content)
def update_matches(
diff --git a/libs/subliminal_patch/providers/zimuku.py b/libs/subliminal_patch/providers/zimuku.py
index 1940f0f1c..99bfb3d6c 100644
--- a/libs/subliminal_patch/providers/zimuku.py
+++ b/libs/subliminal_patch/providers/zimuku.py
@@ -143,7 +143,7 @@ class ZimukuProvider(Provider):
self.session.cookies.set("srcurl", string_to_hex(r.url))
if tr:
verify_resp = self.session.get(
- self.server_url + tr[0] + string_to_hex(self.code), allow_redirects=False)
+ urljoin(self.server_url, tr[0] + string_to_hex(self.code)), allow_redirects=False)
if verify_resp.status_code == 302 \
and self.session.cookies.get("security_session_verify") is not None:
pass
@@ -164,7 +164,7 @@ class ZimukuProvider(Provider):
bs_obj = ParserBeautifulSoup(
r.content.decode("utf-8", "ignore"), ["html.parser"]
)
- subs_body = bs_obj.find("div", class_="subs box clearfix").find("tbody")
+ subs_body = bs_obj.find("tbody")
subs = []
for sub in subs_body.find_all("tr"):
a = sub.find("a")
@@ -208,7 +208,7 @@ class ZimukuProvider(Provider):
logger.debug("Searching subtitles %r", params)
subtitles = []
- search_link = self.server_url + text_type(self.search_url).format(params)
+ search_link = urljoin(self.server_url, text_type(self.search_url).format(params))
r = self.yunsuo_bypass(search_link, timeout=30)
r.raise_for_status()
@@ -254,7 +254,7 @@ class ZimukuProvider(Provider):
season_cn2 = num_to_cn(str(season))
if season_cn1 != season_cn2:
continue
- episode_link = self.server_url + title_a.attrs["href"]
+ episode_link = urljoin(self.server_url, title_a.attrs["href"])
new_subs = self._parse_episode_page(episode_link, subs_year)
subtitles += new_subs
diff --git a/tests/subliminal_patch/test_supersubtitles.py b/tests/subliminal_patch/test_supersubtitles.py
index d02c017fe..ce483caad 100644
--- a/tests/subliminal_patch/test_supersubtitles.py
+++ b/tests/subliminal_patch/test_supersubtitles.py
@@ -107,6 +107,30 @@ def test_download_movie_subtitle(movies):
assert subtitle.is_valid()
+def test_download_movie_subtitle_hungarian(movies):
+ movie = movies["dune"]
+
+ subtitle = SuperSubtitlesSubtitle(
+ Language.fromalpha2("hu"),
+ "https://www.feliratok.eu//index.php?action=letolt&felirat=1681841063",
+ 1634579718,
+ "Foo",
+ 0,
+ 0,
+ "",
+ ["Foo"],
+ "",
+ "",
+ "",
+ asked_for_episode=None,
+ )
+ assert subtitle.get_matches(movie)
+
+ with SuperSubtitlesProvider() as provider:
+ provider.download_subtitle(subtitle)
+ assert subtitle.is_valid()
+
+
def test_subtitle_reprs(movies):
subtitle = SuperSubtitlesSubtitle(
Language.fromalpha2("en"),