2019-09-13 19:12:26 +00:00
|
|
|
from __future__ import absolute_import
|
2019-04-23 12:35:50 +00:00
|
|
|
import enzyme
|
2019-10-20 12:03:55 +00:00
|
|
|
from enzyme.exceptions import MalformedMKVError
|
2019-04-23 12:35:50 +00:00
|
|
|
import logging
|
2019-04-23 20:19:25 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2019-05-02 00:26:48 +00:00
|
|
|
import locale
|
2019-04-23 12:35:50 +00:00
|
|
|
|
|
|
|
from utils import get_binary
|
2019-08-26 02:11:30 +00:00
|
|
|
from pyprobe.pyprobe import VideoFileParser
|
2019-04-23 12:35:50 +00:00
|
|
|
|
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):
|
2019-04-27 12:13:47 +00:00
|
|
|
subtitles_list = []
|
|
|
|
|
2019-08-26 02:11:30 +00:00
|
|
|
if self.ffprobe:
|
|
|
|
parser = VideoFileParser(ffprobe=self.ffprobe, includeMissing=True, rawMode=False)
|
|
|
|
data = parser.parseFfprobe(file)
|
|
|
|
|
|
|
|
for detected_language in data['subtitles']:
|
2019-09-14 22:15:59 +00:00
|
|
|
subtitles_list.append([detected_language['language'], detected_language['forced'], detected_language["codec"]])
|
2019-04-27 12:13:47 +00:00
|
|
|
else:
|
2019-08-26 02:11:30 +00:00
|
|
|
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)
|
2019-11-04 11:34:33 +00:00
|
|
|
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
|
|
|
|
|
2019-04-23 12:35:50 +00:00
|
|
|
|
2019-08-26 02:11:30 +00:00
|
|
|
embedded_subs_reader = EmbeddedSubsReader()
|