mirror of
https://github.com/morpheus65535/bazarr.git
synced 2024-09-20 07:25:58 +08:00
Made all subf2m test pass (#2645)
This commit is contained in:
parent
deae4e52f0
commit
92708e722f
|
@ -132,9 +132,9 @@ _DEFAULT_HEADERS = {
|
||||||
class Subf2mProvider(Provider):
|
class Subf2mProvider(Provider):
|
||||||
provider_name = "subf2m"
|
provider_name = "subf2m"
|
||||||
|
|
||||||
_movie_title_regex = re.compile(r"^(.+?)( \((\d{4})\))?$")
|
_movie_title_regex = re.compile(r"^(.+?)(\s+\((\d{4})\))?$")
|
||||||
_tv_show_title_regex = re.compile(
|
_tv_show_title_regex = re.compile(
|
||||||
r"^(.+?) [-\(]\s?(.*?) (season|series)\)?( \((\d{4})\))?$"
|
r"^(.+?)\s+[-\(]\s?(.*?)\s+(season|series)\)?(\s+\((\d{4})\))?$"
|
||||||
)
|
)
|
||||||
_tv_show_title_alt_regex = re.compile(r"(.+)\s(\d{1,2})(?:\s|$)")
|
_tv_show_title_alt_regex = re.compile(r"(.+)\s(\d{1,2})(?:\s|$)")
|
||||||
_supported_languages = {}
|
_supported_languages = {}
|
||||||
|
|
|
@ -86,11 +86,13 @@ def _get_matching_sub(
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _analize_sub_name(sub_name: str, title_):
|
def _analize_sub_name(sub_name: str, title_: str):
|
||||||
titles = re.split(r"[.-]", os.path.splitext(sub_name)[0])
|
titles = re.split(r"[\s_\.\+]?[.-][\s_\.\+]?", os.path.splitext(sub_name)[0])
|
||||||
|
|
||||||
for title in titles:
|
for title in titles:
|
||||||
title = title.strip()
|
title = title.strip()
|
||||||
ratio = SequenceMatcher(None, title, title_).ratio()
|
ratio = SequenceMatcher(None, title.lower(), title_.lower()).ratio()
|
||||||
|
|
||||||
if ratio > 0.85:
|
if ratio > 0.85:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Episode title matched: '%s' -> '%s' [%s]", title, sub_name, ratio
|
"Episode title matched: '%s' -> '%s' [%s]", title, sub_name, ratio
|
||||||
|
|
|
@ -281,7 +281,7 @@ class Subtitle(Subtitle_):
|
||||||
return encoding
|
return encoding
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
"""Check if a :attr:`text` is a valid SubRip format. Note that orignal format will pypass the checking
|
"""Check if a :attr:`text` is a valid SubRip format. Note that original format will bypass the checking
|
||||||
|
|
||||||
:return: whether or not the subtitle is valid.
|
:return: whether or not the subtitle is valid.
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
|
|
|
@ -184,15 +184,36 @@ def test_download_subtitle_episode(provider, subtitle_episode):
|
||||||
assert subtitle_episode.is_valid()
|
assert subtitle_episode.is_valid()
|
||||||
|
|
||||||
|
|
||||||
def test_download_subtitle_episode_with_title(provider):
|
@pytest.mark.parametrize(
|
||||||
|
"language,page_link,release_info,episode_number,episode_title",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"en",
|
||||||
|
"https://subf2m.co/subtitles/courage-the-cowardly-dog/english/2232402",
|
||||||
|
"Season 3 complete.",
|
||||||
|
13,
|
||||||
|
"Feast of the Bullfrogs",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"en",
|
||||||
|
"https://subf2m.co/subtitles/rick-and-morty-sixth-season/english/3060783",
|
||||||
|
"Used Subtitle Tools to convert from SUP to SRT, then ran the cleaner to remove HI. Grabbed subs from Rick.and.Morty.S06.1080p.BluRay.x264-STORiES.",
|
||||||
|
7,
|
||||||
|
"Full Meta Jackrick",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_download_subtitle_episode_with_title(
|
||||||
|
provider, language, page_link, release_info, episode_number, episode_title
|
||||||
|
):
|
||||||
sub = Subf2mSubtitle(
|
sub = Subf2mSubtitle(
|
||||||
Language.fromalpha2("en"),
|
Language.fromalpha2(language),
|
||||||
"https://subf2m.co/subtitles/courage-the-cowardly-dog/english/2232402",
|
page_link,
|
||||||
"Season 3 complete.",
|
release_info,
|
||||||
13,
|
episode_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
sub.episode_title = "Feast of the Bullfrogs"
|
sub.episode_title = episode_title
|
||||||
provider.download_subtitle(sub)
|
provider.download_subtitle(sub)
|
||||||
assert sub.is_valid()
|
assert sub.is_valid()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue