mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-25 01:02:19 +00:00
d31299870d
# Conflicts: # bazarr/list_subtitles.py # bazarr/main.py
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from __future__ import absolute_import
|
|
import enzyme
|
|
from enzyme.exceptions import MalformedMKVError
|
|
import logging
|
|
import os
|
|
import subprocess
|
|
import locale
|
|
|
|
from utils import get_binary
|
|
from pyprobe.pyprobe import VideoFileParser
|
|
|
|
class NotMKVAndNoFFprobe(Exception):
|
|
pass
|
|
|
|
class FFprobeError(Exception):
|
|
pass
|
|
|
|
class EmbeddedSubsReader:
|
|
def __init__(self):
|
|
self.ffprobe = get_binary("ffprobe")
|
|
|
|
def list_languages(self, file):
|
|
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"]])
|
|
else:
|
|
if os.path.splitext(file)[1] == '.mkv':
|
|
with open(file, 'rb') as f:
|
|
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])
|
|
|
|
return subtitles_list
|
|
|
|
|
|
embedded_subs_reader = EmbeddedSubsReader()
|