Move settings from Database to Config file (#126)
* Move settings from Database to Config file
* Delete unused config and forgot upload init
* Fix
* Update get_subtitles and fix provider auth
* Revert "Update get_subtitles and fix provider auth"
This reverts commit c904bf6b5a
.
* Update get_sebtitles
* more fixes
* Update requirements
pull/130/head
parent
9b11324c85
commit
db2378943f
@ -1,21 +0,0 @@
|
||||
from get_argv import config_dir
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
def get_auth_settings():
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
c.execute('''SELECT * FROM table_settings_auth''')
|
||||
config_auth = c.fetchone()
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
auth_enabled = config_auth[0]
|
||||
auth_username = config_auth[1]
|
||||
auth_password = config_auth[2]
|
||||
|
||||
return [auth_enabled, auth_username, auth_password]
|
@ -1,140 +0,0 @@
|
||||
from get_argv import config_dir
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
import ast
|
||||
import re
|
||||
|
||||
def get_general_settings():
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
# Get general settings from database table
|
||||
c.execute("SELECT * FROM table_settings_general")
|
||||
general_settings = c.fetchone()
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
ip = general_settings[0]
|
||||
port = general_settings[1]
|
||||
base_url = general_settings[2]
|
||||
if base_url == None:
|
||||
base_url = "/"
|
||||
if base_url.startswith("/") == False:
|
||||
base_url = "/" + base_url
|
||||
if base_url.endswith("/") == False:
|
||||
base_url = base_url + "/"
|
||||
|
||||
if general_settings[3] is None:
|
||||
path_mappings = []
|
||||
else:
|
||||
path_mappings = ast.literal_eval(general_settings[3])
|
||||
log_level = general_settings[4]
|
||||
branch = general_settings[5]
|
||||
automatic = general_settings[6]
|
||||
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]
|
||||
use_sonarr = general_settings[14]
|
||||
use_radarr = general_settings[15]
|
||||
if general_settings[16] is None:
|
||||
path_mappings_movie = []
|
||||
else:
|
||||
path_mappings_movie = ast.literal_eval(general_settings[16])
|
||||
serie_default_enabled = general_settings[17]
|
||||
serie_default_language = general_settings[18]
|
||||
serie_default_hi = general_settings[19]
|
||||
movie_default_enabled = general_settings[20]
|
||||
movie_default_language = general_settings[21]
|
||||
movie_default_hi = general_settings[22]
|
||||
page_size = general_settings[23]
|
||||
minimum_score_movie = general_settings[24]
|
||||
use_embedded_subs = general_settings[25]
|
||||
only_monitored = general_settings[26]
|
||||
|
||||
return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie, serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,movie_default_language, movie_default_hi, page_size, minimum_score_movie, use_embedded_subs, only_monitored]
|
||||
|
||||
def path_replace(path):
|
||||
for path_mapping in path_mappings:
|
||||
if path_mapping[0] in path:
|
||||
path = path.replace(path_mapping[0], path_mapping[1])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def path_replace_reverse(path):
|
||||
for path_mapping in path_mappings:
|
||||
if path_mapping[1] in path:
|
||||
path = path.replace(path_mapping[1], path_mapping[0])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def path_replace_movie(path):
|
||||
for path_mapping in path_mappings_movie:
|
||||
if path_mapping[0] in path:
|
||||
path = path.replace(path_mapping[0], path_mapping[1])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def path_replace_reverse_movie(path):
|
||||
for path_mapping in path_mappings_movie:
|
||||
if path_mapping[1] in path:
|
||||
path = path.replace(path_mapping[1], path_mapping[0])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3):
|
||||
pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode))
|
||||
pp_command = pp_command.replace('{{episode}}', episode)
|
||||
pp_command = pp_command.replace('{{episode_name}}', os.path.splitext(os.path.basename(episode))[0])
|
||||
pp_command = pp_command.replace('{{subtitles}}', subtitles)
|
||||
pp_command = pp_command.replace('{{subtitles_language}}', language)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code2}}', language_code2)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code3}}', language_code3)
|
||||
return pp_command
|
||||
|
||||
result = get_general_settings()
|
||||
ip = result[0]
|
||||
port = result[1]
|
||||
base_url = result[2]
|
||||
path_mappings = result[3]
|
||||
log_level = result[4]
|
||||
branch = result[5]
|
||||
automatic = result[6]
|
||||
single_language = result[7]
|
||||
minimum_score = result[8]
|
||||
use_scenename = result[9]
|
||||
use_processing = result[10]
|
||||
postprocessing_cmd = result[11]
|
||||
use_sonarr = result[12]
|
||||
use_radarr = result[13]
|
||||
path_mappings_movie = result[14]
|
||||
serie_default_enabled = result[15]
|
||||
serie_default_language = result[16]
|
||||
serie_default_hi = result[17]
|
||||
movie_default_enabled = result[18]
|
||||
movie_default_language = result[19]
|
||||
movie_default_hi = result[20]
|
||||
page_size = result[21]
|
||||
minimum_score_movie = result[22]
|
||||
use_embedded_subs = result[23]
|
||||
only_monitored = result[24]
|
@ -1,42 +0,0 @@
|
||||
from get_argv import config_dir
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
import ast
|
||||
|
||||
def get_radarr_settings():
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
# Get Radarr API URL from database config table
|
||||
c.execute('''SELECT * FROM table_settings_radarr''')
|
||||
config_radarr = c.fetchone()
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
# Build radarr URL
|
||||
ip_radarr = config_radarr[0]
|
||||
port_radarr = str(config_radarr[1])
|
||||
baseurl_radarr = config_radarr[2]
|
||||
ssl_radarr = config_radarr[3]
|
||||
apikey_radarr = config_radarr[4]
|
||||
full_update = config_radarr[5]
|
||||
|
||||
if ssl_radarr == 1:
|
||||
protocol_radarr = "https"
|
||||
else:
|
||||
protocol_radarr = "http"
|
||||
|
||||
if baseurl_radarr == None:
|
||||
baseurl_radarr = "/"
|
||||
if baseurl_radarr.startswith("/") == False:
|
||||
baseurl_radarr = "/" + baseurl_radarr
|
||||
if baseurl_radarr.endswith("/"):
|
||||
baseurl_radarr = baseurl_radarr[:-1]
|
||||
|
||||
url_radarr = protocol_radarr + "://" + ip_radarr + ":" + port_radarr + baseurl_radarr
|
||||
url_radarr_short = protocol_radarr + "://" + ip_radarr + ":" + port_radarr
|
||||
|
||||
return [url_radarr, url_radarr_short, apikey_radarr, full_update]
|
@ -0,0 +1,416 @@
|
||||
from get_argv import config_dir
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
import ast
|
||||
from configparser import ConfigParser
|
||||
|
||||
config_file = os.path.normpath(os.path.join(config_dir, 'config/config.ini'))
|
||||
|
||||
def get_general_settings():
|
||||
cfg = ConfigParser()
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
cfg.read_file(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if cfg.has_section('general'):
|
||||
if cfg.has_option('general', 'ip'):
|
||||
ip = cfg.get('general', 'ip')
|
||||
else:
|
||||
ip = '0.0.0.0'
|
||||
|
||||
if cfg.has_option('general', 'port'):
|
||||
port = cfg.get('general', 'port')
|
||||
else:
|
||||
port = '6767'
|
||||
|
||||
if cfg.has_option('general', 'base_url'):
|
||||
base_url = cfg.get('general', 'base_url')
|
||||
else:
|
||||
base_url = '/'
|
||||
|
||||
if cfg.has_option('general', 'path_mappings'):
|
||||
path_mappings = cfg.get('general', 'path_mappings')
|
||||
else:
|
||||
path_mappings = []
|
||||
|
||||
if cfg.has_option('general', 'log_level'):
|
||||
log_level = cfg.get('general', 'log_level')
|
||||
else:
|
||||
log_level = 'INFO'
|
||||
|
||||
if cfg.has_option('general', 'branch'):
|
||||
branch = cfg.get('general', 'branch')
|
||||
else:
|
||||
branch = 'master'
|
||||
|
||||
if cfg.has_option('general', 'auto_update'):
|
||||
auto_update = cfg.getboolean('general', 'auto_update')
|
||||
else:
|
||||
auto_update = True
|
||||
|
||||
if cfg.has_option('general', 'single_language'):
|
||||
single_language = cfg.getboolean('general', 'single_language')
|
||||
else:
|
||||
single_language = False
|
||||
|
||||
if cfg.has_option('general', 'minimum_score'):
|
||||
minimum_score = cfg.get('general', 'minimum_score')
|
||||
else:
|
||||
minimum_score = '100'
|
||||
|
||||
if cfg.has_option('general', 'use_scenename'):
|
||||
use_scenename = cfg.getboolean('general', 'use_scenename')
|
||||
else:
|
||||
use_scenename = False
|
||||
|
||||
if cfg.has_option('general', 'use_postprocessing'):
|
||||
use_postprocessing = cfg.getboolean('general', 'use_postprocessing')
|
||||
else:
|
||||
use_postprocessing = False
|
||||
|
||||
if cfg.has_option('general', 'postprocessing_cmd'):
|
||||
postprocessing_cmd = cfg.get('general', 'postprocessing_cmd')
|
||||
else:
|
||||
postprocessing_cmd = ''
|
||||
|
||||
if cfg.has_option('general', 'use_sonarr'):
|
||||
use_sonarr = cfg.getboolean('general', 'use_sonarr')
|
||||
else:
|
||||
use_sonarr = False
|
||||
|
||||
if cfg.has_option('general', 'use_radarr'):
|
||||
use_radarr = cfg.getboolean('general', 'use_radarr')
|
||||
else:
|
||||
use_radarr = False
|
||||
|
||||
if cfg.has_option('general', 'path_mappings_movie'):
|
||||
path_mappings_movie = cfg.get('general', 'path_mappings_movie')
|
||||
else:
|
||||
path_mappings_movie = []
|
||||
|
||||
if cfg.has_option('general', 'serie_default_enabled'):
|
||||
serie_default_enabled = cfg.getboolean('general', 'serie_default_enabled')
|
||||
else:
|
||||
serie_default_enabled = False
|
||||
|
||||
if cfg.has_option('general', 'serie_default_language'):
|
||||
serie_default_language = cfg.get('general', 'serie_default_language')
|
||||
else:
|
||||
serie_default_language = []
|
||||
|
||||
if cfg.has_option('general', 'serie_default_hi'):
|
||||
serie_default_hi = cfg.getboolean('general', 'serie_default_hi')
|
||||
else:
|
||||
serie_default_hi = False
|
||||
|
||||
if cfg.has_option('general', 'movie_default_enabled'):
|
||||
movie_default_enabled = cfg.getboolean('general', 'movie_default_enabled')
|
||||
else:
|
||||
movie_default_enabled = False
|
||||
|
||||
if cfg.has_option('general', 'movie_default_language'):
|
||||
movie_default_language = cfg.get('general', 'movie_default_language')
|
||||
else:
|
||||
movie_default_language = []
|
||||
|
||||
if cfg.has_option('general', 'movie_default_hi'):
|
||||
movie_default_hi = cfg.getboolean('general', 'movie_default_hi')
|
||||
else:
|
||||
movie_default_hi = False
|
||||
|
||||
if cfg.has_option('general', 'page_size'):
|
||||
page_size = cfg.get('general', 'page_size')
|
||||
else:
|
||||
page_size = '25'
|
||||
|
||||
if cfg.has_option('general', 'minimum_score_movie'):
|
||||
minimum_score_movie = cfg.get('general', 'minimum_score_movie')
|
||||
else:
|
||||
minimum_score_movie = '100'
|
||||
|
||||
if cfg.has_option('general', 'use_embedded_subs'):
|
||||
use_embedded_subs = cfg.getboolean('general', 'use_embedded_subs')
|
||||
else:
|
||||
use_embedded_subs = False
|
||||
|
||||
if cfg.has_option('general', 'only_monitored'):
|
||||
only_monitored = cfg.getboolean('general', 'only_monitored')
|
||||
else:
|
||||
only_monitored = False
|
||||
|
||||
else:
|
||||
ip = '0.0.0.0'
|
||||
port = '6768'
|
||||
base_url = '/'
|
||||
path_mappings = []
|
||||
log_level = 'INFO'
|
||||
branch = 'master'
|
||||
auto_update = True
|
||||
single_language = False
|
||||
minimum_score = '100'
|
||||
use_scenename = False
|
||||
use_postprocessing = False
|
||||
postprocessing_cmd = False
|
||||
use_sonarr = False
|
||||
use_radarr = False
|
||||
path_mappings_movie = []
|
||||
serie_default_enabled = False
|
||||
serie_default_language = []
|
||||
serie_default_hi = False
|
||||
movie_default_enabled = False
|
||||
movie_default_language = []
|
||||
movie_default_hi = False
|
||||
page_size = '25'
|
||||
minimum_score_movie = '100'
|
||||
use_embedded_subs = False
|
||||
only_monitored = False
|
||||
|
||||
return [ip, port, base_url, path_mappings, log_level, branch, auto_update, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie, serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,movie_default_language, movie_default_hi, page_size, minimum_score_movie, use_embedded_subs, only_monitored]
|
||||
|
||||
|
||||
def get_auth_settings():
|
||||
cfg = ConfigParser()
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
cfg.read_file(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if cfg.has_section('auth'):
|
||||
if cfg.has_option('auth', 'enabled'):
|
||||
enabled = cfg.getboolean('auth', 'enabled')
|
||||
else:
|
||||
enabled = False
|
||||
|
||||
if cfg.has_option('auth', 'username'):
|
||||
username = cfg.get('auth', 'username')
|
||||
else:
|
||||
username = ''
|
||||
|
||||
if cfg.has_option('auth', 'password'):
|
||||
password = cfg.get('auth', 'password')
|
||||
else:
|
||||
password = ''
|
||||
else:
|
||||
enabled = False
|
||||
username = ''
|
||||
password = ''
|
||||
|
||||
return [enabled, username, password]
|
||||
|
||||
|
||||
def get_sonarr_settings():
|
||||
cfg = ConfigParser()
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
cfg.read_file(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if cfg.has_section('sonarr'):
|
||||
if cfg.has_option('sonarr', 'ip'):
|
||||
ip = cfg.get('sonarr', 'ip')
|
||||
else:
|
||||
ip = '127.0.0.1'
|
||||
|
||||
if cfg.has_option('sonarr', 'port'):
|
||||
port = cfg.get('sonarr', 'port')
|
||||
else:
|
||||
port = '8989'
|
||||
|
||||
if cfg.has_option('sonarr', 'base_url'):
|
||||
base_url = cfg.get('sonarr', 'base_url')
|
||||
else:
|
||||
base_url = '/'
|
||||
|
||||
if cfg.has_option('sonarr', 'ssl'):
|
||||
ssl = cfg.get('sonarr', 'ssl')
|
||||
else:
|
||||
ssl = False
|
||||
|
||||
if cfg.has_option('sonarr', 'apikey'):
|
||||
apikey = cfg.get('sonarr', 'apikey')
|
||||
else:
|
||||
apikey = ''
|
||||
|
||||
if cfg.has_option('sonarr', 'full_update'):
|
||||
full_update = cfg.get('sonarr', 'full_update')
|
||||
else:
|
||||
full_update = 'Dayly'
|
||||
else:
|
||||
ip = '127.0.0.1'
|
||||
port = '8989'
|
||||
base_url = '/'
|
||||
ssl = False
|
||||
apikey = ''
|
||||
full_update = 'Daily'
|
||||
|
||||
if ssl == 1:
|
||||
protocol_sonarr = "https"
|
||||
else:
|
||||
protocol_sonarr = "http"
|
||||
|
||||
if base_url == None:
|
||||
base_url = "/"
|
||||
if base_url.startswith("/") == False:
|
||||
base_url = "/" + base_url
|
||||
if base_url.endswith("/"):
|
||||
base_url = base_url[:-1]
|
||||
|
||||
url_sonarr = protocol_sonarr + "://" + ip + ":" + port + base_url
|
||||
url_sonarr_short = protocol_sonarr + "://" + ip + ":" + port
|
||||
|
||||
|
||||
|
||||
return [ip, port, base_url, ssl, apikey, full_update, url_sonarr, url_sonarr_short]
|
||||
|
||||
|
||||
def get_radarr_settings():
|
||||
cfg = ConfigParser()
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
cfg.read_file(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if cfg.has_section('radarr'):
|
||||
if cfg.has_option('radarr', 'ip'):
|
||||
ip = cfg.get('radarr', 'ip')
|
||||
else:
|
||||
ip = '127.0.0.1'
|
||||
|
||||
if cfg.has_option('radarr', 'port'):
|
||||
port = cfg.get('radarr', 'port')
|
||||
else:
|
||||
port = '7878'
|
||||
|
||||
if cfg.has_option('radarr', 'base_url'):
|
||||
base_url = cfg.get('radarr', 'base_url')
|
||||
else:
|
||||
base_url = '/'
|
||||
|
||||
if cfg.has_option('radarr', 'ssl'):
|
||||
ssl = cfg.get('radarr', 'ssl')
|
||||
else:
|
||||
ssl = False
|
||||
|
||||
if cfg.has_option('radarr', 'apikey'):
|
||||
apikey = cfg.get('radarr', 'apikey')
|
||||
else:
|
||||
apikey = ''
|
||||
|
||||
if cfg.has_option('radarr', 'full_update'):
|
||||
full_update = cfg.get('radarr', 'full_update')
|
||||
else:
|
||||
full_update = 'Dayly'
|
||||
else:
|
||||
ip = '127.0.0.1'
|
||||
port = '8989'
|
||||
base_url = '/'
|
||||
ssl = False
|
||||
apikey = ''
|
||||
full_update = 'Daily'
|
||||
|
||||
if ssl == 1:
|
||||
protocol_radarr = "https"
|
||||
else:
|
||||
protocol_radarr = "http"
|
||||
|
||||
if base_url is None:
|
||||
base_url = "/"
|
||||
if base_url.startswith("/") is False:
|
||||
base_url = "/" + base_url
|
||||
if base_url.endswith("/"):
|
||||
base_url = base_url[:-1]
|
||||
|
||||
url_radarr = protocol_radarr + "://" + ip + ":" + port + base_url
|
||||
url_radarr_short = protocol_radarr + "://" + ip + ":" + port
|
||||
|
||||
return [ip, port, base_url, ssl, apikey, full_update, url_radarr , url_radarr_short]
|
||||
|
||||
|
||||
|
||||
def path_replace(path):
|
||||
for path_mapping in path_mappings:
|
||||
if path_mapping[0] in path:
|
||||
path = path.replace(path_mapping[0], path_mapping[1])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def path_replace_reverse(path):
|
||||
for path_mapping in path_mappings:
|
||||
if path_mapping[1] in path:
|
||||
path = path.replace(path_mapping[1], path_mapping[0])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def path_replace_movie(path):
|
||||
for path_mapping in path_mappings_movie:
|
||||
if path_mapping[0] in path:
|
||||
path = path.replace(path_mapping[0], path_mapping[1])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def path_replace_reverse_movie(path):
|
||||
for path_mapping in path_mappings_movie:
|
||||
if path_mapping[1] in path:
|
||||
path = path.replace(path_mapping[1], path_mapping[0])
|
||||
if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
|
||||
path = path.replace('/', '\\')
|
||||
elif path.startswith('/'):
|
||||
path = path.replace('\\', '/')
|
||||
break
|
||||
return path
|
||||
|
||||
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3):
|
||||
pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode))
|
||||
pp_command = pp_command.replace('{{episode}}', episode)
|
||||
pp_command = pp_command.replace('{{episode_name}}', os.path.splitext(os.path.basename(episode))[0])
|
||||
pp_command = pp_command.replace('{{subtitles}}', subtitles)
|
||||
pp_command = pp_command.replace('{{subtitles_language}}', language)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code2}}', language_code2)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code3}}', language_code3)
|
||||
return pp_command
|
||||
|
||||
result = get_general_settings()
|
||||
ip = result[0]
|
||||
port = result[1]
|
||||
base_url = result[2]
|
||||
path_mappings = ast.literal_eval(result[3])
|
||||
log_level = result[4]
|
||||
branch = result[5]
|
||||
automatic = result[6]
|
||||
single_language = result[7]
|
||||
minimum_score = result[8]
|
||||
use_scenename = result[9]
|
||||
use_processing = result[10]
|
||||
postprocessing_cmd = result[11]
|
||||
use_sonarr = result[12]
|
||||
use_radarr = result[13]
|
||||
path_mappings_movie = ast.literal_eval(result[14])
|
||||
serie_default_enabled = result[15]
|
||||
serie_default_language = result[16]
|
||||
serie_default_hi = result[17]
|
||||
movie_default_enabled = result[18]
|
||||
movie_default_language = result[19]
|
||||
movie_default_hi = result[20]
|
||||
page_size = result[21]
|
||||
minimum_score_movie = result[22]
|
||||
use_embedded_subs = result[23]
|
||||
only_monitored = result[24]
|
@ -1,42 +0,0 @@
|
||||
from get_argv import config_dir
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
import ast
|
||||
|
||||
def get_sonarr_settings():
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
# Get Sonarr API URL from database config table
|
||||
c.execute('''SELECT * FROM table_settings_sonarr''')
|
||||
config_sonarr = c.fetchone()
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
# Build Sonarr URL
|
||||
ip_sonarr = config_sonarr[0]
|
||||
port_sonarr = str(config_sonarr[1])
|
||||
baseurl_sonarr = config_sonarr[2]
|
||||
ssl_sonarr = config_sonarr[3]
|
||||
apikey_sonarr = config_sonarr[4]
|
||||
full_update = config_sonarr[5]
|
||||
|
||||
if ssl_sonarr == 1:
|
||||
protocol_sonarr = "https"
|
||||
else:
|
||||
protocol_sonarr = "http"
|
||||
|
||||
if baseurl_sonarr == None:
|
||||
baseurl_sonarr = "/"
|
||||
if baseurl_sonarr.startswith("/") == False:
|
||||
baseurl_sonarr = "/" + baseurl_sonarr
|
||||
if baseurl_sonarr.endswith("/"):
|
||||
baseurl_sonarr = baseurl_sonarr[:-1]
|
||||
|
||||
url_sonarr = protocol_sonarr + "://" + ip_sonarr + ":" + port_sonarr + baseurl_sonarr
|
||||
url_sonarr_short = protocol_sonarr + "://" + ip_sonarr + ":" + port_sonarr
|
||||
|
||||
return [url_sonarr, url_sonarr_short, apikey_sonarr, full_update]
|
@ -0,0 +1,220 @@
|
||||
import os
|
||||
import sqlite3
|
||||
import logging
|
||||
|
||||
from configparser import ConfigParser
|
||||
from get_argv import config_dir
|
||||
|
||||
# Check if config_dir exist
|
||||
if os.path.exists(config_dir) is False:
|
||||
# Create config_dir directory tree
|
||||
try:
|
||||
os.mkdir(os.path.join(config_dir))
|
||||
logging.debug("Created data directory")
|
||||
except OSError:
|
||||
logging.exception("The configuration directory doesn't exist and Bazarr cannot create it (permission issue?).")
|
||||
exit(2)
|
||||
|
||||
if os.path.exists(os.path.join(config_dir, 'config')) is False:
|
||||
os.mkdir(os.path.join(config_dir, 'config'))
|
||||
logging.debug("Created config folder")
|
||||
if os.path.exists(os.path.join(config_dir, 'db')) is False:
|
||||
os.mkdir(os.path.join(config_dir, 'db'))
|
||||
logging.debug("Created db folder")
|
||||
if os.path.exists(os.path.join(config_dir, 'log')) is False:
|
||||
os.mkdir(os.path.join(config_dir, 'log'))
|
||||
logging.debug("Created log folder")
|
||||
|
||||
config_file = os.path.normpath(os.path.join(config_dir, 'config/config.ini'))
|
||||
|
||||
# if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) is True and os.path.exists(config_file) is False:
|
||||
try:
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
# Get general settings from database table
|
||||
c.execute("SELECT * FROM table_settings_general")
|
||||
general_settings = c.fetchone()
|
||||
c.execute('''SELECT * FROM table_settings_auth''')
|
||||
auth_settings = c.fetchone()
|
||||
c.execute('''SELECT * FROM table_settings_sonarr''')
|
||||
sonarr_settings = c.fetchone()
|
||||
c.execute('''SELECT * FROM table_settings_radarr''')
|
||||
radarr_settings = c.fetchone()
|
||||
|
||||
c.execute("DROP TABLE table_settings_general")
|
||||
c.execute("DROP TABLE table_settings_auth")
|
||||
c.execute("DROP TABLE table_settings_sonarr")
|
||||
c.execute("DROP TABLE table_settings_radarr")
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
cfg = ConfigParser()
|
||||
|
||||
section = 'general'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'ip', str(general_settings[0]))
|
||||
cfg.set(section, 'port', str(general_settings[1]))
|
||||
cfg.set(section, 'base_url', general_settings[2])
|
||||
cfg.set(section, 'path_mappings', general_settings[3])
|
||||
cfg.set(section, 'log_level', general_settings[4])
|
||||
cfg.set(section, 'branch', general_settings[5])
|
||||
cfg.set(section, 'auto_update', general_settings[6])
|
||||
cfg.set(section, 'single_language', general_settings[9])
|
||||
cfg.set(section, 'minimum_score', general_settings[10])
|
||||
cfg.set(section, 'use_scenename', general_settings[11])
|
||||
cfg.set(section, 'use_postprocessing', general_settings[12])
|
||||
cfg.set(section, 'postprocessing_cmd', general_settings[13])
|
||||
cfg.set(section, 'use_sonarr', general_settings[14])
|
||||
cfg.set(section, 'use_radarr', general_settings[15])
|
||||
cfg.set(section, 'path_mappings_movie', general_settings[16])
|
||||
cfg.set(section, 'serie_default_enabled', general_settings[17])
|
||||
cfg.set(section, 'serie_default_language', general_settings[18])
|
||||
cfg.set(section, 'serie_default_hi', general_settings[19])
|
||||
cfg.set(section, 'movie_default_enabled', general_settings[20])
|
||||
cfg.set(section, 'movie_default_language', general_settings[21])
|
||||
cfg.set(section, 'movie_default_hi', general_settings[22])
|
||||
cfg.set(section, 'page_size', general_settings[23])
|
||||
cfg.set(section, 'minimum_score_movie', general_settings[24])
|
||||
cfg.set(section, 'use_embedded_subs', general_settings[25])
|
||||
cfg.set(section, 'only_monitored', general_settings[26])
|
||||
|
||||
section = 'auth'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'enabled', auth_settings[0])
|
||||
cfg.set(section, 'username', auth_settings[1])
|
||||
cfg.set(section, 'password', auth_settings[2])
|
||||
|
||||
section = 'sonarr'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'ip', sonarr_settings[0])
|
||||
cfg.set(section, 'port', str(sonarr_settings[1]))
|
||||
cfg.set(section, 'base_url', sonarr_settings[2])
|
||||
cfg.set(section, 'ssl', sonarr_settings[3])
|
||||
cfg.set(section, 'apikey', sonarr_settings[4])
|
||||
cfg.set(section, 'full_update', sonarr_settings[5])
|
||||
|
||||
section = 'radarr'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'ip', radarr_settings[0])
|
||||
cfg.set(section, 'port', str(radarr_settings[1]))
|
||||
cfg.set(section, 'base_url', radarr_settings[2])
|
||||
cfg.set(section, 'ssl', radarr_settings[3])
|
||||
cfg.set(section, 'apikey', radarr_settings[4])
|
||||
cfg.set(section, 'full_update', radarr_settings[5])
|
||||
|
||||
with open(config_file, 'w+') as configfile:
|
||||
cfg.write(configfile)
|
||||
|
||||
|
||||
logging.info('Config file succesfully migrated from database')
|
||||
|
||||
except sqlite3.OperationalError:
|
||||
# if not os.path.exists(config_file):
|
||||
if os.path.exists(config_file) is False:
|
||||
cfg = ConfigParser()
|
||||
|
||||
section = 'general'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'ip', "0.0.0.0")
|
||||
cfg.set(section, 'port', "6767")
|
||||
cfg.set(section, 'base_url', "/")
|
||||
cfg.set(section, 'path_mappings', '[]')
|
||||
cfg.set(section, 'log_level', "INFO")
|
||||
cfg.set(section, 'branch', "master")
|
||||
cfg.set(section, 'auto_update', "True")
|
||||
cfg.set(section, 'single_language', "False")
|
||||
cfg.set(section, 'minimum_score', "100")
|
||||
cfg.set(section, 'use_scenename', "False")
|
||||
cfg.set(section, 'use_postprocessing', "False")
|
||||
cfg.set(section, 'postprocessing_cmd', "False")
|
||||
cfg.set(section, 'use_sonarr', "False")
|
||||
cfg.set(section, 'use_radarr', "False")
|
||||
cfg.set(section, 'path_mappings_movie', '[]')
|
||||
cfg.set(section, 'serie_default_enabled', "False")
|
||||
cfg.set(section, 'serie_default_language', '')
|
||||
cfg.set(section, 'serie_default_hi', "False")
|
||||
cfg.set(section, 'movie_default_enabled', "False")
|
||||
cfg.set(section, 'movie_default_language', '')
|
||||
cfg.set(section, 'movie_default_hi', "False")
|
||||
cfg.set(section, 'page_size', "25")
|
||||
cfg.set(section, 'minimum_score_movie', "100")
|
||||
cfg.set(section, 'use_embedded_subs', "False")
|
||||
cfg.set(section, 'only_monitored', "False")
|
||||
|
||||
section = 'auth'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'enabled', "False")
|
||||
cfg.set(section, 'username', "")
|
||||
cfg.set(section, 'password', "")
|
||||
|
||||
section = 'sonarr'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'ip', "127.0.0.1")
|
||||
cfg.set(section, 'port', "8989")
|
||||
cfg.set(section, 'base_url', "/")
|
||||
cfg.set(section, 'ssl', "False")
|
||||
cfg.set(section, 'apikey', "")
|
||||
cfg.set(section, 'full_update', "Daily")
|
||||
|
||||
section = 'radarr'
|
||||
|
||||
if not cfg.has_section(section):
|
||||
cfg.add_section(section)
|
||||
|
||||
cfg.set(section, 'ip', "127.0.0.1")
|
||||
cfg.set(section, 'port', "7878")
|
||||
cfg.set(section, 'base_url', "/")
|
||||
cfg.set(section, 'ssl', "False")
|
||||
cfg.set(section, 'apikey', "")
|
||||
cfg.set(section, 'full_update', "Daily")
|
||||
|
||||
|
||||
with open(config_file, 'w+') as configfile:
|
||||
cfg.write(configfile)
|
||||
|
||||
logging.info('Config file created successfully')
|
||||
try:
|
||||
# Get SQL script from file
|
||||
fd = open(os.path.join(os.path.dirname(__file__), 'create_db.sql'), 'r')
|
||||
script = fd.read()
|
||||
|
||||
# Close SQL script file
|
||||
fd.close()
|
||||
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
# Execute script and commit change to database
|
||||
c.executescript(script)
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
logging.info('Database created successfully')
|
||||
except:
|
||||
pass
|
@ -1,50 +0,0 @@
|
||||
from get_argv import config_dir
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import logging
|
||||
|
||||
# Check if config_dir exist
|
||||
if os.path.exists(config_dir) == True:
|
||||
pass
|
||||
else:
|
||||
# Create config_dir directory tree
|
||||
try:
|
||||
os.mkdir(os.path.join(config_dir))
|
||||
except OSError:
|
||||
logging.exception("The configuration directory doesn't exist and Bazarr cannot create it (permission issue?).")
|
||||
exit(2)
|
||||
|
||||
# Check if database exist
|
||||
if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
|
||||
pass
|
||||
else:
|
||||
# Create data directory tree
|
||||
try:
|
||||
os.mkdir(os.path.join(config_dir, 'db'))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
try:
|
||||
os.mkdir(os.path.join(config_dir, 'log'))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# Get SQL script from file
|
||||
fd = open(os.path.join(os.path.dirname(__file__), 'create_db.sql'), 'r')
|
||||
script = fd.read()
|
||||
|
||||
# Close SQL script file
|
||||
fd.close()
|
||||
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
# Execute script and commit change to database
|
||||
c.executescript(script)
|
||||
|
||||
# Close database connection
|
||||
db.close()
|
||||
|
||||
logging.info('Database created successfully')
|
Loading…
Reference in new issue