diff options
author | morpheus65535 <[email protected]> | 2024-10-12 11:35:27 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-10-12 11:35:27 -0400 |
commit | 43563cdcbd9524803856228352a3ef0d1131717c (patch) | |
tree | b72e573c33d7f419d8d2d96a98ea2c914270a20d /custom_libs | |
parent | f50bcf34ac3c246d21a69dc3cc2f2eba63314c21 (diff) | |
download | bazarr-43563cdcbd9524803856228352a3ef0d1131717c.tar.gz bazarr-43563cdcbd9524803856228352a3ef0d1131717c.zip |
Fixed subtitles conversion when use original format is enabled and prevented hearing-impaired detection for non srt format subtitles. #2693
Diffstat (limited to 'custom_libs')
-rw-r--r-- | custom_libs/subliminal_patch/core.py | 13 | ||||
-rw-r--r-- | custom_libs/subliminal_patch/core_persistent.py | 2 | ||||
-rw-r--r-- | custom_libs/subliminal_patch/subtitle.py | 11 |
3 files changed, 14 insertions, 12 deletions
diff --git a/custom_libs/subliminal_patch/core.py b/custom_libs/subliminal_patch/core.py index 0fc2ac0a7..708cbd58b 100644 --- a/custom_libs/subliminal_patch/core.py +++ b/custom_libs/subliminal_patch/core.py @@ -524,7 +524,7 @@ class SZProviderPool(ProviderPool): return True def download_best_subtitles(self, subtitles, video, languages, min_score=0, hearing_impaired=False, only_one=False, - compute_score=None): + compute_score=None, use_original_format=False): """Download the best matching subtitles. patch: @@ -543,6 +543,7 @@ class SZProviderPool(ProviderPool): :param bool only_one: download only one subtitle, not one per language. :param compute_score: function that takes `subtitle` and `video` as positional arguments, `hearing_impaired` as keyword argument and returns the score. + :param bool use_original_format: preserve original subtitles format :return: downloaded subtitles. :rtype: list of :class:`~subliminal.subtitle.Subtitle` @@ -620,6 +621,9 @@ class SZProviderPool(ProviderPool): subtitle, score) continue + # make sure to preserve original subtitles format if requested + subtitle.use_original_format = use_original_format + # download logger.debug("%r: Trying to download subtitle with matches %s, score: %s; release(s): %s", subtitle, matches, score, subtitle.release_info) @@ -1213,10 +1217,9 @@ def save_subtitles(file_path, subtitles, single=False, directory=None, chmod=Non continue # create subtitle path - if subtitle.text and parse_for_hi_regex(subtitle_text=subtitle.text, - alpha3_language=subtitle.language.alpha3 if - (hasattr(subtitle, 'language') and hasattr(subtitle.language, 'alpha3')) - else None): + if (subtitle.text and subtitle.format == 'srt' and + parse_for_hi_regex(subtitle_text=subtitle.text, alpha3_language=subtitle.language.alpha3 if + (hasattr(subtitle, 'language') and hasattr(subtitle.language, 'alpha3')) else None)): subtitle.language.hi = True subtitle_path = get_subtitle_path(file_path, None if single else subtitle.language, forced_tag=subtitle.language.forced, diff --git a/custom_libs/subliminal_patch/core_persistent.py b/custom_libs/subliminal_patch/core_persistent.py index e98914901..31ec61273 100644 --- a/custom_libs/subliminal_patch/core_persistent.py +++ b/custom_libs/subliminal_patch/core_persistent.py @@ -50,6 +50,7 @@ def download_best_subtitles( hearing_impaired=False, only_one=False, compute_score=None, + use_original_format=False, **kwargs ): downloaded_subtitles = defaultdict(list) @@ -77,6 +78,7 @@ def download_best_subtitles( hearing_impaired=hearing_impaired, only_one=only_one, compute_score=compute_score, + use_original_format=use_original_format, ) logger.info("Downloaded %d subtitle(s)", len(subtitles)) downloaded_subtitles[video].extend(subtitles) diff --git a/custom_libs/subliminal_patch/subtitle.py b/custom_libs/subliminal_patch/subtitle.py index c65f8cdd2..82d5a6895 100644 --- a/custom_libs/subliminal_patch/subtitle.py +++ b/custom_libs/subliminal_patch/subtitle.py @@ -313,13 +313,10 @@ class Subtitle(Subtitle_): logger.info("Got FPS from MicroDVD subtitle: %s", subs.fps) else: logger.info("Got format: %s", subs.format) - self._og_format = subs.format - self._is_valid = True - # if self.use_original_format: - # self.format = subs.format - # self._is_valid = True - # logger.debug("Using original format") - return True + if self.use_original_format: + self._og_format = subs.format + self._is_valid = True + return True except pysubs2.UnknownFPSError: # if parsing failed, use frame rate from provider |