summaryrefslogtreecommitdiffhomepage
path: root/custom_libs/subliminal_patch
diff options
context:
space:
mode:
Diffstat (limited to 'custom_libs/subliminal_patch')
-rw-r--r--custom_libs/subliminal_patch/core.py13
-rw-r--r--custom_libs/subliminal_patch/core_persistent.py2
-rw-r--r--custom_libs/subliminal_patch/providers/embeddedsubtitles.py2
-rw-r--r--custom_libs/subliminal_patch/subtitle.py11
4 files changed, 15 insertions, 13 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/providers/embeddedsubtitles.py b/custom_libs/subliminal_patch/providers/embeddedsubtitles.py
index 2d8a492c7..943607735 100644
--- a/custom_libs/subliminal_patch/providers/embeddedsubtitles.py
+++ b/custom_libs/subliminal_patch/providers/embeddedsubtitles.py
@@ -287,7 +287,7 @@ def _check_hi_fallback(streams, languages):
logger.debug("Checking HI fallback for '%r' language", language)
streams_ = [
- stream for stream in streams if stream.language.alpha3 == language.alpha3
+ stream for stream in streams if stream.language.alpha3 == language.alpha3 and stream.language.forced == language.forced
]
if len(streams_) == 1 and streams_[0].disposition.hearing_impaired:
stream_ = streams_[0]
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