summaryrefslogtreecommitdiffhomepage
path: root/custom_libs/subliminal_patch
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2024-08-25 15:05:31 -0400
committermorpheus65535 <[email protected]>2024-08-25 15:05:31 -0400
commiteb084abc21b3d37390d6ec70d73e62297032f7c3 (patch)
tree3a7de3224c2d2db4feeb41e2f7d62be7b5b952f5 /custom_libs/subliminal_patch
parent4887066000a461d2026e95ba8d493bd667d9bfb2 (diff)
downloadbazarr-eb084abc21b3d37390d6ec70d73e62297032f7c3.tar.gz
bazarr-eb084abc21b3d37390d6ec70d73e62297032f7c3.zip
Fixed hearing-impaired detection using regex when language is Arabic and parenthesis are included in text. #2612
Diffstat (limited to 'custom_libs/subliminal_patch')
-rw-r--r--custom_libs/subliminal_patch/core.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/custom_libs/subliminal_patch/core.py b/custom_libs/subliminal_patch/core.py
index c1629496b..f0d7f3618 100644
--- a/custom_libs/subliminal_patch/core.py
+++ b/custom_libs/subliminal_patch/core.py
@@ -49,7 +49,17 @@ SUBTITLE_EXTENSIONS = ('.srt', '.sub', '.smi', '.txt', '.ssa', '.ass', '.mpl', '
_POOL_LIFETIME = datetime.timedelta(hours=12)
-HI_REGEX = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](?<!{\\an\d})')
+HI_REGEX_WITHOUT_PARENTHESIS = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\{].{3,}[\]\}](?<!{\\an\d})')
+HI_REGEX_WITH_PARENTHESIS = re.compile(r'[*¶♫♪].{3,}[*¶♫♪]|[\[\(\{].{3,}[\]\)\}](?<!{\\an\d})')
+
+HI_REGEX_PARENTHESIS_EXCLUDED_LANGUAGES = ['ara']
+
+
+def parse_for_hi_regex(subtitle_text, alpha3_language):
+ if alpha3_language in HI_REGEX_PARENTHESIS_EXCLUDED_LANGUAGES:
+ return bool(re.search(HI_REGEX_WITHOUT_PARENTHESIS, subtitle_text))
+ else:
+ return bool(re.search(HI_REGEX_WITH_PARENTHESIS, subtitle_text))
def remove_crap_from_fn(fn):
@@ -1203,7 +1213,7 @@ def save_subtitles(file_path, subtitles, single=False, directory=None, chmod=Non
continue
# create subtitle path
- if subtitle.text and bool(re.search(HI_REGEX, subtitle.text)):
+ if subtitle.text and parse_for_hi_regex(subtitle_text=subtitle.text, alpha3_language=subtitle.language.alpha3):
subtitle.language.hi = True
subtitle_path = get_subtitle_path(file_path, None if single else subtitle.language,
forced_tag=subtitle.language.forced,