From a5599d553e228d6280c21498715f744cb45e1a83 Mon Sep 17 00:00:00 2001 From: sekkr1 Date: Tue, 23 Apr 2019 23:19:25 +0300 Subject: [PATCH] added mkv extension check before enzyme+exceptions --- bazarr/embedded_subs_reader.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bazarr/embedded_subs_reader.py b/bazarr/embedded_subs_reader.py index a24a60cb8..f4b51b095 100644 --- a/bazarr/embedded_subs_reader.py +++ b/bazarr/embedded_subs_reader.py @@ -1,19 +1,30 @@ import enzyme import logging +import os +import subprocess -from subprocess import check_output from utils import get_binary +class MKVAndNoFFprobe(Exception): + pass + +class FFprobeError(Exception): + pass + class EmbeddedSubsReader: def __init__(self): self.ffprobe = get_binary("ffprobe") def list_languages(self, file): if self.ffprobe: - return check_output([self.ffprobe, "-loglevel", "quiet", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file], universal_newlines=True).strip().split("\n") - else: - with open(file, 'rb') as f: - mkv = enzyme.MKV(f) - return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks] + 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 MKVAndNoFFprobe() + with open(file, 'rb') as f: + mkv = enzyme.MKV(f) + return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks] embedded_subs_reader = EmbeddedSubsReader() \ No newline at end of file