Use pyprobe instead of calling ffprobe executable directly.

This commit is contained in:
Louis Vézina 2019-08-25 22:11:30 -04:00
parent 4b12dea4cf
commit e4f4f9e357
1 changed files with 15 additions and 17 deletions

View File

@ -4,8 +4,8 @@ import os
import subprocess
import locale
from config import settings
from utils import get_binary
from pyprobe.pyprobe import VideoFileParser
class NotMKVAndNoFFprobe(Exception):
pass
@ -20,24 +20,22 @@ class EmbeddedSubsReader:
def list_languages(self, file):
subtitles_list = []
if os.path.splitext(file)[1] == '.mkv':
with open(file, 'rb') as f:
mkv = enzyme.MKV(f)
for subtitle_track in mkv.subtitle_tracks:
subtitles_list.append([subtitle_track.language, subtitle_track.forced])
if self.ffprobe:
parser = VideoFileParser(ffprobe=self.ffprobe, includeMissing=True, rawMode=False)
data = parser.parseFfprobe(file)
detected_languages = []
for detected_language in data['subtitles']:
subtitles_list.append([detected_language['language'], detected_language['forced']])
else:
if self.ffprobe:
detected_languages = []
try:
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")
except subprocess.CalledProcessError as e:
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
if os.path.splitext(file)[1] == '.mkv':
with open(file, 'rb') as f:
mkv = enzyme.MKV(f)
for subtitle_track in mkv.subtitle_tracks:
subtitles_list.append([subtitle_track.language, subtitle_track.forced])
return subtitles_list
embedded_subs_reader = EmbeddedSubsReader()
embedded_subs_reader = EmbeddedSubsReader()