From 93e061462ac93e610171a0ee38e6de204abfb635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sat, 27 Apr 2019 08:13:47 -0400 Subject: [PATCH] Continuing development. --- bazarr/embedded_subs_reader.py | 31 +++++++++++++++++++++---------- bazarr/list_subtitles.py | 8 +++++--- views/movie.tpl | 8 ++++---- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/bazarr/embedded_subs_reader.py b/bazarr/embedded_subs_reader.py index b4961f7d9..8992134f4 100644 --- a/bazarr/embedded_subs_reader.py +++ b/bazarr/embedded_subs_reader.py @@ -16,15 +16,26 @@ class EmbeddedSubsReader: self.ffprobe = get_binary("ffprobe") def list_languages(self, file): - if self.ffprobe: - try: - return subprocess.check_output([self.ffprobe, "-loglevel", "error", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file], universal_newlines=True, stderr=subprocess.STDOUT).strip().split("\n") - except subprocess.CalledProcessError as e: - raise FFprobeError(e.output) - if os.path.splitext(file)[1] != '.mkv': - raise NotMKVAndNoFFprobe() - with open(file, 'rb') as f: - mkv = enzyme.MKV(f) - return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks] + subtitles_list = [] + + if os.path.splitext(file)[1] == '.mkv': + with open(file, 'rb') as f: + mkv = enzyme.MKV(f) + for subtitle_track in mkv.subtitle_tracks: + subtitles_list.append([subtitle_track.language, subtitle_track.forced]) + else: + if self.ffprobe: + detected_languages = [] + try: + detected_languages = subprocess.check_output([self.ffprobe, "-loglevel", "error", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file], universal_newlines=True, stderr=subprocess.STDOUT).strip().split("\n") + except subprocess.CalledProcessError as e: + raise FFprobeError(e.output) + else: + for detected_language in detected_languages: + subtitles_list.append([detected_language, False]) + # I can't get the forced flag from ffprobe so I always assume it as not forced + + return subtitles_list + embedded_subs_reader = EmbeddedSubsReader() \ No newline at end of file diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index efefae880..e8220e859 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -35,10 +35,12 @@ def store_subtitles(file): logging.debug("BAZARR is trying to index embedded subtitles.") try: subtitle_languages = embedded_subs_reader.list_languages(file) - for subtitle_language in subtitle_languages: + for subtitle_language, subtitle_forced in subtitle_languages: try: if alpha2_from_alpha3(subtitle_language) is not None: lang = str(alpha2_from_alpha3(subtitle_language)) + if subtitle_forced: + lang = lang + ":forced" logging.debug("BAZARR embedded subtitles detected: " + lang) actual_subtitles.append([lang, None]) except: @@ -122,11 +124,11 @@ def store_subtitles_movie(file): logging.debug("BAZARR is trying to index embedded subtitles.") try: subtitle_languages = embedded_subs_reader.list_languages(file) - for subtitle_language in subtitle_languages: + for subtitle_language, subtitle_forced in subtitle_languages: try: if alpha2_from_alpha3(subtitle_language) is not None: lang = str(alpha2_from_alpha3(subtitle_language)) - if subtitle_track.forced: + if subtitle_forced: lang = lang + ':forced' logging.debug("BAZARR embedded subtitles detected: " + lang) actual_subtitles.append([lang, None]) diff --git a/views/movie.tpl b/views/movie.tpl index da5f81827..9bf38ce6e 100644 --- a/views/movie.tpl +++ b/views/movie.tpl @@ -175,7 +175,7 @@ %>