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")
def list_languages(self, file):
if self.ffprobe:
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")
except subprocess.CalledProcessError as e:
raise FFprobeError(e.output)
if os.path.splitext(file)[1] != '.mkv':
raise NotMKVAndNoFFprobe()
with open(file, 'rb') as f:
mkv = enzyme.MKV(f)
return [subtitle_track.language for subtitle_track in mkv.subtitle_tracks]
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:
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], 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 as not forced
return subtitles_list
embedded_subs_reader = EmbeddedSubsReader()

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

@ -175,7 +175,7 @@
%>
<tr>
<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>
%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]}}>
@ -225,12 +225,12 @@
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]}}>
{{!'<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>
</a>
%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]}}>
{{!'<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>
</a>
<%
@ -240,7 +240,7 @@
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]}}>
{{!'<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>
</a>
<%

Loading…
Cancel
Save