Settings implementation

This commit is contained in:
Louis Vézina 2017-09-19 06:43:14 -04:00
parent 2edd6a328d
commit 6fa68abe6b
7 changed files with 240 additions and 24 deletions

BIN
bazarr.db

Binary file not shown.

View file

@ -15,6 +15,8 @@ import urllib
from init_db import *
from get_languages import *
from get_providers import *
from get_general_settings import *
from get_sonarr_settings import *
from list_subtitles import *
@ -108,16 +110,39 @@ def settings():
c = db.cursor()
c.execute("SELECT * FROM table_settings_general")
settings_general = c.fetchone()
c.execute("SELECT * FROM table_settings_languages")
c.execute("SELECT * FROM table_settings_languages ORDER BY name")
settings_languages = c.fetchall()
c.execute("SELECT * FROM table_settings_providers")
c.execute("SELECT * FROM table_settings_providers ORDER BY name")
settings_providers = c.fetchall()
c.execute("SELECT * FROM table_settings_sonarr")
settings_sonarr = c.fetchone()
c.execute("SELECT * FROM table_settings_subliminal")
settings_subliminal = c.fetchone()
c.close()
return template('settings', settings_general=settings_general, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, settings_subliminal=settings_subliminal)
return template('settings', settings_general=settings_general, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr)
@route('/save_settings', method='POST')
def save_settings():
lang = request.forms.getall('languages')
if len(lang) > 0:
if lang[0] == '':
lang = None
else:
pass
else:
lang = None
hi = request.forms.get('hearing_impaired')
if hi == "on":
hi = "True"
else:
hi = "False"
conn = sqlite3.connect('bazarr.db')
c = conn.cursor()
c.execute("UPDATE table_shows SET languages = ?, hearing_impaired = ? WHERE tvdbId LIKE ?", (str(lang), hi, no))
conn.commit()
c.close()
redirect('/settings')
@route('/system')
def system():

19
get_providers.py Normal file
View file

@ -0,0 +1,19 @@
import sqlite3
from subliminal import *
# Get providers list from subliminal
providers_list = sorted(provider_manager.names())
# Open database connection
db = sqlite3.connect('bazarr.db')
c = db.cursor()
# Insert providers in database table
for provider_name in providers_list:
c.execute('''INSERT OR IGNORE INTO table_settings_providers(name) VALUES(?)''', (provider_name, ))
# Commit changes to database table
db.commit()
# Close database connection
db.close()

View file

