1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2025-01-31 03:12:12 +00:00

added mkv extension check before enzyme+exceptions

This commit is contained in:
sekkr1 2019-04-23 23:19:25 +03:00
parent 730f0e1c10
commit a5599d553e

View file

@ -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()