Added scenename and minimum score settings #48

pull/56/merge
morpheus65535 7 years ago
parent a363560f36
commit 3a87391868

@ -1,4 +1,4 @@
bazarr_version = '0.3.6'
bazarr_version = '0.3.7'
import os
import sys
@ -394,10 +394,16 @@ def save_settings():
settings_general_single_language = 'False'
else:
settings_general_single_language = 'True'
settings_general_scenename = request.forms.get('settings_general_scenename')
if settings_general_scenename is None:
settings_general_scenename = 'False'
else:
settings_general_scenename = 'True'
settings_general_minimum_score = request.forms.get('settings_general_minimum_score')
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=?", (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)))
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) ))
conn.commit()
if after != before:
configured()

@ -27,8 +27,10 @@ def get_general_settings():
branch = general_settings[5]
automatic = general_settings[6]
single_language = general_settings[9]
minimum_score = general_settings[10]
use_scenename = general_settings[11]
return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language]
return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename]
def path_replace(path):
for path_mapping in path_mappings:
@ -60,4 +62,6 @@ path_mappings = result[3]
log_level = result[4]
branch = result[5]
automatic = result[6]
single_language = result[7]
single_language = result[7]
minimum_score = result[8]
use_scenename = result[9]

@ -14,31 +14,34 @@ from notifier import send_notifications
region.configure('dogpile.cache.memory')
def download_subtitle(path, language, hi, providers, providers_auth, sceneName):
minimum_score = int(get_general_settings()[8])
use_scenename = get_general_settings()[9]
try:
if sceneName is None:
if sceneName is None or use_scenename == "False":
used_sceneName = False
video = scan_video(path)
else:
used_sceneName = True
video = Video.fromname(sceneName)
except Exception as e:
logging.exception('Error trying to extract information from this filename: ' + path)
return None
else:
try:
best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi, provider_configs=providers_auth)
best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, min_score=minimum_score, hearing_impaired=hi, provider_configs=providers_auth)
except Exception as e:
logging.exception('Error trying to best subtitles for this file: ' + path)
logging.exception('Error trying to get the best subtitles for this file: ' + path)
return None
else:
try:
best_subtitle = best_subtitles[video][0]
except:
pass
logging.debug('No subtitles found for ' + path)
return None
else:
single = get_general_settings()[7]
try:
if sceneName is not None:
if used_sceneName == True:
video = scan_video(path)
if single == 'True':
result = save_subtitles(video, [best_subtitle], single=True, encoding='utf-8')
@ -50,8 +53,8 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName):
else:
downloaded_provider = str(result[0]).strip('<>').split(' ')[0][:-8]
downloaded_language = pycountry.languages.lookup(str(str(result[0]).strip('<>').split(' ')[2].strip('[]'))).name
if sceneName is not None:
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " using scene name from Sonarr guessing."
if used_sceneName == True:
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " using this scene name obtained from Sonarr: " + sceneName
else:
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " using filename guessing."

@ -58,6 +58,20 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
from scheduler import execute_now
execute_now('update_all_episodes')
try:
c.execute('alter table table_settings_general add column "minimum_score" "text"')
except:
pass
else:
c.execute('UPDATE table_settings_general SET minimum_score="0"')
try:
c.execute('alter table table_settings_general add column "use_scenename" "text"')
except:
pass
else:
c.execute('UPDATE table_settings_general SET use_scenename="True"')
# Commit change to db
db.commit()

@ -366,11 +366,57 @@
</div>
<div class="ui bottom attached tab segment" data-tab="subliminal">
<div class="ui container"><button class="submit ui blue right floated button" type="submit" value="Submit" form="settings_form">Save</button></div>
<div class="ui dividing header">Subtitles providers</div>
<div class="twelve wide column">
<br><br><br>
<div class="ui container">
<div class="ui info message">
<p>Thanks to Diaoul for his work on <a href="https://github.com/Diaoul/subliminal" target="_blank">Subliminal</a> on which Bazarr is based.</p>
</div>
</div>
<div class="ui dividing header">Subtitles options</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Use Sonarr scene naming</label>
</div>
<div class="one wide column">
<div id="settings_scenename" class="ui toggle checkbox" data-scenename={{settings_general[11]}}>
<input name="settings_general_scenename" type="checkbox">
<label></label>
</div>
</div>
<div class="collapsed column">
<div class="collapsed center aligned column">
<div class="ui basic icon" data-tooltip="Use the scene name from Sonarr if available to circumvent usage of episode file renaming." 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>Minimum score</label>
</div>
<div class="two wide column">
<div class='field'>
<div class="ui input">
<input name="settings_general_minimum_score" type="number" min="0" max="100" step="5" onkeydown="return false" value="{{settings_general[10]}}">
</div>
</div>
</div>
<div class="collapsed column">
<div class="collapsed center aligned column">
<div class="ui basic icon" data-tooltip="Minimum score for a subtitle to be downloaded (0 to 100)." data-inverted="">
<i class="help circle large icon"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui dividing header">Subtitles providers</div>
<div class="twelve wide column">
<div class="ui orange message">
<p>Be aware that the more providers you enable, the longer it will take everytime you search for a subtitles.</p>
</div>
@ -396,7 +442,6 @@
</div>
</div>
</div>
<div class="ui dividing header">Providers authentication (optionnal)</div>
<div class="twelve wide column">
<div class="ui grid">
@ -596,6 +641,12 @@
$("#settings_single_language").checkbox('uncheck');
}
if ($('#settings_scenename').data("scenename") == "True") {
$("#settings_scenename").checkbox('check');
} else {
$("#settings_scenename").checkbox('uncheck');
}
$('.notifier_enabled').each(function(i, obj) {
if ($(this).data("enabled") == 1) {
$(this).checkbox('check');

Loading…
Cancel
Save