mirror of https://github.com/morpheus65535/bazarr
Use pyprobe instead of calling ffprobe executable directly.
This commit is contained in:
parent
4b12dea4cf
commit
e4f4f9e357
|
@ -4,8 +4,8 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import locale
|
import locale
|
||||||
|
|
||||||
from config import settings
|
|
||||||
from utils import get_binary
|
from utils import get_binary
|
||||||
|
from pyprobe.pyprobe import VideoFileParser
|
||||||
|
|
||||||
class NotMKVAndNoFFprobe(Exception):
|
class NotMKVAndNoFFprobe(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -20,22 +20,20 @@ class EmbeddedSubsReader:
|
||||||
def list_languages(self, file):
|
def list_languages(self, file):
|
||||||
subtitles_list = []
|
subtitles_list = []
|
||||||
|
|
||||||
if os.path.splitext(file)[1] == '.mkv':
|
if self.ffprobe:
|
||||||
with open(file, 'rb') as f:
|
parser = VideoFileParser(ffprobe=self.ffprobe, includeMissing=True, rawMode=False)
|
||||||
mkv = enzyme.MKV(f)
|
data = parser.parseFfprobe(file)
|
||||||
for subtitle_track in mkv.subtitle_tracks:
|
|
||||||
subtitles_list.append([subtitle_track.language, subtitle_track.forced])
|
detected_languages = []
|
||||||
|
|
||||||
|
for detected_language in data['subtitles']:
|
||||||
|
subtitles_list.append([detected_language['language'], detected_language['forced']])
|
||||||
else:
|
else:
|
||||||
if self.ffprobe:
|
if os.path.splitext(file)[1] == '.mkv':
|
||||||
detected_languages = []
|
with open(file, 'rb') as f:
|
||||||
try:
|
mkv = enzyme.MKV(f)
|
||||||
detected_languages = subprocess.check_output([self.ffprobe, "-loglevel", "error", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file.encode(locale.getpreferredencoding())], universal_newlines=True, stderr=subprocess.STDOUT).strip().split("\n")
|
for subtitle_track in mkv.subtitle_tracks:
|
||||||
except subprocess.CalledProcessError as e:
|
subtitles_list.append([subtitle_track.language, subtitle_track.forced])
|
||||||
raise FFprobeError(e.output)
|
|
||||||
else:
|
|
||||||
for detected_language in detected_languages:
|
|
||||||
subtitles_list.append([detected_language, False])
|
|
||||||
# I can't get the forced flag from ffprobe so I always assume it isn't forced
|
|
||||||
|
|
||||||
return subtitles_list
|
return subtitles_list
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue