summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorVitiko <[email protected]>2022-05-05 00:02:34 -0400
committerVitiko <[email protected]>2022-05-05 00:04:37 -0400
commit134613711ac1ede510cfc023072f0712a175b858 (patch)
treead7446c8521787948cb472f5beac35622f51b19d /libs
parente186bd1a0f754738873eec995271522dc1df2263 (diff)
downloadbazarr-134613711ac1ede510cfc023072f0712a175b858.tar.gz
bazarr-134613711ac1ede510cfc023072f0712a175b858.zip
Embedded Subtitles provider: improve detection of potentially incomplete subtitlesv1.0.5-beta.3
Diffstat (limited to 'libs')
-rw-r--r--libs/subliminal_patch/providers/embeddedsubtitles.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/libs/subliminal_patch/providers/embeddedsubtitles.py b/libs/subliminal_patch/providers/embeddedsubtitles.py
index 324438a1c..63e7c8fde 100644
--- a/libs/subliminal_patch/providers/embeddedsubtitles.py
+++ b/libs/subliminal_patch/providers/embeddedsubtitles.py
@@ -117,6 +117,8 @@ class EmbeddedSubtitlesProvider(Provider):
self._blacklist.add(path)
streams = []
+ streams = _discard_possible_incomplete_subtitles(list(streams))
+
if not streams:
logger.debug("No subtitles found for container: %s", video)
@@ -260,6 +262,39 @@ def _check_hi_fallback(streams, languages):
logger.debug("HI fallback not needed: %s", compatible_streams)
+def _discard_possible_incomplete_subtitles(streams):
+ """Check number_of_frames attributes from subtitle streams in order to find
+ supposedly incomplete subtitles"""
+ try:
+ max_frames = max(stream.number_of_frames for stream in streams)
+ except ValueError:
+ return []
+
+ # Blatantly assume there's nothing to discard as some ffprobe streams don't
+ # have number_of_frames tags
+ if not max_frames:
+ return streams
+
+ logger.debug("Checking possible incomplete subtitles (max frames: %d)", max_frames)
+
+ valid_streams = []
+
+ for stream in streams:
+ # 500 < 1200
+ if stream.number_of_frames < max_frames // 2:
+ logger.debug(
+ "Possible bad subtitle found: %s (%s frames - %s frames)",
+ stream,
+ stream.number_of_frames,
+ max_frames,
+ )
+ continue
+
+ valid_streams.append(stream)
+
+ return valid_streams
+
+
def _is_fuse_rclone_mount(path: str):
# Experimental!