added subzero mods support

This commit is contained in:
josdion 2020-07-29 16:11:45 +03:00
parent 131c43fae5
commit 1432f83bf4
5 changed files with 96 additions and 4 deletions

View File

@ -57,7 +57,8 @@ defaults = {
'upgrade_manual': 'True',
'anti_captcha_provider': 'None',
'wanted_search_frequency': '3',
'wanted_search_frequency_movie': '3'
'wanted_search_frequency_movie': '3',
'subzero_mods': ''
},
'auth': {
'type': 'None',

View File

@ -177,12 +177,16 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro
logging.info("BAZARR All providers are throttled")
return None
subz_mods = settings.general.subzero_mods.strip().split(',') if settings.general.subzero_mods.strip() else None
saved_any = False
if downloaded_subtitles:
for video, subtitles in downloaded_subtitles.items():
if not subtitles:
continue
for s in subtitles:
s.mods = subz_mods
try:
fld = get_target_folder(path)
chmod = int(settings.general.chmod, 8) if not sys.platform.startswith(
@ -417,6 +421,7 @@ def manual_download_subtitle(path, language, audio_language, hi, forced, subtitl
os.environ["SZ_KEEP_ENCODING"] = "True"
subtitle = pickle.loads(codecs.decode(subtitle.encode(), "base64"))
subtitle.mods = settings.general.subzero_mods.strip().split(',') if settings.general.subzero_mods.strip() else None
use_postprocessing = settings.general.getboolean('use_postprocessing')
postprocessing_cmd = settings.general.postprocessing_cmd
single = settings.general.getboolean('single_language')

View File

@ -30,7 +30,7 @@ class CommonFixes(SubtitleTextModification):
NReProcessor(re.compile(r'(?u)(\w|\b|\s|^)(-\s?-{1,2})'), r"\1—", name="CM_multidash"),
# line = _/-/\s
NReProcessor(re.compile(r'(?u)(^\W*[-_.:>~]+\W*$)'), "", name="<CM_non_word_only"),
NReProcessor(re.compile(r'(?u)(^\W*[-_.:<>~"\']+\W*$)'), "", name="CM_non_word_only"),
# remove >>
NReProcessor(re.compile(r'(?u)^\s?>>\s*'), "", name="CM_leading_crocodiles"),

View File

@ -48,7 +48,7 @@ class HearingImpaired(SubtitleTextModification):
name="HI_before_colon_noncaps"),
# brackets (only remove if at least 3 chars in brackets)
NReProcessor(re.compile(r'(?sux)-?%(t)s[([][^([)\]]+?(?=[A-zÀ-ž"\'.]{3,})[^([)\]]+[)\]][\s:]*%(t)s' %
NReProcessor(re.compile(r'(?sux)-?%(t)s["\']*[([][^([)\]]+?(?=[A-zÀ-ž"\'.]{3,})[^([)\]]+[)\]]["\']*[\s:]*%(t)s' %
{"t": TAG}), "", name="HI_brackets"),
#NReProcessor(re.compile(r'(?sux)-?%(t)s[([]%(t)s(?=[A-zÀ-ž"\'.]{3,})[^([)\]]+%(t)s$' % {"t": TAG}),
@ -92,7 +92,7 @@ class HearingImpaired(SubtitleTextModification):
"", name="HI_music_symbols_only"),
# remove music entries
NReProcessor(re.compile(r'(?ums)(^[-\s>~]*[♫♪]+\s*.+|.+\s*[♫♪]+\s*$)'),
NReProcessor(re.compile(r'(?ums)(^[-\s>~]*[*#¶♫♪]+\s*.+|.+\s*[*#¶♫♪]+\s*$)'),
"", name="HI_music"),
]

View File

@ -258,6 +258,78 @@
<label>Re-encode downloaded Subtitles to UTF8. Should be left enabled in most case.</label>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
<b>Hearing Impaired</b>
</div>
<div class="form-group col-sm-8">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input subzero_mods" id="remove_HI">
<span class="custom-control-label"></span>
</label>
<label>Removes HI-tags from subtitles (such as (SIRENS WAIL), DOCTOR: Rose!).</label>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
<b>Remove Tags</b>
</div>
<div class="form-group col-sm-8">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input subzero_mods" id="remove_tags">
<span class="custom-control-label"></span>
</label>
<label>Removes any font style tags from the subtitles (bold, italic, underline, colors, ...).</label>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
<b>OCR Fixes</b>
</div>
<div class="form-group col-sm-8">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input subzero_mods" id="OCR_fixes">
<span class="custom-control-label"></span>
</label>
<label>Fixes problems in subtitles introduced by OCR (custom implementation of SubtitleEdit's dictionaries).</label>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
<b>Common Fixes</b>
</div>
<div class="form-group col-sm-8">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input subzero_mods" id="common">
<span class="custom-control-label"></span>
</label>
<label> Fixes common issues in subtitles, such as punctuation (-- I don't know! -> ... I don't know!; over 9 000! -> over 9000!).</label>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
<b>Fix Uppercase</b>
</div>
<div class="form-group col-sm-8">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input subzero_mods" id="fix_uppercase">
<span class="custom-control-label"></span>
</label>
<label>Tries to make subtitles that are completely uppercase readable.</label>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
<b>Reverse RTL</b>
</div>
<div class="form-group col-sm-8">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input subzero_mods" id="reverse_rtl">
<span class="custom-control-label"></span>
</label>
<label>Reverses the punctuation in right-to-left subtitles for problematic playback devices.</label>
</div>
</div>
{% if not os.startswith('win') %}
<div class="row">
<div class="col-sm-3 text-right">
@ -551,9 +623,23 @@
$('#settings-general-use_postprocessing_threshold').prop('checked', {{'true' if settings.general.getboolean('use_postprocessing_threshold') else 'false'}}).trigger('change');
$('#settings-general-use_postprocessing_threshold_movie').prop('checked', {{'true' if settings.general.getboolean('use_postprocessing_threshold_movie') else 'false'}}).trigger('change');
$('.subzero_mods').prop('checked', false).trigger('change');
{% if settings.general.subzero_mods %}
$('{{settings.general.subzero_mods}}'.split(',')).each( function(i, item) {
$("[id=" + item + "]").prop('checked', true).trigger('change');
})
{% endif %}
$('#save_button').on('click', function () {
var formdata = new FormData(document.getElementById("settings_form"));
var enabled_subzero_mods = $(".subzero_mods").map(function () {
if ($(this).prop('checked')) {
return $(this).attr('id');
}
}).get().join(',');
formdata.append('settings-general-subzero_mods', enabled_subzero_mods)
// Make sure all checkbox input are sent with true/false value
$('input[type=checkbox]').each(function () {
formdata.set($(this).prop('id'), $(this).prop('checked'));