From e4f4f9e3575827580b5b70371bf98533020e471b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 25 Aug 2019 22:11:30 -0400 Subject: [PATCH] Use pyprobe instead of calling ffprobe executable directly. --- bazarr/embedded_subs_reader.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/bazarr/embedded_subs_reader.py b/bazarr/embedded_subs_reader.py index 835f577f5..df9625d4c 100644 --- a/bazarr/embedded_subs_reader.py +++ b/bazarr/embedded_subs_reader.py @@ -4,8 +4,8 @@ import os import subprocess import locale -from config import settings from utils import get_binary +from pyprobe.pyprobe import VideoFileParser class NotMKVAndNoFFprobe(Exception): pass @@ -20,24 +20,22 @@ class EmbeddedSubsReader: def list_languages(self, file): 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]) + if self.ffprobe: + parser = VideoFileParser(ffprobe=self.ffprobe, includeMissing=True, rawMode=False) + data = parser.parseFfprobe(file) + + detected_languages = [] + + for detected_language in data['subtitles']: + subtitles_list.append([detected_language['language'], detected_language['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.encode(locale.getpreferredencoding())], 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 isn't forced + 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]) return subtitles_list -embedded_subs_reader = EmbeddedSubsReader() \ No newline at end of file +embedded_subs_reader = EmbeddedSubsReader()