Continuing development.

pull/479/head
Louis Vézina 6 years ago
parent 05ec091f69
commit 93e061462a

@ -16,15 +16,26 @@ class EmbeddedSubsReader:
self.ffprobe = get_binary("ffprobe") self.ffprobe = get_binary("ffprobe")
def list_languages(self, file): 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])
else:
if self.ffprobe: if self.ffprobe:
detected_languages = []
try: try:
return subprocess.check_output([self.ffprobe, "-loglevel", "error", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file], universal_newlines=True, stderr=subprocess.STDOUT).strip().split("\n") detected_languages = subprocess.check_output([self.ffprobe, "-loglevel", "error", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file], universal_newlines=True, stderr=subprocess.STDOUT).strip().split("\n")
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
raise FFprobeError(e.output) raise FFprobeError(e.output)
if os.path.splitext(file)[1] != '.mkv': else:
raise NotMKVAndNoFFprobe() for detected_language in detected_languages:
with open(file, 'rb') as f: subtitles_list.append([detected_language, False])
mkv = enzyme.MKV(f) # I can't get the forced flag from ffprobe so I always assume it as not forced
return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks]
return subtitles_list
embedded_subs_reader = EmbeddedSubsReader() embedded_subs_reader = EmbeddedSubsReader()

@ -35,10 +35,12 @@ def store_subtitles(file):
logging.debug("BAZARR is trying to index embedded subtitles.") logging.debug("BAZARR is trying to index embedded subtitles.")
try: try:
subtitle_languages = embedded_subs_reader.list_languages(file) subtitle_languages = embedded_subs_reader.list_languages(file)
for subtitle_language in subtitle_languages: for subtitle_language, subtitle_forced in subtitle_languages:
try: try:
if alpha2_from_alpha3(subtitle_language) is not None: if alpha2_from_alpha3(subtitle_language) is not None:
lang = str(alpha2_from_alpha3(subtitle_language)) lang = str(alpha2_from_alpha3(subtitle_language))
if subtitle_forced:
lang = lang + ":forced"
logging.debug("BAZARR embedded subtitles detected: " + lang) logging.debug("BAZARR embedded subtitles detected: " + lang)
actual_subtitles.append([lang, None]) actual_subtitles.append([lang, None])
except: except:
@ -122,11 +124,11 @@ def store_subtitles_movie(file):
logging.debug("BAZARR is trying to index embedded subtitles.") logging.debug("BAZARR is trying to index embedded subtitles.")
try: try:
subtitle_languages = embedded_subs_reader.list_languages(file) subtitle_languages = embedded_subs_reader.list_languages(file)
for subtitle_language in subtitle_languages: for subtitle_language, subtitle_forced in subtitle_languages:
try: try:
if alpha2_from_alpha3(subtitle_language) is not None: if alpha2_from_alpha3(subtitle_language) is not None:
lang = str(alpha2_from_alpha3(subtitle_language)) lang = str(alpha2_from_alpha3(subtitle_language))
if subtitle_track.forced: if subtitle_forced:
lang = lang + ':forced' lang = lang + ':forced'
logging.debug("BAZARR embedded subtitles detected: " + lang) logging.debug("BAZARR embedded subtitles detected: " + lang)
actual_subtitles.append([lang, None]) actual_subtitles.append([lang, None])

