2019-04-23 12:35:50 +00:00
|
|
|
import enzyme
|
|
|
|
import logging
|
2019-04-23 20:19:25 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2019-04-23 12:35:50 +00:00
|
|
|
|
|
|
|
from utils import get_binary
|
|
|
|
|
2019-04-23 20:28:35 +00:00
|
|
|
class NotMKVAndNoFFprobe(Exception):
|
2019-04-23 20:19:25 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
class FFprobeError(Exception):
|
|
|
|
pass
|
|
|
|
|
2019-04-23 12:35:50 +00:00
|
|
|
class EmbeddedSubsReader:
|
|
|
|
def __init__(self):
|
|
|
|
self.ffprobe = get_binary("ffprobe")
|
|
|
|
|
|
|
|
def list_languages(self, file):
|
|
|
|
if self.ffprobe:
|
2019-04-23 20:19:25 +00:00
|
|
|
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':
|
2019-04-23 20:28:35 +00:00
|
|
|
raise NotMKVAndNoFFprobe()
|
2019-04-23 20:19:25 +00:00
|
|
|
with open(file, 'rb') as f:
|
|
|
|
mkv = enzyme.MKV(f)
|
|
|
|
return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks]
|
2019-04-23 12:35:50 +00:00
|
|
|
|
|
|
|
embedded_subs_reader = EmbeddedSubsReader()
|