parent
730f0e1c10
commit
a5599d553e
@ -1,19 +1,30 @@
|
|||||||
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")
|
||||||
with open(file, 'rb') as f:
|
except subprocess.CalledProcessError as e:
|
||||||
mkv = enzyme.MKV(f)
|
raise FFprobeError(e.output)
|
||||||
return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks]
|
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()
|
embedded_subs_reader = EmbeddedSubsReader()
|
Loading…
Reference in new issue