mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-04-23 22:27:17 -04:00
Adding post-processing options
This commit is contained in:
parent
36e6557a1c
commit
2adb299eb8
5 changed files with 126 additions and 4 deletions
|
@ -400,10 +400,16 @@ def save_settings():
|
|||
else:
|
||||
settings_general_scenename = 'True'
|
||||
settings_general_minimum_score = request.forms.get('settings_general_minimum_score')
|
||||
settings_general_use_postprocessing = request.forms.get('settings_general_use_postprocessing')
|
||||
if settings_general_use_postprocessing is None:
|
||||
settings_general_use_postprocessing = 'False'
|
||||
else:
|
||||
settings_general_use_postprocessing = 'True'
|
||||
settings_general_postprocessing_cmd = request.forms.get('settings_general_postprocessing_cmd')
|
||||
|
||||
before = c.execute("SELECT ip, port, base_url FROM table_settings_general").fetchone()
|
||||
after = (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl))
|
||||
c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?", (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_loglevel), unicode(settings_general_branch), unicode(settings_general_automatic), unicode(settings_general_single_language), unicode(settings_general_minimum_score), unicode(settings_general_scenename) ))
|
||||
c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?, use_postprocessing=?, postprocessing_cmd=?", (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_loglevel), unicode(settings_general_branch), unicode(settings_general_automatic), unicode(settings_general_single_language), unicode(settings_general_minimum_score), unicode(settings_general_scenename), unicode(settings_general_use_postprocessing), unicode(settings_general_postprocessing_cmd) ))
|
||||
conn.commit()
|
||||
if after != before:
|
||||
configured()
|
||||
|
|
|
@ -29,8 +29,10 @@ def get_general_settings():
|
|||
single_language = general_settings[9]
|
||||
minimum_score = general_settings[10]
|
||||
use_scenename = general_settings[11]
|
||||
use_postprocessing = general_settings[12]
|
||||
postprocessing_cmd = general_settings[13]
|
||||
|
||||
return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename]
|
||||
return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd]
|
||||
|
||||
def path_replace(path):
|
||||
for path_mapping in path_mappings:
|
||||
|
@ -54,6 +56,14 @@ def path_replace_reverse(path):
|
|||
break
|
||||
return path
|
||||
|
||||
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3):
|
||||
pp_command = pp_command.replace('{{episode}}', episode)
|
||||
pp_command = pp_command.replace('{{subtitles}}', subtitles)
|
||||
pp_command = pp_command.replace('{{language}}', language)
|
||||
pp_command = pp_command.replace('{{language_code2}}', language_code2)
|
||||
pp_command = pp_command.replace('{{language_code3}}', language_code3)
|
||||
return pp_command
|
||||
|
||||
result = get_general_settings()
|
||||
ip = result[0]
|
||||
port = result[1]
|
||||
|
@ -65,3 +75,5 @@ automatic = result[6]
|
|||
single_language = result[7]
|
||||
minimum_score = result[8]
|
||||
use_scenename = result[9]
|
||||
use_processing = result[10]
|
||||
postprocessing_cmd = result[11]
|
|
@ -2,9 +2,11 @@ import os
|
|||
import sqlite3
|
||||
import ast
|
||||
import logging
|
||||
import subprocess
|
||||
from babelfish import *
|
||||
from subliminal import *
|
||||
from pycountry import *
|
||||
from bs4 import UnicodeDammit
|
||||
from get_general_settings import *
|
||||
from list_subtitles import *
|
||||
from utils import *
|
||||
|
@ -16,6 +18,8 @@ region.configure('dogpile.cache.memory')
|
|||
def download_subtitle(path, language, hi, providers, providers_auth, sceneName):
|
||||
minimum_score = float(get_general_settings()[8]) / 100 * 360
|
||||
use_scenename = get_general_settings()[9]
|
||||
use_postprocessing = get_general_settings()[10]
|
||||
postprocessing_cmd = get_general_settings()[11]
|
||||
try:
|
||||
if sceneName is None or use_scenename == "False":
|
||||
used_sceneName = False
|
||||
|
@ -52,13 +56,43 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName):
|
|||
logging.error('Error saving subtitles file to disk.')
|
||||
return None
|
||||
else:
|
||||
downloaded_provider = str(result[0]).strip('<>').split(' ')[0][:-8]
|
||||
downloaded_language = pycountry.languages.lookup(str(str(result[0]).strip('<>').split(' ')[2].strip('[]'))).name
|
||||
downloaded_provider = str(result[0][0]).strip('<>').split(' ')[0][:-8]
|
||||
downloaded_language = pycountry.languages.lookup(str(str(result[0][0]).strip('<>').split(' ')[2].strip('[]'))).name
|
||||
downloaded_language_code2 = pycountry.languages.lookup(downloaded_language).alpha_2
|
||||
downloaded_language_code3 = pycountry.languages.lookup(downloaded_language).alpha_3
|
||||
downloaded_path = result[1]
|
||||
if used_sceneName == True:
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(score) + "% using this scene name obtained from Sonarr: " + sceneName
|
||||
else:
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(score) + "% using filename guessing."
|
||||
|
||||
if use_postprocessing == "True":
|
||||
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language, downloaded_language_code2, downloaded_language_code3)
|
||||
try:
|
||||
if os.name == 'nt':
|
||||
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
# wait for the process to terminate
|
||||
out_codepage, err_codepage = codepage.communicate()
|
||||
encoding = out_codepage.split(':')[-1].strip()
|
||||
|
||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
# wait for the process to terminate
|
||||
out, err = process.communicate()
|
||||
|
||||
if os.name == 'nt':
|
||||
out = out.decode(encoding)
|
||||
|
||||
except:
|
||||
if out == "":
|
||||
logging.error('Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
else:
|
||||
logging.error('Post-processing result for file ' + path + ' : ' + out)
|
||||
else:
|
||||
if out == "":
|
||||
logging.info('Post-processing result for file ' + path + ' : Nothing returned from command execution')
|
||||
else:
|
||||
logging.info('Post-processing result for file ' + path + ' : ' + out)
|
||||
|
||||
return message
|
||||
|
||||
def series_download_subtitles(no):
|
||||
|
|
12
update_db.py
12
update_db.py
|
@ -72,6 +72,18 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
|
|||
else:
|
||||
c.execute('UPDATE table_settings_general SET use_scenename="True"')
|
||||
|
||||
try:
|
||||
c.execute('alter table table_settings_general add column "use_postprocessing" "text"')
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
c.execute('UPDATE table_settings_general SET use_postprocessing="False"')
|
||||
|
||||
try:
|
||||
c.execute('alter table table_settings_general add column "postprocessing_cmd" "text"')
|
||||
except:
|
||||
pass
|
||||
|
||||
# Commit change to db
|
||||
db.commit()
|
||||
|
||||
|
|
|
@ -231,6 +231,48 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui dividing header">Post-processing</div>
|
||||
<div class="twelve wide column">
|
||||
<div class="ui grid">
|
||||
<div class="middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Use post-processing</label>
|
||||
</div>
|
||||
<div class="one wide column">
|
||||
<div id="settings_use_postprocessing" class="ui toggle checkbox" data-postprocessing={{settings_general[12]}}>
|
||||
<input name="settings_general_use_postprocessing" type="checkbox">
|
||||
<label></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapsed column">
|
||||
<div class="collapsed center aligned column">
|
||||
<div class="ui basic icon" data-tooltip="Enable the post-processing execution after downloading a subtitles." data-inverted="">
|
||||
<i class="help circle large icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="middle aligned row">
|
||||
<div class="right aligned four wide column">
|
||||
<label>Post-processing command</label>
|
||||
</div>
|
||||
<div class="five wide column">
|
||||
<div id="settings_general_postprocessing_cmd_div" class="ui fluid input">
|
||||
<input name="settings_general_postprocessing_cmd" type="text" value="{{settings_general[13] if settings_general[13] != None else ''}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapsed column">
|
||||
<div class="collapsed center aligned column">
|
||||
<div class="ui basic icon" data-tooltip="You can use those variables in your command (include the double curly brace): {{episode}} {{subtitles}} {{language}} {{language-code2}} {{language-code3}}" data-inverted="">
|
||||
<i class="help circle large icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui dividing header">Updates</div>
|
||||
<div class="twelve wide column">
|
||||
<div class="ui grid">
|
||||
|
@ -647,6 +689,22 @@
|
|||
$("#settings_scenename").checkbox('uncheck');
|
||||
}
|
||||
|
||||
if ($('#settings_use_postprocessing').data("postprocessing") == "True") {
|
||||
$("#settings_use_postprocessing").checkbox('check');
|
||||
$("#settings_general_postprocessing_cmd_div").removeClass('disabled');
|
||||
} else {
|
||||
$("#settings_use_postprocessing").checkbox('uncheck');
|
||||
$("#settings_general_postprocessing_cmd_div").addClass('disabled');
|
||||
}
|
||||
|
||||
$("#settings_use_postprocessing").change(function(i, obj) {
|
||||
if ($("#settings_use_postprocessing").checkbox('is checked')) {
|
||||
$("#settings_general_postprocessing_cmd_div").removeClass('disabled');
|
||||
} else {
|
||||
$("#settings_general_postprocessing_cmd_div").addClass('disabled');
|
||||
}
|
||||
});
|
||||
|
||||
$('.notifier_enabled').each(function(i, obj) {
|
||||
if ($(this).data("enabled") == 1) {
|
||||
$(this).checkbox('check');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue