mirror of https://github.com/morpheus65535/bazarr
add subtitle mods to tools dialog
This commit is contained in:
parent
49dd078fa1
commit
ea71a557ea
|
@ -30,7 +30,7 @@ from list_subtitles import store_subtitles, store_subtitles_movie, series_scan_s
|
|||
list_missing_subtitles, list_missing_subtitles_movies
|
||||
from utils import history_log, history_log_movie, blacklist_log, blacklist_delete, blacklist_delete_all, \
|
||||
blacklist_log_movie, blacklist_delete_movie, blacklist_delete_all_movie, get_sonarr_version, get_radarr_version, \
|
||||
delete_subtitles
|
||||
delete_subtitles, subtitles_apply_mods
|
||||
from get_providers import get_providers, get_providers_auth, list_throttled_providers, reset_throttled_providers
|
||||
from event_handler import event_stream
|
||||
from scheduler import scheduler
|
||||
|
@ -1748,6 +1748,18 @@ class SyncSubtitles(Resource):
|
|||
return '', 200
|
||||
|
||||
|
||||
class SubMods(Resource):
|
||||
@authenticate
|
||||
def post(self):
|
||||
language = request.form.get('language')
|
||||
subtitles_path = request.form.get('subtitlesPath')
|
||||
mod = request.form.get('mod')
|
||||
|
||||
subtitles_apply_mods(language, subtitles_path, [mod])
|
||||
|
||||
return '', 200
|
||||
|
||||
|
||||
class BrowseBazarrFS(Resource):
|
||||
@authenticate
|
||||
def get(self):
|
||||
|
@ -1844,6 +1856,7 @@ api.add_resource(BlacklistMovieSubtitlesRemove, '/blacklist_movie_subtitles_remo
|
|||
api.add_resource(BlacklistMovieSubtitlesRemoveAll, '/blacklist_movie_subtitles_remove_all')
|
||||
|
||||
api.add_resource(SyncSubtitles, '/sync_subtitles')
|
||||
api.add_resource(SubMods, '/sub_mods')
|
||||
|
||||
api.add_resource(BrowseBazarrFS, '/browse_bazarr_filesystem')
|
||||
api.add_resource(BrowseSonarrFS, '/browse_sonarr_filesystem')
|
||||
|
|
|
@ -11,10 +11,11 @@ from get_args import args
|
|||
from config import settings, url_sonarr, url_radarr
|
||||
from database import database
|
||||
from event_handler import event_stream
|
||||
from get_languages import alpha2_from_alpha3, language_from_alpha3
|
||||
from get_languages import alpha2_from_alpha3, language_from_alpha3, alpha3_from_alpha2
|
||||
from helper import path_mappings
|
||||
from list_subtitles import store_subtitles, store_subtitles_movie
|
||||
|
||||
from subliminal_patch.subtitle import Subtitle
|
||||
from subzero.language import Language
|
||||
from subliminal import region as subliminal_cache_region
|
||||
import datetime
|
||||
import glob
|
||||
|
@ -250,3 +251,29 @@ def delete_subtitles(media_type, language, forced, media_path, subtitles_path, s
|
|||
store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path)
|
||||
notify_radarr(radarr_id)
|
||||
return True
|
||||
|
||||
|
||||
def subtitles_apply_mods(language, subtitle_path, mods):
|
||||
|
||||
if language == 'pob':
|
||||
lang_obj = Language('por', 'BR')
|
||||
else:
|
||||
lang_obj = Language(language)
|
||||
|
||||
sub = Subtitle(lang_obj, mods=mods)
|
||||
with open(subtitle_path, 'rb') as f:
|
||||
sub.content = f.read()
|
||||
|
||||
if not sub.is_valid():
|
||||
logging.exception('BAZARR Invalid subtitle file: ' + subtitle_path)
|
||||
return
|
||||
|
||||
content = sub.get_modified_content()
|
||||
if content:
|
||||
if os.path.exists(subtitle_path):
|
||||
os.remove(subtitle_path)
|
||||
|
||||
with open(subtitle_path, 'wb') as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@
|
|||
<tr>
|
||||
<th style="text-align: left;">Language:</th>
|
||||
<th style="text-align: left;">Filename:</th>
|
||||
<th style="text-align: left;">Sync:</th>
|
||||
<th style="text-align: left;">Tools:</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
@ -1021,7 +1021,17 @@
|
|||
{
|
||||
data: null,
|
||||
"render": function (data) {
|
||||
return '<a href="" class="subtitles_sync badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-videopath="' + data.videopath + '"><i class="far fa-play-circle"></i></a>';
|
||||
var tools = '';
|
||||
|
||||
tools += '<a href="" class="subtitles_sync badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-videopath="' + data.videopath + '" data-toggle="tooltip" data-placement="right" title="Sync"><i class="far fa-play-circle"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "remove_HI" data-toggle="tooltip" data-placement="right" title="Remove HI-tags"><i class="fa fa-deaf"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "remove_tags" data-toggle="tooltip" data-placement="right" title="Remove style tags"><i class="fa fa-code"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "OCR_fixes" data-toggle="tooltip" data-placement="right" title="OCR Fixes"><i class="fa fa-image"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "common" data-toggle="tooltip" data-placement="right" title="Common Fixes"><i class="fas fa-magic"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "fix_uppercase" data-toggle="tooltip" data-placement="right" title="Fix Uppercase"><i class="fa fa-text-height"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "reverse_rtl" data-toggle="tooltip" data-placement="right" title="Reverse RTL"><i class="fa fa-exchange-alt"></i></a> ';
|
||||
|
||||
return tools;
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -1050,6 +1060,32 @@
|
|||
dataType: "json",
|
||||
data: values,
|
||||
beforeSend: function () {
|
||||
$('.subtitles_sync').tooltip('hide')
|
||||
cell.html('<div class="spinner-border spinner-border-sm" role="status"><span class="sr-only">Loading...</span></div>');
|
||||
},
|
||||
complete: function () {
|
||||
$('#episodeToolsModal').modal('hide');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#episode_tools_result').on('click', '.subtitles_mod', function (e) {
|
||||
e.preventDefault();
|
||||
const values = {
|
||||
language: $(this).attr("data-language"),
|
||||
subtitlesPath: $(this).attr("data-path"),
|
||||
mod: $(this).attr("data-mod"),
|
||||
};
|
||||
|
||||
var cell = $(this).parent();
|
||||
|
||||
$.ajax({
|
||||
url: "{{ url_for('api.submods') }}",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: values,
|
||||
beforeSend: function () {
|
||||
$('.subtitles_mod').tooltip('hide')
|
||||
cell.html('<div class="spinner-border spinner-border-sm" role="status"><span class="sr-only">Loading...</span></div>');
|
||||
},
|
||||
complete: function () {
|
||||
|
|
|
@ -334,7 +334,7 @@
|
|||
<tr>
|
||||
<th style="text-align: left;">Language:</th>
|
||||
<th style="text-align: left;">Filename:</th>
|
||||
<th style="text-align: left;">Sync:</th>
|
||||
<th style="text-align: left;">Tools:</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
@ -829,7 +829,17 @@
|
|||
{
|
||||
data: null,
|
||||
"render": function (data) {
|
||||
return '<a href="" class="subtitles_sync badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-videopath="' + data.videopath + '"><i class="far fa-play-circle"></i></a>';
|
||||
var tools = '';
|
||||
|
||||
tools += '<a href="" class="subtitles_sync badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-videopath="' + data.videopath + '" data-toggle="tooltip" data-placement="right" title="Sync"><i class="far fa-play-circle"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "remove_HI" data-toggle="tooltip" data-placement="right" title="Remove HI-tags"><i class="fa fa-deaf"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "remove_tags" data-toggle="tooltip" data-placement="right" title="Remove style tags"><i class="fa fa-code"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "OCR_fixes" data-toggle="tooltip" data-placement="right" title="OCR Fixes"><i class="fa fa-image"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "common" data-toggle="tooltip" data-placement="right" title="Common Fixes"><i class="fas fa-magic"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "fix_uppercase" data-toggle="tooltip" data-placement="right" title="Fix Uppercase"><i class="fa fa-text-height"></i></a> ';
|
||||
tools += '<a href="" class="subtitles_mod badge badge-secondary" data-language="' + data.language.code3 + '" data-path="' + data.path + '" data-mod = "reverse_rtl" data-toggle="tooltip" data-placement="right" title="Reverse RTL"><i class="fa fa-exchange-alt"></i></a> ';
|
||||
|
||||
return tools;
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -857,6 +867,7 @@
|
|||
dataType: "json",
|
||||
data: values,
|
||||
beforeSend: function () {
|
||||
$('.subtitles_sync').tooltip('hide')
|
||||
cell.html('<div class="spinner-border spinner-border-sm" role="status"><span class="sr-only">Loading...</span></div>');
|
||||
},
|
||||
complete: function (data) {
|
||||
|
@ -864,6 +875,31 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#movie_tools_result').on('click', '.subtitles_mod', function (e) {
|
||||
e.preventDefault();
|
||||
const values = {
|
||||
language: $(this).attr("data-language"),
|
||||
subtitlesPath: $(this).attr("data-path"),
|
||||
mod: $(this).attr("data-mod"),
|
||||
};
|
||||
|
||||
var cell = $(this).parent();
|
||||
|
||||
$.ajax({
|
||||
url: "{{ url_for('api.submods') }}",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: values,
|
||||
beforeSend: function () {
|
||||
$('.subtitles_mod').tooltip('hide')
|
||||
cell.html('<div class="spinner-border spinner-border-sm" role="status"><span class="sr-only">Loading...</span></div>');
|
||||
},
|
||||
complete: function () {
|
||||
$('#movieToolsModal').modal('hide');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function movieDetailsRefresh() {
|
||||
|
|
Loading…
Reference in New Issue