@ -1,6 +1,7 @@
import os
import enzyme
import babelfish
from subliminal import *
import pycountry
import sqlite3
import ast
@ -25,20 +26,19 @@ def store_subtitles(file):
conn_db = sqlite3.connect('bazarr.db')
c_db = conn_db.cursor()
enabled_languages = c_db.execute("SELECT code2 FROM table_settings_languages WHERE enabled = 1").fetchall()
for language in enabled_languages:
subtitle_path = os.path.splitext(file)[0] + "." + str(language[0]) + ".srt"
if os.path.isfile(subtitle_path):
languages.append([str(language[0]),str(path_replace_reverse(subtitle_path))])
subtitles = core.search_external_subtitles(file)
actual_subtitles = []
for subtitle, language in subtitles.iteritems():
actual_subtitles.append([str(language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
try:
c_db.execute("UPDATE table_episodes SET subtitles = ? WHERE path = ?", (str(languages), path_replace_reverse(file)))
c_db.execute("UPDATE table_episodes SET subtitles = ? WHERE path = ?", (str(actual_subtitles), path_replace_reverse(file)))
conn_db.commit()
except:
pass
c_db.close()
return languages
return actual_subtitles
def list_missing_subtitles(file):
conn_db = sqlite3.connect('bazarr.db')
@ -69,5 +69,4 @@ def full_scan_subtitles():
for path in all_path:
print store_subtitles(path_replace(path[0]))
#print list_missing_subtitles('/tv/Fear the Walking Dead/Season 3/Fear.The.Walking.Dead.S03E01.CONVERT.720p.WEB.h264-TBS[rarbg].mkv')
#full_scan_subtitles()

Binary file not shown.

BIN
utils.pyc

Binary file not shown.

View file

@ -71,23 +71,182 @@
<a class="item active" data-tab="general">General</a>
<a class="item" data-tab="sonarr">Sonarr</a>
<a class="item" data-tab="subliminal">Subliminal</a>
<a class="item" data-tab="providers">Providers</a>
<a class="item" data-tab="languages">Languages</a>
</div>
<div class="ui bottom attached tab segment active" data-tab="general">
General
<div class="ui container"><button class="ui blue right floated button">Save</button></div>
<br>
<div class="ui dividing header">Bazarr settings</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Listening IP address</label>
</div>
<div class="eleven wide column">
<div class="ui input">
<input type="text" value="{{settings_general[0]}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Listening port</label>
</div>
<div class="eleven wide column">
<div class="ui input">
<input type="text" value="{{settings_general[1]}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Base URL</label>
</div>
<div class="eleven wide column">
<div class="ui input">
<input type="text" value="{{settings_general[2]}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>SSL enabled</label>
</div>
<div class="eleven wide column">
<div id="sonarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings_general[3]}}>
<input type="checkbox">
<label></label>
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Path substitution</label>
</div>
<div class="five wide column">
<div class="ui fluid input">
<input type="text" value="{{settings_general[4]}}">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="sonarr">
Sonarr
<div class="ui container"><button class="ui blue right floated button">Save</button></div>
<br>
<div class="ui dividing header">sonarr settings</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Listening IP address</label>
</div>
<div class="eleven wide column">
<div class="ui input">
<input type="text" value="{{settings_sonarr[0]}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Listening port</label>
</div>
<div class="eleven wide column">
<div class="ui input">
<input type="text" value="{{settings_sonarr[1]}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Base URL</label>
</div>
<div class="eleven wide column">
<div class="ui input">
<input type="text" value="{{settings_sonarr[2]}}">
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>SSL enabled</label>
</div>
<div class="eleven wide column">
<div id="sonarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings_sonarr[3]}}>
<input type="checkbox">
<label></label>
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>API key</label>
</div>
<div class="five wide column">
<div class="ui fluid input">
<input type="text" value="{{settings_sonarr[4]}}">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="subliminal">
Subliminal
</div>
<div class="ui bottom attached tab segment" data-tab="providers">
Providers
</div>
<div class="ui bottom attached tab segment" data-tab="languages">
Languages
<div class="ui container"><button class="ui blue right floated button">Save</button></div>
<br>
<div class="ui dividing header">Providers</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Enabled providers</label>
</div>
<div class="eleven wide column">
<select name="settings_providers" id="settings_providers" multiple="" class="ui fluid selection dropdown">
<option value="">Providers</option>
%enabled_providers = []
%for provider in settings_providers:
<option value="{{provider[0]}}">{{provider[0]}}</option>
%if provider[1] == True:
% enabled_languages.append(str(provider[0]))
%end
%end
</select>
</div>
</div>
</div>
</div>
<div class="ui dividing header">Subtitles languages</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Enabled languages</label>
</div>
<div class="eleven wide column">
<select name="settings_languages" id="settings_languages" multiple="" class="ui fluid selection dropdown">
<option value="">Languages</option>
%enabled_languages = []
%for language in settings_languages:
<option value="{{language[1]}}">{{language[2]}}</option>
%if language[3] == True:
% enabled_languages.append(str(language[1]))
%end
%end
</select>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
@ -102,4 +261,18 @@
$('a.menu').click(function(){
$('#loader').addClass('active');
})
if ($('#sonarr_ssl_div').data("ssl") == "True") {
$("#sonarr_ssl_div").checkbox('check');
} else {
$("#sonarr_ssl_div").checkbox('uncheck');
}
$('#settings_providers').dropdown('clear');
$('#settings_providers').dropdown('set selected',{{!enabled_providers}});
$('#settings_languages').dropdown('clear');
$('#settings_languages').dropdown('set selected',{{!enabled_languages}});
$('#settings_providers').dropdown();
$('#settings_languages').dropdown();
</script>