Completed custom folder for subtitles file.

pull/489/head
Louis Vézina 5 years ago
parent 1144b5b198
commit 56c0d0edcc

@ -344,7 +344,13 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
logging.debug('BAZARR Subtitles file downloaded for this file:' + path)
try:
score = round(subtitle.score / max_score * 100, 2)
fld = get_target_folder(path)
chmod = int(settings.general.chmod, 8) if not sys.platform.startswith('win') else None
saved_subtitles = save_subtitles(video.original_path, [subtitle], single=single,
tags=None, # fixme
directory=fld,
chmod=chmod,
# formats=("srt", "vtt")
path_decoder=force_unicode)
except Exception as e:

@ -3,6 +3,7 @@ import ast
import os
import re
import types
import logging
from config import settings
@ -73,24 +74,33 @@ def get_subtitle_destination_folder():
def get_target_folder(file_path):
fld = None
subfolder = settings.general.subfolder
fld_custom = str(settings.general.subfolder_custom).strip() \
if settings.general.subfolder_custom else None
if fld_custom or settings.general.subfolder != "current":
if subfolder != "current" and fld_custom:
# specific subFolder requested, create it if it doesn't exist
fld_base = os.path.split(file_path)[0]
if fld_custom:
if fld_custom.startswith("/"):
# absolute folder
fld = fld_custom
else:
fld = os.path.join(fld_base, fld_custom)
if subfolder == "absolute":
# absolute folder
fld = fld_custom
elif subfolder == "relative":
fld = os.path.join(fld_base, fld_custom)
else:
fld = os.path.join(fld_base, settings.general.subfolder)
fld = None
fld = force_unicode(fld)
if not os.path.exists(fld):
os.makedirs(fld)
if not os.path.isdir(fld):
try:
os.makedirs(fld)
except Exception as e:
logging.error('BAZARR is unable to create directory to save subtitles: ' + fld)
fld = None
else:
fld = None
return fld

@ -63,14 +63,15 @@ def store_subtitles(file):
pass
else:
for subtitle, language in subtitles.iteritems():
subtitle_path = get_external_subtitles_path(file, subtitle)
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)):
logging.debug("BAZARR external subtitles detected: " + "pb")
actual_subtitles.append(
[str("pb"), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
[str("pb"), path_replace_reverse(subtitle_path)])
elif str(language) != 'und':
logging.debug("BAZARR external subtitles detected: " + str(language))
actual_subtitles.append(
[str(language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
[str(language), path_replace_reverse(subtitle_path)])
else:
if os.path.splitext(subtitle)[1] != ".sub":
logging.debug("BAZARR falling back to file content analysis to detect language.")
@ -337,3 +338,30 @@ def movies_scan_subtitles(no):
store_subtitles_movie(path_replace_movie(movie[0]))
list_missing_subtitles_movies(no)
def get_external_subtitles_path(file, subtitle):
fld = os.path.dirname(file)
if settings.general.subfolder == "current":
path = os.path.join(fld, subtitle)
elif settings.general.subfolder == "absolute":
custom_fld = settings.general.subfolder_custom
if os.path.exists(os.path.join(fld, subtitle)):
path = os.path.join(fld, subtitle)
elif os.path.exists(os.path.join(custom_fld, subtitle)):
path = os.path.join(custom_fld, subtitle)
else:
path = None
elif settings.general.subfolder == "relative":
custom_fld = os.path.join(fld, settings.general.subfolder_custom)
if os.path.exists(os.path.join(fld, subtitle)):
path = os.path.join(fld, subtitle)
elif os.path.exists(os.path.join(custom_fld, subtitle)):
path = os.path.join(custom_fld, subtitle)
else:
path = None
else:
path = None
return path

@ -1634,11 +1634,9 @@ def remove_subtitles():
subtitlesPath = request.forms.get('subtitlesPath')
sonarrSeriesId = request.forms.get('sonarrSeriesId')
sonarrEpisodeId = request.forms.get('sonarrEpisodeId')
subfolder = ('/' + get_subtitle_destination_folder() + '/') if get_subtitle_destination_folder() else '/'
subtitlesPath = os.path.split(subtitlesPath)
try:
os.remove(subtitlesPath[0] + subfolder + subtitlesPath[1])
os.remove(subtitlesPath)
result = language_from_alpha3(language) + " subtitles deleted from disk."
history_log(0, sonarrSeriesId, sonarrEpisodeId, result)
except OSError:

@ -1065,12 +1065,9 @@
<div class="five wide column">
<select name="settings_subfolder" id="settings_subfolder"
class="ui fluid selection dropdown">
<option value="current">Current</option>
<option value="sub">sub</option>
<option value="subs">subs</option>
<option value="subtitle">subtitle</option>
<option value="subtitles">subtitles</option>
<option value="custom">Custom folder</option>
<option value="current">Alongside media file</option>
<option value="relative">Relative path to media file</option>
<option value="absolute">Absolute path</option>
</select>
</div>
@ -2138,12 +2135,12 @@
}
});
if ($('#settings_subfolder').val() !== "custom") {
if (($('#settings_subfolder').val() !== "relative") && ($('#settings_subfolder').val() !== "absolute")) {
$('.subfolder').hide();
}
$('#settings_subfolder').dropdown('setting', 'onChange', function(){
if ($('#settings_subfolder').val() !== "custom") {
if (($('#settings_subfolder').val() !== "relative") && ($('#settings_subfolder').val() !== "absolute")) {
$('.subfolder').hide();
}
else {
@ -2381,16 +2378,6 @@
]
},
% end
settings_subfolder_custom : {
rules : [
{
type: 'doesntContain[\\]',
},
{
type: 'doesntContain[/]',
}
]
},
settings_auth_password : {
depends: 'settings_auth_username',
rules : [

Loading…
Cancel
Save