1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-25 17:17:12 +00:00
bazarr/bazarr/embedded_subs_reader.py

46 lines
1.5 KiB
Python
Raw Normal View History

2019-09-13 19:12:26 +00:00
from __future__ import absolute_import
import enzyme
2019-10-20 12:03:55 +00:00
from enzyme.exceptions import MalformedMKVError
import logging
import os
import subprocess
2019-05-02 00:26:48 +00:00
import locale
from utils import get_binary
from pyprobe.pyprobe import VideoFileParser
2019-04-23 20:28:35 +00:00
class NotMKVAndNoFFprobe(Exception):
pass
class FFprobeError(Exception):
pass
class EmbeddedSubsReader:
def __init__(self):
self.ffprobe = get_binary("ffprobe")
def list_languages(self, file):
2019-04-27 12:13:47 +00:00
subtitles_list = []
if self.ffprobe:
parser = VideoFileParser(ffprobe=self.ffprobe, includeMissing=True, rawMode=False)
data = parser.parseFfprobe(file)
for detected_language in data['subtitles']:
subtitles_list.append([detected_language['language'], detected_language['forced'], detected_language["codec"]])
2019-04-27 12:13:47 +00:00
else:
if os.path.splitext(file)[1] == '.mkv':
with open(file, 'rb') as f:
2019-10-20 12:03:55 +00:00
try:
mkv = enzyme.MKV(f)
except MalformedMKVError:
logging.error('BAZARR cannot analyze this MKV with our built-in MKV parser, you should install ffmpeg: ' + file)
else:
for subtitle_track in mkv.subtitle_tracks:
subtitles_list.append([subtitle_track.language, subtitle_track.forced, subtitle_track.codec_id])
2019-04-27 12:13:47 +00:00
return subtitles_list
embedded_subs_reader = EmbeddedSubsReader()