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:
parent
730f0e1c10
commit
a5599d553e
1 changed files with 17 additions and 6 deletions
|
@ -1,17 +1,28 @@
|
||||||
import enzyme
|
import enzyme
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from subprocess import check_output
|
|
||||||
from utils import get_binary
|
from utils import get_binary
|
||||||
|
|
||||||
|
class MKVAndNoFFprobe(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class FFprobeError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class EmbeddedSubsReader:
|
class EmbeddedSubsReader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ffprobe = get_binary("ffprobe")
|
self.ffprobe = get_binary("ffprobe")
|
||||||
|
|
||||||
def list_languages(self, file):
|
def list_languages(self, file):
|
||||||
if self.ffprobe:
|
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")
|
try:
|
||||||
else:
|
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:
|
with open(file, 'rb') as f:
|
||||||
mkv = enzyme.MKV(f)
|
mkv = enzyme.MKV(f)
|
||||||
return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks]
|
return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks]
|
||||||
|
|
Loading…
Reference in a new issue