@ -175,7 +175,7 @@
%> %>
<tr> <tr>
<td>{{path_replace_movie(subtitles_file[1]) if subtitles_file[1] is not None else 'Video file subtitles track'}}</td> <td>{{path_replace_movie(subtitles_file[1]) if subtitles_file[1] is not None else 'Video file subtitles track'}}</td>
<td><div class="ui tiny inverted label" style='background-color: #777777;'>{{!'<span class="ui" data-tooltip="Forced" data-inverted=""><i class="exclamation icon"></i></span>' if forced else ''}}{{language_from_alpha2(subtitles_file[0].split(':')[0])}}</div></td> <td><div class="ui tiny inverted label" style='background-color: #777777;'>{{language_from_alpha2(subtitles_file[0].split(':')[0])}}{{' forced' if forced else ''}}</div></td>
<td> <td>
%if subtitles_file[1] is not None: %if subtitles_file[1] is not None:
<a class="remove_subtitles ui inverted basic compact icon" data-tooltip="Delete subtitles file from disk" data-inverted="" data-position="top right" data-moviePath="{{details[8]}}" data-subtitlesPath="{{path_replace_movie(subtitles_file[1])}}" data-language="{{alpha3_from_alpha2(subtitles_file[0].split(':')[0])}}" data-radarrId={{details[10]}}> <a class="remove_subtitles ui inverted basic compact icon" data-tooltip="Delete subtitles file from disk" data-inverted="" data-position="top right" data-moviePath="{{details[8]}}" data-subtitlesPath="{{path_replace_movie(subtitles_file[1])}}" data-language="{{alpha3_from_alpha2(subtitles_file[0].split(':')[0])}}" data-radarrId={{details[10]}}>
@ -225,12 +225,12 @@
if search_active(lang[1]): if search_active(lang[1]):
%> %>
<a class="get_subtitle ui small blue label" data-moviePath="{{details[8]}}" data-scenename="{{details[12]}}" data-language="{{alpha3_from_alpha2(str(missing_subs_language.split(':')[0]))}}" data-hi="{{details[4]}}" data-forced="{{details[15]}}" data-radarrId={{details[10]}}> <a class="get_subtitle ui small blue label" data-moviePath="{{details[8]}}" data-scenename="{{details[12]}}" data-language="{{alpha3_from_alpha2(str(missing_subs_language.split(':')[0]))}}" data-hi="{{details[4]}}" data-forced="{{details[15]}}" data-radarrId={{details[10]}}>
{{!'<span class="ui" data-tooltip="Forced" data-inverted=""><i class="exclamation icon"></i></span>' if forced else ''}}{{language_from_alpha2(str(missing_subs_language.split(':')[0]))}} {{language_from_alpha2(str(missing_subs_language.split(':')[0]))}}{{' forced' if forced else ''}}
<i style="margin-left:3px; margin-right:0" class="search icon"></i> <i style="margin-left:3px; margin-right:0" class="search icon"></i>
</a> </a>
%else: %else:
<a data-tooltip="Automatic searching delayed (adaptive search)" data-position="top left" data-inverted="" class="get_subtitle ui small red label" data-moviePath="{{details[8]}}" data-scenename="{{details[12]}}" data-language="{{alpha3_from_alpha2(str(missing_subs_language.split(':')[0]))}}" data-hi="{{details[4]}}" data-forced="{{details[15]}}" data-radarrId={{details[10]}}> <a data-tooltip="Automatic searching delayed (adaptive search)" data-position="top left" data-inverted="" class="get_subtitle ui small red label" data-moviePath="{{details[8]}}" data-scenename="{{details[12]}}" data-language="{{alpha3_from_alpha2(str(missing_subs_language.split(':')[0]))}}" data-hi="{{details[4]}}" data-forced="{{details[15]}}" data-radarrId={{details[10]}}>
{{!'<span class="ui" data-tooltip="Forced" data-inverted=""><i class="exclamation icon"></i></span>' if forced else ''}}{{language_from_alpha2(str(missing_subs_language.split(':')[0]))}} {{language_from_alpha2(str(missing_subs_language.split(':')[0]))}}{{' forced' if forced else ''}}
<i style="margin-left:3px; margin-right:0" class="search icon"></i> <i style="margin-left:3px; margin-right:0" class="search icon"></i>
</a> </a>
<% <%
@ -240,7 +240,7 @@
else: else:
%> %>
<a class="get_subtitle ui small blue label" data-moviePath="{{details[8]}}" data-scenename="{{details[12]}}" data-language="{{alpha3_from_alpha2(str(missing_subs_language.split(':')[0]))}}" data-hi="{{details[4]}}" data-forced="{{details[15]}}" data-radarrId={{details[10]}}> <a class="get_subtitle ui small blue label" data-moviePath="{{details[8]}}" data-scenename="{{details[12]}}" data-language="{{alpha3_from_alpha2(str(missing_subs_language.split(':')[0]))}}" data-hi="{{details[4]}}" data-forced="{{details[15]}}" data-radarrId={{details[10]}}>
{{!'<span class="ui" data-tooltip="Forced" data-inverted=""><i class="exclamation icon"></i></span>' if forced else ''}}{{language_from_alpha2(str(missing_subs_language.split(':')[0]))}} {{language_from_alpha2(str(missing_subs_language.split(':')[0]))}}{{' forced' if forced else ''}}
<i style="margin-left:3px; margin-right:0" class="search icon"></i> <i style="margin-left:3px; margin-right:0" class="search icon"></i>
</a> </a>
<% <%

Loading…
Cancel
Save