More work for new Config code

pull/292/head
Halali 6 years ago
parent ead1f31eb1
commit 99118f87fd

@ -1,7 +1,4 @@
from get_argv import config_dir
from get_settings import get_general_settings
# coding=utf-8
import os
import logging
import sqlite3
@ -10,6 +7,10 @@ import requests
import git
from get_argv import config_dir
from config import settings
current_working_directory = os.path.dirname(os.path.dirname(__file__))
def gitconfig():
@ -32,7 +33,7 @@ def gitconfig():
def check_and_apply_update():
gitconfig()
check_releases()
branch = get_general_settings()[5]
branch = settings.general.branch
g = git.cmd.Git(current_working_directory)
g.fetch('origin')
result = g.diff('--shortstat', 'origin/' + branch)

@ -44,6 +44,7 @@ def read(config_file):
settings = read(os.path.join(os.path.join(config_dir, 'config', 'config.ini')))
base_url = settings.general.base_url
# sonarr url
if settings.sonarr.ssl:

@ -1,30 +1,32 @@
from get_argv import config_dir
# coding=utf-8
import os
import sqlite3
import requests
import logging
from get_settings import path_replace
from get_argv import config_dir
from config import settings, url_sonarr
from helper import path_replace
from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles, movies_full_scan_subtitles
def update_all_episodes():
series_full_scan_subtitles()
logging.info('BAZARR All existing episode subtitles indexed from disk.')
list_missing_subtitles()
logging.info('BAZARR All missing episode subtitles updated in database.')
def update_all_movies():
movies_full_scan_subtitles()
logging.info('BAZARR All existing movie subtitles indexed from disk.')
list_missing_subtitles()
logging.info('BAZARR All missing movie subtitles updated in database.')
def sync_episodes():
logging.debug('BAZARR Starting episode sync from Sonarr.')
from get_settings import get_sonarr_settings
url_sonarr = get_sonarr_settings()[6]
apikey_sonarr = get_sonarr_settings()[4]
apikey_sonarr = settings.sonarr.apikey
# Open database connection
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)

@ -1,8 +1,10 @@
from get_argv import config_dir
# coding=utf-8
import os
import sqlite3
import pycountry
import os
from get_argv import config_dir
def load_language_in_db():
# Get languages list in langs tuple
@ -11,7 +13,7 @@ def load_language_in_db():
if hasattr(lang, 'alpha_2')]
# Open database connection
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
# Insert languages in database table
@ -31,6 +33,7 @@ def load_language_in_db():
# Close database connection
db.close()
def language_from_alpha2(lang):
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
c = db.cursor()
@ -41,6 +44,7 @@ def language_from_alpha2(lang):
db.close()
return result
def language_from_alpha3(lang):
if lang == 'fre':
lang = 'fra'
@ -53,6 +57,7 @@ def language_from_alpha3(lang):
db.close()
return result
def alpha2_from_alpha3(lang):
if lang == 'fre':
lang = 'fra'
@ -65,6 +70,7 @@ def alpha2_from_alpha3(lang):
db.close()
return result
def alpha2_from_language(lang):
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
c = db.cursor()
@ -75,6 +81,7 @@ def alpha2_from_language(lang):
db.close()
return result
def alpha3_from_alpha2(lang):
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
c = db.cursor()
@ -85,6 +92,7 @@ def alpha3_from_alpha2(lang):
db.close()
return result
def alpha3_from_language(lang):
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
c = db.cursor()
@ -95,5 +103,6 @@ def alpha3_from_language(lang):
db.close()
return result
if __name__ == '__main__':
load_language_in_db()

@ -1,23 +1,23 @@
from get_argv import config_dir
# coding=utf-8
import os
import sqlite3
import requests
import logging
from get_settings import get_general_settings, path_replace_movie
from get_argv import config_dir
from config import settings, url_radarr
from helper import path_replace_movie
from list_subtitles import store_subtitles_movie, list_missing_subtitles_movies
def update_movies():
logging.debug('BAZARR Starting movie sync from Radarr.')
from get_settings import get_radarr_settings
url_radarr = get_radarr_settings()[6]
apikey_radarr = get_radarr_settings()[4]
movie_default_enabled = get_general_settings()[18]
movie_default_language = get_general_settings()[19]
movie_default_hi = get_general_settings()[20]
if apikey_radarr == None:
apikey_radarr = settings.radarr.apikey
movie_default_enabled = settings.general.movie_default_enabled
movie_default_language = settings.general.movie_default_language
movie_default_hi = settings.general.movie_default_hi
if apikey_radarr is None:
pass
else:
get_profile_list()
@ -124,11 +124,9 @@ def update_movies():
list_missing_subtitles_movies()
logging.debug('BAZARR All movie missing subtitles updated in database.')
def get_profile_list():
from get_settings import get_radarr_settings
url_radarr = get_radarr_settings()[6]
# url_radarr_short = get_radarr_settings()[7]
apikey_radarr = get_radarr_settings()[4]
apikey_radarr = settings.radarr.apikey
# Get profiles data from radarr
global profiles_list
@ -148,10 +146,12 @@ def get_profile_list():
for profile in profiles_json.json():
profiles_list.append([profile['id'], profile['language'].capitalize()])
def profile_id_to_language(id):
for profile in profiles_list:
if id == profile[0]:
return profile[1]
if __name__ == '__main__':
update_movies()

@ -1,16 +1,19 @@
from get_argv import config_dir
# coding=utf-8
import sqlite3
import os
from subliminal import provider_manager
import collections
from subliminal import provider_manager
from get_argv import config_dir
def load_providers():
# Get providers list from subliminal
providers_list = sorted(provider_manager.names())
# Open database connection
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
# Remove unsupported providers
@ -34,7 +37,7 @@ def load_providers():
def get_providers():
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
enabled_providers = c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1").fetchall()
c.close()
@ -50,7 +53,7 @@ def get_providers():
def get_providers_auth():
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
enabled_providers = c.execute("SELECT * FROM table_settings_providers WHERE enabled = 1 AND username is not NULL AND password is not NULL").fetchall()
c.close()
@ -64,4 +67,4 @@ def get_providers_auth():
else:
providers_auth = None
return providers_auth
return providers_auth

@ -1,22 +1,21 @@
from get_argv import config_dir
# coding=utf-8
import os
import sqlite3
import requests
import logging
from get_settings import get_general_settings
from get_argv import config_dir
from config import settings, url_sonarr
from list_subtitles import list_missing_subtitles
def update_series():
from get_settings import get_sonarr_settings
url_sonarr = get_sonarr_settings()[6]
apikey_sonarr = get_sonarr_settings()[4]
serie_default_enabled = get_general_settings()[15]
serie_default_language = get_general_settings()[16]
serie_default_hi = get_general_settings()[17]
if apikey_sonarr == None:
apikey_sonarr = settings.sonarr.apikey
serie_default_enabled = settings.general.serie_default_enabled
serie_default_language = settings.general.serie_default_language
serie_default_hi = settings.general.serie_default_hi
if apikey_sonarr is None:
pass
else:
get_profile_list()
@ -105,11 +104,9 @@ def update_series():
db.commit()
db.close()
def get_profile_list():
from get_settings import get_sonarr_settings
url_sonarr = get_sonarr_settings()[6]
# url_sonarr_short = get_sonarr_settings()[5]
apikey_sonarr = get_sonarr_settings()[4]
apikey_sonarr = settings.sonarr.apikey
# Get profiles data from Sonarr
error = False
@ -155,6 +152,7 @@ def get_profile_list():
for profile in profiles_json_v3.json():
profiles_list.append([profile['id'], profile['name'].capitalize()])
def profile_id_to_language(id):
for profile in profiles_list:
if id == profile[0]:

@ -390,7 +390,6 @@ def get_radarr_settings():
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:

@ -1,30 +1,35 @@
from get_argv import config_dir
import os
import sqlite3
# coding=utf-8
import ast
import cPickle as pickle
import codecs
import logging
import operator
import os
import sqlite3
import subprocess
import time
from datetime import datetime, timedelta
from babelfish import Language
from subliminal import region, scan_video, Video, download_best_subtitles, compute_score, save_subtitles, AsyncProviderPool, score, list_subtitles, download_subtitles
from subliminal import AsyncProviderPool, Video, compute_score, download_subtitles, region, save_subtitles, scan_video, \
score
from subliminal.providers.legendastv import LegendasTVSubtitle
from subliminal.subtitle import get_subtitle_path
from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2
from bs4 import UnicodeDammit
from get_settings import get_general_settings, pp_replace, path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
from list_subtitles import store_subtitles, list_missing_subtitles, store_subtitles_movie, list_missing_subtitles_movies
from utils import history_log, history_log_movie
from notifier import send_notifications, send_notifications_movie
import cPickle as pickle
import codecs
from get_argv import config_dir
from get_languages import alpha2_from_alpha3, alpha3_from_alpha2, language_from_alpha3
from get_providers import get_providers, get_providers_auth
from subliminal.providers.legendastv import LegendasTVSubtitle
from config import settings
from helper import path_replace, path_replace_movie, path_replace_reverse, \
path_replace_reverse_movie, pp_replace
from list_subtitles import list_missing_subtitles, list_missing_subtitles_movies, store_subtitles, store_subtitles_movie
from notifier import send_notifications, send_notifications_movie
from utils import history_log, history_log_movie
# configure the cache
region.configure('dogpile.cache.memory')
def download_subtitle(path, language, hi, providers, providers_auth, sceneName, media_type):
logging.debug('BAZARR Searching subtitles for this file: ' + path)
if hi == "True":
@ -37,11 +42,11 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
else:
language_set.add(Language(language))
use_scenename = get_general_settings()[9]
minimum_score = get_general_settings()[8]
minimum_score_movie = get_general_settings()[22]
use_postprocessing = get_general_settings()[10]
postprocessing_cmd = get_general_settings()[11]
use_scenename = settings.general.use_scenename
minimum_score = settings.general.minimum_score
minimum_score_movie = settings.general.minimum_score_movie
use_postprocessing = settings.general.use_postprocessing
postprocessing_cmd = settings.general.postprocessing_cmd
try:
if sceneName == "None" or use_scenename is False:
@ -100,13 +105,13 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
download_result = False
for subtitle in subtitles_list:
download_result = p.download_subtitle(subtitle)
if download_result == True:
if download_result:
logging.debug('BAZARR Subtitles file downloaded from ' + str(subtitle.provider_name) + ' for this file: ' + path)
break
else:
logging.warning('BAZARR Subtitles file skipped from ' + str(subtitle.provider_name) + ' for this file: ' + path + ' because no content was returned by the provider (probably throttled).')
continue
if download_result == False:
if not download_result:
logging.error('BAZARR Tried to download a subtitles for file: ' + path + " but we weren't able to do it this time (probably being throttled). Going to retry on next search.")
return None
except Exception as e:
@ -115,9 +120,9 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
else:
try:
calculated_score = round(float(compute_score(subtitle, video, hearing_impaired=hi)) / max_score * 100, 2)
if used_sceneName == True:
if used_sceneName:
video = scan_video(path)
single = get_general_settings()[7]
single = settings.general.single_language
if single is True:
result = save_subtitles(video, [subtitle], single=True, encoding='utf-8')
else:
@ -132,7 +137,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
downloaded_language_code3 = result[0].language.alpha3
downloaded_path = get_subtitle_path(path, downloaded_language_code2)
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
if used_sceneName == True:
if used_sceneName:
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(calculated_score) + "% using this scene name: " + sceneName
else:
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(calculated_score) + "% using filename guessing."
@ -170,6 +175,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
return None
logging.debug('BAZARR Ended searching subtitles for file: ' + path)
def manual_search(path, language, hi, providers, providers_auth, sceneName, media_type):
logging.debug('BAZARR Manually searching subtitles for this file: ' + path)
@ -187,9 +193,9 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, medi
else:
language_set.add(Language(lang))
use_scenename = get_general_settings()[9]
use_postprocessing = get_general_settings()[10]
postprocessing_cmd = get_general_settings()[11]
use_scenename = settings.general.use_scenename
use_postprocessing = settings.general.use_postprocessing
postprocessing_cmd = settings.general.postprocessing_cmd
try:
if sceneName == "None" or use_scenename is False:
@ -247,6 +253,7 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, medi
logging.debug('BAZARR Ended searching subtitles for this file: ' + path)
return(subtitles_dict)
def manual_download_subtitle(path, language, hi, subtitle, provider, providers_auth, sceneName, media_type):
logging.debug('BAZARR Manually downloading subtitles for this file: ' + path)
if hi == "True":
@ -258,9 +265,9 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
type_of_score = 360
elif media_type == 'movie':
type_of_score = 120
use_scenename = get_general_settings()[9]
use_postprocessing = get_general_settings()[10]
postprocessing_cmd = get_general_settings()[11]
use_scenename = settings.general.use_scenename
use_postprocessing = settings.general.use_postprocessing
postprocessing_cmd = settings.general.postprocessing_cmd
language = alpha3_from_alpha2(language)
if language == 'pob':
@ -286,7 +293,7 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
logging.exception('BAZARR Error downloading subtitles for this file ' + path)
return None
else:
single = get_general_settings()[7]
single = settings.general.single_language
try:
score = round(float(compute_score(subtitle, video, hearing_impaired=hi)) / type_of_score * 100, 2)
if used_sceneName == True:
@ -341,13 +348,14 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a
return None
logging.debug('BAZARR Ended manually downloading subtitles for file: ' + path)
def series_download_subtitles(no):
if get_general_settings()[24] is True:
if settings.general.only_monitored:
monitored_only_query_string = ' AND monitored = "True"'
else:
monitored_only_query_string = ""
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes_details = c_db.execute('SELECT path, missing_subtitles, sonarrEpisodeId, scene_name FROM table_episodes WHERE sonarrSeriesId = ? AND missing_subtitles != "[]"' + monitored_only_query_string, (no,)).fetchall()
series_details = c_db.execute("SELECT hearing_impaired FROM table_shows WHERE sonarrSeriesId = ?", (no,)).fetchone()
@ -368,7 +376,7 @@ def series_download_subtitles(no):
def movies_download_subtitles(no):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
movie = c_db.execute("SELECT path, missing_subtitles, radarrId, sceneName, hearing_impaired FROM table_movies WHERE radarrId = ?", (no,)).fetchone()
c_db.close()
@ -387,7 +395,7 @@ def movies_download_subtitles(no):
def wanted_download_subtitles(path):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes_details = c_db.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, table_shows.hearing_impaired, table_episodes.scene_name, table_episodes.failedAttempts FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? AND missing_subtitles != '[]'", (path_replace_reverse(path),)).fetchall()
c_db.close()
@ -408,7 +416,7 @@ def wanted_download_subtitles(path):
if language not in att:
attempt.append([language, time.time()])
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
c_db.execute('UPDATE table_episodes SET failedAttempts = ? WHERE sonarrEpisodeId = ?', (unicode(attempt), episode[2]))
conn_db.commit()
@ -428,7 +436,7 @@ def wanted_download_subtitles(path):
def wanted_download_subtitles_movie(path):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
movies_details = c_db.execute("SELECT path, missing_subtitles, radarrId, radarrId, hearing_impaired, sceneName, failedAttempts FROM table_movies WHERE path = ? AND missing_subtitles != '[]'", (path_replace_reverse_movie(path),)).fetchall()
c_db.close()
@ -449,7 +457,7 @@ def wanted_download_subtitles_movie(path):
if language not in att:
attempt.append([language, time.time()])
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
c_db.execute('UPDATE table_movies SET failedAttempts = ? WHERE radarrId = ?', (unicode(attempt), movie[2]))
conn_db.commit()
@ -469,12 +477,12 @@ def wanted_download_subtitles_movie(path):
def wanted_search_missing_subtitles():
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace)
db.create_function("path_substitution_movie", 1, path_replace_movie)
c = db.cursor()
if get_general_settings()[24] is True:
if settings.general.only_monitored:
monitored_only_query_string = ' AND monitored = "True"'
else:
monitored_only_query_string = ""
@ -487,13 +495,11 @@ def wanted_search_missing_subtitles():
c.close()
integration = get_general_settings()
if integration[12] is True:
if settings.general.use_sonarr:
for episode in episodes:
wanted_download_subtitles(episode[0])
if integration[13] is True:
if settings.general.use_radarr:
for movie in movies:
wanted_download_subtitles_movie(movie[0])
@ -501,7 +507,7 @@ def wanted_search_missing_subtitles():
def search_active(timestamp):
if get_general_settings()[25] is True:
if settings.general.only_monitored:
search_deadline = timedelta(weeks=3)
search_delta = timedelta(weeks=1)
aa = datetime.fromtimestamp(float(timestamp))

@ -1,4 +1,5 @@
# coding=utf-8
import ast
import os
import re
@ -6,7 +7,7 @@ from config import settings
def path_replace(path):
for path_mapping in settings.general.path_mappings:
for path_mapping in ast.literal_eval(settings.general.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):
@ -18,7 +19,7 @@ def path_replace(path):
def path_replace_reverse(path):
for path_mapping in settings.general.path_mappings:
for path_mapping in ast.literal_eval(settings.general.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):
@ -30,7 +31,7 @@ def path_replace_reverse(path):
def path_replace_movie(path):
for path_mapping in settings.general.path_mappings_movie:
for path_mapping in ast.literal_eval(settings.general.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):
@ -42,7 +43,7 @@ def path_replace_movie(path):
def path_replace_reverse_movie(path):
for path_mapping in settings.general.path_mappings_movie:
for path_mapping in ast.literal_eval(settings.general.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):

@ -1,3 +1,4 @@
# coding=utf-8
import os
import sqlite3
import logging
@ -5,10 +6,11 @@ import time
from cork import Cork
from configparser import ConfigParser
from check_update import check_releases
from get_argv import config_dir
# Check if config_dir exist
if os.path.exists(config_dir) is False:
if not os.path.exists(config_dir):
# Create config_dir directory tree
try:
os.mkdir(os.path.join(config_dir))
@ -17,22 +19,21 @@ if os.path.exists(config_dir) is False:
logging.exception("BAZARR 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:
if not os.path.exists(os.path.join(config_dir, 'config')):
os.mkdir(os.path.join(config_dir, 'config'))
logging.debug("BAZARR Created config folder")
if os.path.exists(os.path.join(config_dir, 'db')) is False:
if not os.path.exists(os.path.join(config_dir, 'db')):
os.mkdir(os.path.join(config_dir, 'db'))
logging.debug("BAZARR Created db folder")
if os.path.exists(os.path.join(config_dir, 'log')) is False:
if not os.path.exists(os.path.join(config_dir, 'log')):
os.mkdir(os.path.join(config_dir, 'log'))
logging.debug("BAZARR Created log folder")
if not os.path.exists(os.path.join(config_dir, 'config', 'releases.txt')):
from check_update import check_releases
check_releases()
logging.debug("BAZARR Created releases file")
config_file = os.path.normpath(os.path.join(config_dir, 'config/config.ini'))
config_file = os.path.normpath(os.path.join(config_dir, 'config', 'config.ini'))
cfg = ConfigParser()
try:
@ -44,7 +45,7 @@ try:
fd.close()
# Open database connection
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
# Execute script and commit change to database
@ -81,7 +82,7 @@ if cfg.has_section('general'):
with open(config_file, 'w+') as configfile:
cfg.write(configfile)
if os.path.exists(os.path.normpath(os.path.join(config_dir, 'config/users.json'))) is False:
if not os.path.exists(os.path.normpath(os.path.join(config_dir, 'config', 'users.json'))):
cork = Cork(os.path.normpath(os.path.join(config_dir, 'config')), initialize=True)
cork._store.roles[''] = 100

@ -1,22 +1,24 @@
from get_argv import config_dir
import ast
import gc
import os
import enzyme
import babelfish
import logging
from subliminal import core
import os
import sqlite3
import ast
from itertools import islice
import enzyme
import langdetect
from bs4 import UnicodeDammit
from itertools import islice
from subliminal import core
from get_settings import path_replace_reverse, path_replace, path_replace_reverse_movie, path_replace_movie, get_general_settings
from get_argv import config_dir
from get_languages import alpha2_from_alpha3
from config import settings
from helper import path_replace, path_replace_movie, path_replace_reverse, \
path_replace_reverse_movie
gc.enable()
def store_subtitles(file):
logging.debug('BAZARR started subtitles indexing for this file: ' + file)
actual_subtitles = []
@ -29,7 +31,7 @@ def store_subtitles(file):
for subtitle_track in mkv.subtitle_tracks:
try:
if alpha2_from_alpha3(subtitle_track.language) != None:
if alpha2_from_alpha3(subtitle_track.language) is not None:
lang = str(alpha2_from_alpha3(subtitle_track.language))
logging.debug("BAZARR embedded subtitles detected: " + lang)
actual_subtitles.append([lang,None])
@ -51,7 +53,7 @@ def store_subtitles(file):
pass
else:
for subtitle, language in subtitles.iteritems():
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)) is True:
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)):
logging.debug("BAZARR external subtitles detected: " + "pb")
actual_subtitles.append([str("pb"), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))])
elif str(language) != 'und':
@ -101,7 +103,7 @@ def store_subtitles_movie(file):
for subtitle_track in mkv.subtitle_tracks:
try:
if alpha2_from_alpha3(subtitle_track.language) != None:
if alpha2_from_alpha3(subtitle_track.language) is not None:
lang = str(alpha2_from_alpha3(subtitle_track.language))
logging.debug("BAZARR embedded subtitles detected: " + lang)
actual_subtitles.append([lang, None])
@ -146,7 +148,7 @@ def store_subtitles_movie(file):
logging.debug("BAZARR external subtitles detected and analysis guessed this language: " + str(detected_language))
actual_subtitles.append([str(detected_language), path_replace_reverse_movie(os.path.join(os.path.dirname(file), subtitle))])
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
logging.debug("BAZARR storing those languages to DB: " + str(actual_subtitles))
c_db.execute("UPDATE table_movies SET subtitles = ? WHERE path = ?", (str(actual_subtitles), path_replace_reverse_movie(file)))
@ -167,30 +169,30 @@ def list_missing_subtitles(*no):
query_string = " WHERE table_shows.sonarrSeriesId = " + str(no[0])
except:
pass
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes_subtitles = c_db.execute("SELECT table_episodes.sonarrEpisodeId, table_episodes.subtitles, table_shows.languages FROM table_episodes INNER JOIN table_shows on table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId" + query_string).fetchall()
c_db.close()
missing_subtitles_global = []
use_embedded_subs = get_general_settings()[23]
use_embedded_subs = settings.general.use_embedded_subs
for episode_subtitles in episodes_subtitles:
actual_subtitles_temp = []
actual_subtitles = []
desired_subtitles = []
missing_subtitles = []
if episode_subtitles[1] != None:
if use_embedded_subs is True:
if episode_subtitles[1] is not None:
if use_embedded_subs:
actual_subtitles = ast.literal_eval(episode_subtitles[1])
else:
actual_subtitles_temp = ast.literal_eval(episode_subtitles[1])
for subtitle in actual_subtitles_temp:
if subtitle[1] != None:
if subtitle[1] is not None:
actual_subtitles.append(subtitle)
if episode_subtitles[2] != None:
if episode_subtitles[2] is not None:
desired_subtitles = ast.literal_eval(episode_subtitles[2])
actual_subtitles_list = []
if desired_subtitles == None:
if desired_subtitles is None:
missing_subtitles_global.append(tuple(['[]', episode_subtitles[0]]))
else:
for item in actual_subtitles:
@ -201,7 +203,7 @@ def list_missing_subtitles(*no):
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles[0]]))
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
c_db.executemany("UPDATE table_episodes SET missing_subtitles = ? WHERE sonarrEpisodeId = ?", (missing_subtitles_global))
conn_db.commit()
@ -214,30 +216,30 @@ def list_missing_subtitles_movies(*no):
query_string = " WHERE table_movies.radarrId = " + str(no[0])
except:
pass
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
movies_subtitles = c_db.execute("SELECT radarrId, subtitles, languages FROM table_movies" + query_string).fetchall()
c_db.close()
missing_subtitles_global = []
use_embedded_subs = get_general_settings()[23]
use_embedded_subs = settings.general.use_embedded_subs
for movie_subtitles in movies_subtitles:
actual_subtitles_temp = []
actual_subtitles = []
desired_subtitles = []
missing_subtitles = []
if movie_subtitles[1] != None:
if use_embedded_subs is True:
if movie_subtitles[1] is not None:
if use_embedded_subs:
actual_subtitles = ast.literal_eval(movie_subtitles[1])
else:
actual_subtitles_temp = ast.literal_eval(movie_subtitles[1])
for subtitle in actual_subtitles_temp:
if subtitle[1] != None:
if subtitle[1] is not None:
actual_subtitles.append(subtitle)
if movie_subtitles[2] != None:
if movie_subtitles[2] is not None:
desired_subtitles = ast.literal_eval(movie_subtitles[2])
actual_subtitles_list = []
if desired_subtitles == None:
if desired_subtitles is None:
missing_subtitles_global.append(tuple(['[]', movie_subtitles[0]]))
else:
for item in actual_subtitles:
@ -248,14 +250,15 @@ def list_missing_subtitles_movies(*no):
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
missing_subtitles_global.append(tuple([str(missing_subtitles), movie_subtitles[0]]))
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
c_db.executemany("UPDATE table_movies SET missing_subtitles = ? WHERE radarrId = ?", (missing_subtitles_global))
conn_db.commit()
c_db.close()
def series_full_scan_subtitles():
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes = c_db.execute("SELECT path FROM table_episodes").fetchall()
c_db.close()
@ -266,7 +269,7 @@ def series_full_scan_subtitles():
gc.collect()
def movies_full_scan_subtitles():
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
movies = c_db.execute("SELECT path FROM table_movies").fetchall()
c_db.close()
@ -277,7 +280,7 @@ def movies_full_scan_subtitles():
gc.collect()
def series_scan_subtitles(no):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
episodes = c_db.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall()
c_db.close()
@ -289,7 +292,7 @@ def series_scan_subtitles(no):
def movies_scan_subtitles(no):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
movies = c_db.execute("SELECT path FROM table_movies WHERE radarrId = ?", (no,)).fetchall()
c_db.close()

@ -162,4 +162,5 @@ class PublicIPFilter(ArgsFilteringFilter):
def empty_log():
fh.doRollover()
fh.doRollover()

@ -11,8 +11,6 @@ reload(sys)
sys.setdefaultencoding('utf8')
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../libs/'))
import os
import sys
import signal
import sqlite3
from init import *
@ -21,21 +19,21 @@ from notifier import update_notifier
update_notifier()
from get_settings import get_general_settings, get_proxy_settings
import logging
from logger import configure_logging, empty_log
from config import settings, url_sonarr, url_radarr, url_radarr_short, url_sonarr_short, base_url
configure_logging(get_general_settings()[4])
configure_logging(settings.general.debug)
import requests
if get_proxy_settings()[0] != 'None':
if get_proxy_settings()[3] != '' and get_proxy_settings()[4] != '':
proxy = get_proxy_settings()[0] + '://' + get_proxy_settings()[3] + ':' + get_proxy_settings()[4] + '@' + get_proxy_settings()[1] + ':' + get_proxy_settings()[2]
if settings.proxy.type != 'None':
if settings.proxy.username != '' and settings.proxy.password != '':
proxy = settings.proxy.type + '://' + settings.proxy.username + ':' + settings.proxy.password + '@' + settings.proxy.url + ':' + settings.proxy.port
else:
proxy = get_proxy_settings()[0] + '://' + get_proxy_settings()[1] + ':' + get_proxy_settings()[2]
proxy = settings.proxy.type + '://' + settings.proxy.url + ':' + settings.proxy.port
os.environ['HTTP_PROXY'] = str(proxy)
os.environ['HTTPS_PROXY'] = str(proxy)
os.environ['NO_PROXY'] = str(get_proxy_settings()[5])
os.environ['NO_PROXY'] = str(settings.proxy.exclude)
from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app, hook
import bottle
@ -71,7 +69,7 @@ load_providers()
from get_series import *
from get_episodes import *
from get_settings import base_url, ip, port, path_replace, path_replace_movie
from helper import path_replace, path_replace_movie
if no_update is False:
from check_update import check_and_apply_update
from list_subtitles import store_subtitles, store_subtitles_movie, series_scan_subtitles, movies_scan_subtitles, list_missing_subtitles, list_missing_subtitles_movies
@ -80,23 +78,22 @@ from utils import history_log, history_log_movie
from scheduler import *
from notifier import send_notifications, send_notifications_movie
# Reset restart required warning on start
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
c.execute("UPDATE system SET configured = 0, updated = 0")
conn.commit()
c.close()
logging.debug('Bazarr version: %s', bazarr_version)
logging.debug('Bazarr branch: %s', get_general_settings()[5])
logging.debug('Bazarr branch: %s', settings.general.branch)
logging.debug('Operating system: %s', platform.platform())
logging.debug('Python version: %s', platform.python_version())
# Load languages in database
load_language_in_db()
from get_settings import get_auth_settings
aaa = Cork(os.path.normpath(os.path.join(config_dir, 'config')))
app = app()
@ -109,13 +106,13 @@ session_opts = {
'session.validate_key': True
}
app = SessionMiddleware(app, session_opts)
login_auth = get_auth_settings()[0]
login_auth = settings.auth.type
def custom_auth_basic(check):
def decorator(func):
def wrapper(*a, **ka):
if get_auth_settings()[0] == 'basic':
if settings.auth.type == 'basic':
user, password = request.auth or (None, None)
if user is None or not check(user, password):
err = HTTPError(401, "Access denied")
@ -128,11 +125,11 @@ def custom_auth_basic(check):
return wrapper
return decorator
def check_credentials(user, pw):
from get_settings import get_auth_settings
username = get_auth_settings()[1]
password = get_auth_settings()[2]
username = settings.auth.username
password = settings.auth.password
if hashlib.md5(pw).hexdigest() == password and user == username:
return True
return False
@ -178,6 +175,7 @@ def redirect_root():
authorize()
redirect (base_url)
@route(base_url + 'shutdown')
def shutdown():
try:
@ -189,6 +187,7 @@ def shutdown():
stop_file.close()
server.stop()
@route(base_url + 'restart')
def restart():
try:
@ -211,19 +210,15 @@ def restart():
@custom_auth_basic(check_credentials)
def wizard():
authorize()
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
settings_languages = c.execute("SELECT * FROM table_settings_languages ORDER BY name").fetchall()
settings_providers = c.execute("SELECT * FROM table_settings_providers ORDER BY name").fetchall()
c.close()
settings_general = get_general_settings()
settings_sonarr = get_sonarr_settings()
settings_radarr = get_radarr_settings()
return template('wizard', bazarr_version=bazarr_version, settings_general=settings_general,
return template('wizard', bazarr_version=bazarr_version, settings=settings,
settings_languages=settings_languages, settings_providers=settings_providers,
settings_sonarr=settings_sonarr, settings_radarr=settings_radarr, base_url=base_url)
base_url=base_url)
@route(base_url + 'save_wizard', method='POST')
@ -231,7 +226,7 @@ def wizard():
def save_wizard():
authorize()
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
settings_general_ip = request.forms.get('settings_general_ip')
@ -278,39 +273,39 @@ def save_wizard():
cfg.set('general', 'port', text_type(settings_general_port))
cfg.set('general', 'base_url', text_type(settings_general_baseurl))
cfg.set('general', 'path_mappings', text_type(settings_general_pathmapping))
cfg.set('general', 'log_level', text_type(get_general_settings()[4]))
cfg.set('general', 'branch', text_type(get_general_settings()[5]))
cfg.set('general', 'auto_update', text_type(get_general_settings()[6]))
cfg.set('general', 'debug', text_type(settings.general.debug))
cfg.set('general', 'branch', text_type(settings.general.branch))
cfg.set('general', 'auto_update', text_type(settings.general.auto_update))
cfg.set('general', 'single_language', text_type(settings_general_single_language))
cfg.set('general', 'minimum_score', text_type(get_general_settings()[8]))
cfg.set('general', 'use_scenename', text_type(text_type(get_general_settings()[9])))
cfg.set('general', 'use_postprocessing', text_type(get_general_settings()[10]))
cfg.set('general', 'postprocessing_cmd', text_type(get_general_settings()[11]))
cfg.set('general', 'minimum_score', text_type(settings.general.minimum_score))
cfg.set('general', 'use_scenename', text_type(text_type(settings.general.use_scenename)))
cfg.set('general', 'use_postprocessing', text_type(settings.general.use_postprocessing))
cfg.set('general', 'postprocessing_cmd', text_type(settings.general.postprocessing_cmd))
cfg.set('general', 'use_sonarr', text_type(settings_general_use_sonarr))
cfg.set('general', 'use_radarr', text_type(settings_general_use_radarr))
cfg.set('general', 'path_mappings_movie', text_type(settings_general_pathmapping_movie))
cfg.set('general', 'page_size', text_type(get_general_settings()[21]))
cfg.set('general', 'minimum_score_movie', text_type(get_general_settings()[22]))
cfg.set('general', 'use_embedded_subs', text_type(get_general_settings()[23]))
cfg.set('general', 'only_monitored', text_type(get_general_settings()[24]))
cfg.set('general', 'page_size', text_type(settings.general.page_size))
cfg.set('general', 'minimum_score_movie', text_type(settings.general.minimum_score_movie))
cfg.set('general', 'use_embedded_subs', text_type(settings.general.use_embedded_subs))
cfg.set('general', 'only_monitored', text_type(settings.general.only_monitored))
cfg.set('general', 'adaptive_searching', text_type(settings_general_adaptive_searching))
if not cfg.has_section('proxy'):
cfg.add_section('proxy')
cfg.set('proxy', 'type', text_type(get_proxy_settings()[0]))
cfg.set('proxy', 'url', text_type(get_proxy_settings()[1]))
cfg.set('proxy', 'port', text_type(get_proxy_settings()[2]))
cfg.set('proxy', 'username', text_type(get_proxy_settings()[3]))
cfg.set('proxy', 'password', text_type(get_proxy_settings()[4]))
cfg.set('proxy', 'exclude', text_type(get_proxy_settings()[5]))
cfg.set('proxy', 'type', text_type(settings.proxy.type))
cfg.set('proxy', 'url', text_type(settings.proxy.url))
cfg.set('proxy', 'port', text_type(settings.proxy.port))
cfg.set('proxy', 'username', text_type(settings.proxy.username))
cfg.set('proxy', 'password', text_type(settings.proxy.password))
cfg.set('proxy', 'exclude', text_type(settings.proxy.exclude))
if not cfg.has_section('auth'):
cfg.add_section('auth')
cfg.set('auth', 'type', text_type(get_auth_settings()[0]))
cfg.set('auth', 'username', text_type(get_auth_settings()[1]))
cfg.set('auth', 'password', text_type(get_auth_settings()[2]))
cfg.set('auth', 'type', text_type(settings.auth.type))
cfg.set('auth', 'username', text_type(settings.auth.username))
cfg.set('auth', 'password', text_type(settings.auth.password))
settings_sonarr_ip = request.forms.get('settings_sonarr_ip')
settings_sonarr_port = request.forms.get('settings_sonarr_port')
@ -330,7 +325,7 @@ def save_wizard():
cfg.set('sonarr', 'base_url', text_type(settings_sonarr_baseurl))
cfg.set('sonarr', 'ssl', text_type(settings_sonarr_ssl))
cfg.set('sonarr', 'apikey', text_type(settings_sonarr_apikey))
cfg.set('sonarr', 'full_update', text_type(get_sonarr_settings()[5]))
cfg.set('sonarr', 'full_update', text_type(settings.sonarr.full_update))
settings_radarr_ip = request.forms.get('settings_radarr_ip')
settings_radarr_port = request.forms.get('settings_radarr_port')
@ -354,7 +349,7 @@ def save_wizard():
cfg.set('radarr', 'base_url', text_type(settings_radarr_baseurl))
cfg.set('radarr', 'ssl', text_type(settings_radarr_ssl))
cfg.set('radarr', 'apikey', text_type(settings_radarr_apikey))
cfg.set('radarr', 'full_update', text_type(get_radarr_settings()[5]))
cfg.set('radarr', 'full_update', text_type(settings.radarr.full_update))
settings_subliminal_providers = request.forms.getall('settings_subliminal_providers')
c.execute("UPDATE table_settings_providers SET enabled = 0")
@ -442,9 +437,7 @@ def download_log():
@custom_auth_basic(check_credentials)
def image_proxy(url):
authorize()
url_sonarr = get_sonarr_settings()[6]
url_sonarr_short = get_sonarr_settings()[7]
apikey = get_sonarr_settings()[4]
apikey = settings.sonarr.apikey
url_image = url_sonarr_short + '/' + url + '?apikey=' + apikey
try:
image_buffer = BytesIO(requests.get(url_sonarr + '/api' + url_image.split(url_sonarr)[1], timeout=15, verify=False).content)
@ -460,9 +453,7 @@ def image_proxy(url):
@custom_auth_basic(check_credentials)
def image_proxy_movies(url):
authorize()
url_radarr = get_radarr_settings()[6]
url_radarr_short = get_radarr_settings()[7]
apikey = get_radarr_settings()[4]
apikey = settings.radarr.apikey
try:
url_image = (url_radarr_short + '/' + url + '?apikey=' + apikey).replace('/fanart.jpg', '/banner.jpg')
image_buffer = BytesIO(requests.get(url_radarr + '/api' + url_image.split(url_radarr)[1], timeout=15, verify=False).content)
@ -481,9 +472,9 @@ def image_proxy_movies(url):
@custom_auth_basic(check_credentials)
def redirect_root():
authorize()
if get_general_settings()[12] is True:
if settings.general.use_sonarr is True:
redirect(base_url + 'series')
elif get_general_settings()[13] is True:
elif settings.general.use_radarr is True:
redirect(base_url + 'movies')
elif os.path.exists(os.path.join(config_dir, 'config/config.ini')) is False:
redirect(base_url + 'wizard')
@ -495,9 +486,9 @@ def redirect_root():
@custom_auth_basic(check_credentials)
def series():
authorize()
single_language = get_general_settings()[7]
single_language = settings.general.single_language
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace)
c = db.cursor()
@ -507,11 +498,11 @@ def series():
page = request.GET.page
if page == "":
page = "1"
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
offset = (int(page) - 1) * page_size
max_page = int(math.ceil(missing_count / (page_size + 0.0)))
if get_general_settings()[24] is True:
if settings.general.only_monitored is True:
monitored_only_query_string = ' AND monitored = "True"'
else:
monitored_only_query_string = ""
@ -528,7 +519,7 @@ def series():
output = template('series', bazarr_version=bazarr_version, rows=data,
missing_subtitles_list=missing_subtitles_list, total_subtitles_list=total_subtitles_list,
languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url,
single_language=single_language, page_size=page_size, current_port=port)
single_language=single_language, page_size=page_size, current_port=settings.general.port)
return output
@ -536,9 +527,9 @@ def series():
@custom_auth_basic(check_credentials)
def serieseditor():
authorize()
single_language = get_general_settings()[7]
single_language = settings.general.single_language
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace)
c = db.cursor()
@ -551,7 +542,7 @@ def serieseditor():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall()
c.close()
output = template('serieseditor', bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language, current_port=port)
output = template('serieseditor', bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language, current_port=settings.general.port)
return output
@ -559,18 +550,18 @@ def serieseditor():
@custom_auth_basic(check_credentials)
def search_json(query):
authorize()
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
search_list = []
if get_general_settings()[12] is True:
if settings.general.use_sonarr is True:
c.execute("SELECT title, sonarrSeriesId FROM table_shows WHERE title LIKE ? ORDER BY title",
('%' + query + '%',))
series = c.fetchall()
for serie in series:
search_list.append(dict([('name', serie[0]), ('url', base_url + 'episodes/' + str(serie[1]))]))
if get_general_settings()[13] is True:
if settings.general.use_radarr is True:
c.execute("SELECT title, radarrId FROM table_movies WHERE title LIKE ? ORDER BY title", ('%' + query + '%',))
movies = c.fetchall()
for movie in movies:
@ -593,7 +584,7 @@ def edit_series(no):
else:
lang = 'None'
single_language = get_general_settings()[7]
single_language = settings.general.single_language
if single_language is True:
if str(lang) == "['None']":
lang = 'None'
@ -610,7 +601,7 @@ def edit_series(no):
else:
hi = "False"
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
c.execute("UPDATE table_shows SET languages = ?, hearing_impaired = ? WHERE sonarrSeriesId LIKE ?", (str(lang), hi, no))
conn.commit()
@ -620,6 +611,7 @@ def edit_series(no):
redirect(ref)
@route(base_url + 'edit_serieseditor', method='POST')
@custom_auth_basic(check_credentials)
def edit_serieseditor():
@ -631,7 +623,7 @@ def edit_serieseditor():
lang = request.forms.getall('languages')
hi = request.forms.get('hearing_impaired')
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
for serie in series:
@ -652,14 +644,14 @@ def edit_serieseditor():
redirect(ref)
@route(base_url + 'episodes/<no:int>', method='GET')
@custom_auth_basic(check_credentials)
def episodes(no):
authorize()
# single_language = get_general_settings()[7]
url_sonarr_short = get_sonarr_settings()[7]
# single_language = settings.general.single_language
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
conn.create_function("path_substitution", 1, path_replace)
c = conn.cursor()
@ -676,15 +668,16 @@ def episodes(no):
for key, season in itertools.groupby(episodes,operator.itemgetter(2)):
seasons_list.append(list(season))
return template('episodes', bazarr_version=bazarr_version, no=no, details=series_details, languages=languages, seasons=seasons_list, url_sonarr_short=url_sonarr_short, base_url=base_url, tvdbid=tvdbid, number=number, current_port=port)
return template('episodes', bazarr_version=bazarr_version, no=no, details=series_details, languages=languages, seasons=seasons_list, url_sonarr_short=url_sonarr_short, base_url=base_url, tvdbid=tvdbid, number=number, current_port=settings.general.port)
@route(base_url + 'movies')
@custom_auth_basic(check_credentials)
def movies():
authorize()
single_language = get_general_settings()[7]
single_language = settings.general.single_language
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace_movie)
c = db.cursor()
@ -694,7 +687,7 @@ def movies():
page = request.GET.page
if page == "":
page = "1"
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
offset = (int(page) - 1) * page_size
max_page = int(math.ceil(missing_count / (page_size + 0.0)))
@ -703,16 +696,17 @@ def movies():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall()
c.close()
output = template('movies', bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size, current_port=port)
output = template('movies', bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size, current_port=settings.general.port)
return output
@route(base_url + 'movieseditor')
@custom_auth_basic(check_credentials)
def movieseditor():
authorize()
single_language = get_general_settings()[7]
single_language = settings.general.single_language
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace_movie)
c = db.cursor()
@ -725,9 +719,10 @@ def movieseditor():
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages = c.fetchall()
c.close()
output = template('movieseditor', bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language, current_port=port)
output = template('movieseditor', bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, base_url=base_url, single_language=single_language, current_port=settings.general.port)
return output
@route(base_url + 'edit_movieseditor', method='POST')
@custom_auth_basic(check_credentials)
def edit_movieseditor():
@ -739,7 +734,7 @@ def edit_movieseditor():
lang = request.forms.getall('languages')
hi = request.forms.get('hearing_impaired')
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
for movie in movies:
@ -760,6 +755,7 @@ def edit_movieseditor():
redirect(ref)
@route(base_url + 'edit_movie/<no:int>', method='POST')
@custom_auth_basic(check_credentials)
def edit_movie(no):
@ -782,7 +778,7 @@ def edit_movie(no):
else:
hi = "False"
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
c.execute("UPDATE table_movies SET languages = ?, hearing_impaired = ? WHERE radarrId LIKE ?", (str(lang), hi, no))
conn.commit()
@ -792,14 +788,14 @@ def edit_movie(no):
redirect(ref)
@route(base_url + 'movie/<no:int>', method='GET')
@custom_auth_basic(check_credentials)
def movie(no):
authorize()
# single_language = get_general_settings()[7]
url_radarr_short = get_radarr_settings()[7]
# single_language = settings.general.single_language
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
conn.create_function("path_substitution", 1, path_replace_movie)
c = conn.cursor()
@ -810,7 +806,8 @@ def movie(no):
languages = c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1").fetchall()
c.close()
return template('movie', bazarr_version=bazarr_version, no=no, details=movies_details, languages=languages, url_radarr_short=url_radarr_short, base_url=base_url, tmdbid=tmdbid, current_port=port)
return template('movie', bazarr_version=bazarr_version, no=no, details=movies_details, languages=languages, url_radarr_short=url_radarr_short, base_url=base_url, tmdbid=tmdbid, current_port=settings.general.port)
@route(base_url + 'scan_disk/<no:int>', method='GET')
@custom_auth_basic(check_credentials)
@ -832,6 +829,7 @@ def scan_disk_movie(no):
redirect(ref)
@route(base_url + 'search_missing_subtitles/<no:int>', method='GET')
@custom_auth_basic(check_credentials)
def search_missing_subtitles(no):
@ -842,6 +840,7 @@ def search_missing_subtitles(no):
redirect(ref)
@route(base_url + 'search_missing_subtitles_movie/<no:int>', method='GET')
@custom_auth_basic(check_credentials)
def search_missing_subtitles_movie(no):
@ -852,17 +851,19 @@ def search_missing_subtitles_movie(no):
redirect(ref)
@route(base_url + 'history')
@custom_auth_basic(check_credentials)
def history():
authorize()
return template('history', bazarr_version=bazarr_version, base_url=base_url, current_port=port)
return template('history', bazarr_version=bazarr_version, base_url=base_url, current_port=settings.general.port)
@route(base_url + 'historyseries')
@custom_auth_basic(check_credentials)
def historyseries():
authorize()
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
c.execute("SELECT COUNT(*) FROM table_history")
@ -871,7 +872,7 @@ def historyseries():
page = request.GET.page
if page == "":
page = "1"
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
offset = (int(page) - 1) * page_size
max_page = int(math.ceil(row_count / (page_size + 0.0)))
@ -894,13 +895,14 @@ def historyseries():
data = c.fetchall()
c.close()
data = reversed(sorted(data, key=operator.itemgetter(4)))
return template('historyseries', bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size, current_port=port)
return template('historyseries', bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size, current_port=settings.general.port)
@route(base_url + 'historymovies')
@custom_auth_basic(check_credentials)
def historymovies():
authorize()
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
c.execute("SELECT COUNT(*) FROM table_history_movie")
@ -909,7 +911,7 @@ def historymovies():
page = request.GET.page
if page == "":
page = "1"
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
offset = (int(page) - 1) * page_size
max_page = int(math.ceil(row_count / (page_size + 0.0)))
@ -932,23 +934,25 @@ def historymovies():
data = c.fetchall()
c.close()
data = reversed(sorted(data, key=operator.itemgetter(2)))
return template('historymovies', bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size, current_port=port)
return template('historymovies', bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size, current_port=settings.general.port)
@route(base_url + 'wanted')
@custom_auth_basic(check_credentials)
def wanted():
authorize()
return template('wanted', bazarr_version=bazarr_version, base_url=base_url, current_port=port)
return template('wanted', bazarr_version=bazarr_version, base_url=base_url, current_port=settings.general.port)
@route(base_url + 'wantedseries')
@custom_auth_basic(check_credentials)
def wantedseries():
authorize()
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace)
c = db.cursor()
if get_general_settings()[24] is True:
if settings.general.only_monitored is True:
monitored_only_query_string = ' AND monitored = "True"'
else:
monitored_only_query_string = ""
@ -959,24 +963,25 @@ def wantedseries():
page = request.GET.page
if page == "":
page = "1"
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
offset = (int(page) - 1) * page_size
max_page = int(math.ceil(missing_count / (page_size + 0.0)))
c.execute("SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, path_substitution(table_episodes.path), table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, table_episodes.scene_name, table_episodes.failedAttempts FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != '[]'" + monitored_only_query_string + " ORDER BY table_episodes._rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,))
data = c.fetchall()
c.close()
return template('wantedseries', bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size, current_port=port)
return template('wantedseries', bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size, current_port=settings.general.port)
@route(base_url + 'wantedmovies')
@custom_auth_basic(check_credentials)
def wantedmovies():
authorize()
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
db.create_function("path_substitution", 1, path_replace_movie)
c = db.cursor()
if get_general_settings()[24] is True:
if settings.general.only_monitored is True:
monitored_only_query_string = ' AND monitored = "True"'
else:
monitored_only_query_string = ""
@ -987,14 +992,15 @@ def wantedmovies():
page = request.GET.page
if page == "":
page = "1"
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
offset = (int(page) - 1) * page_size
max_page = int(math.ceil(missing_count / (page_size + 0.0)))
c.execute("SELECT title, missing_subtitles, radarrId, path_substitution(path), hearing_impaired, sceneName, failedAttempts FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string + " ORDER BY _rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,))
data = c.fetchall()
c.close()
return template('wantedmovies', bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size, current_port=port)
return template('wantedmovies', bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size, current_port=settings.general.port)
@route(base_url + 'wanted_search_missing_subtitles')
@custom_auth_basic(check_credentials)
@ -1006,11 +1012,12 @@ def wanted_search_missing_subtitles_list():
redirect(ref)
@route(base_url + 'settings')
@custom_auth_basic(check_credentials)
def settings():
def _settings():
authorize()
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
c.execute("SELECT * FROM table_settings_languages ORDER BY name")
settings_languages = c.fetchall()
@ -1020,14 +1027,9 @@ def settings():
settings_notifier = c.fetchall()
c.close()
from get_settings import get_general_settings, get_proxy_settings, get_auth_settings, get_radarr_settings, get_sonarr_settings
settings_general = get_general_settings()
settings_proxy = get_proxy_settings()
settings_auth = get_auth_settings()
settings_sonarr = get_sonarr_settings()
settings_radarr = get_radarr_settings()
return template('settings', bazarr_version=bazarr_version, settings_general=settings_general, settings_proxy=settings_proxy, settings_auth=settings_auth, settings_languages=settings_languages, settings_providers=settings_providers, settings_sonarr=settings_sonarr, settings_radarr=settings_radarr, settings_notifier=settings_notifier, base_url=base_url, current_port=port)
return template('settings', bazarr_version=bazarr_version, settings=settings, settings_languages=settings_languages, settings_providers=settings_providers, settings_notifier=settings_notifier, base_url=base_url, current_port=settings.general.port)
@route(base_url + 'save_settings', method='POST')
@custom_auth_basic(check_credentials)
@ -1035,7 +1037,7 @@ def save_settings():
authorize()
ref = request.environ['HTTP_REFERER']
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
settings_general_ip = request.forms.get('settings_general_ip')
@ -1107,9 +1109,7 @@ def save_settings():
settings_general_use_radarr = 'True'
settings_page_size = request.forms.get('settings_page_size')
settings_general = get_general_settings()
before = (unicode(settings_general[0]), int(settings_general[1]), unicode(settings_general[2]), unicode(settings_general[3]), unicode(settings_general[12]), unicode(settings_general[13]), unicode(settings_general[14]))
before = (unicode(settings.general.ip), int(settings.general.port), unicode(settings.general.base_url), unicode(settings.general.path_mappings), unicode(settings.general.use_sonarr), unicode(settings.general.use_radarr), unicode(settings.general.path_mappings_movie))
after = (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr), unicode(settings_general_pathmapping_movie))
from six import text_type
@ -1141,9 +1141,6 @@ def save_settings():
if after != before:
configured()
get_general_settings()
settings_proxy = get_proxy_settings()
if not cfg.has_section('proxy'):
cfg.add_section('proxy')
@ -1155,7 +1152,7 @@ def save_settings():
settings_proxy_password = request.forms.get('settings_proxy_password')
settings_proxy_exclude = request.forms.get('settings_proxy_exclude')
before_proxy_password = (unicode(settings_proxy[0]), unicode(settings_proxy[5]))
before_proxy_password = (unicode(settings.proxy.type), unicode(settings.proxy.exclude))
if before_proxy_password[0] != settings_proxy_type:
configured()
if before_proxy_password[1] == settings_proxy_password:
@ -1172,15 +1169,13 @@ def save_settings():
cfg.set('proxy', 'password', text_type(settings_proxy_password))
cfg.set('proxy', 'exclude', text_type(settings_proxy_exclude))
settings_auth = get_auth_settings()
settings_auth_type = request.forms.get('settings_auth_type')
settings_auth_username = request.forms.get('settings_auth_username')
settings_auth_password = request.forms.get('settings_auth_password')
if get_auth_settings()[0] != settings_auth_type:
if settings.auth.type != settings_auth_type:
configured()
if settings_auth[2] == settings_auth_password:
if settings.auth.password == settings_auth_password:
cfg.set('auth', 'type', text_type(settings_auth_type))
cfg.set('auth', 'username', text_type(settings_auth_username))
else:
@ -1204,7 +1199,7 @@ def save_settings():
else:
aaa._beaker_session.delete()
else:
if settings_auth[2] != settings_auth_password:
if settings.auth.password != settings_auth_password:
aaa.user(settings_auth_username).update(role='', pwd=settings_auth_password)
if settings_auth_type == 'basic' or settings_auth_type == 'None':
pass
@ -1308,7 +1303,7 @@ def save_settings():
with open(config_file, 'wb') as f:
cfg.write(f)
configure_logging(get_general_settings()[4])
configure_logging(settings.general.debug)
notifiers = c.execute("SELECT * FROM table_settings_notifier ORDER BY name").fetchall()
for notifier in notifiers:
@ -1334,6 +1329,7 @@ def save_settings():
redirect(ref)
@route(base_url + 'check_update')
@custom_auth_basic(check_credentials)
def check_update():
@ -1345,10 +1341,12 @@ def check_update():
redirect(ref)
@route(base_url + 'system')
@custom_auth_basic(check_credentials)
def system():
authorize()
def get_time_from_interval(interval):
interval_clean = interval.split('[')
interval_clean = interval_clean[1][:-1]
@ -1390,6 +1388,7 @@ def system():
return text
def get_time_from_cron(cron):
text = "at "
hour = str(cron[5])
@ -1427,7 +1426,6 @@ def system():
return text
task_list = []
for job in scheduler.get_jobs():
if job.next_run_time is not None:
@ -1445,16 +1443,15 @@ def system():
for i, l in enumerate(f, 1):
pass
row_count = i
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
max_page = int(math.ceil(row_count / (page_size + 0.0)))
with open(os.path.join(config_dir, 'config', 'releases.txt'), 'r') as f:
releases = ast.literal_eval(f.read())
import platform
use_sonarr = get_general_settings()[12]
url_sonarr = get_sonarr_settings()[6]
apikey_sonarr = get_sonarr_settings()[4]
use_sonarr = settings.general.use_sonarr
apikey_sonarr = settings.sonarr.apikey
sv = url_sonarr + "/api/system/status?apikey=" + apikey_sonarr
sonarr_version = ''
if use_sonarr:
@ -1463,9 +1460,8 @@ def system():
except:
pass
use_radarr = get_general_settings()[13]
url_radarr = get_radarr_settings()[6]
apikey_radarr = get_radarr_settings()[4]
use_radarr = settings.general.use_radarr
apikey_radarr = settings.radarr.apikey
rv = url_radarr + "/api/system/status?apikey=" + apikey_radarr
radarr_version = ''
if use_radarr:
@ -1480,14 +1476,14 @@ def system():
operating_system=platform.platform(), python_version=platform.python_version(),
config_dir=config_dir, bazarr_dir=os.path.normcase(os.getcwd()),
base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, page_size=page_size,
releases=releases, current_port=port)
releases=releases, current_port=settings.general.port)
@route(base_url + 'logs/<page:int>')
@custom_auth_basic(check_credentials)
def get_logs(page):
authorize()
page_size = int(get_general_settings()[21])
page_size = int(settings.general.page_size)
begin = (page * page_size) - page_size
end = (page * page_size) - 1
logs_complete = []
@ -1495,7 +1491,8 @@ def get_logs(page):
logs_complete.append(line.rstrip())
logs = logs_complete[begin:end]
return template('logs', logs=logs, base_url=base_url, current_port=port)
return template('logs', logs=logs, base_url=base_url, current_port=settings.general.port)
@route(base_url + 'execute/<taskid>')
@custom_auth_basic(check_credentials)
@ -1575,6 +1572,7 @@ def get_subtitle():
except OSError:
pass
@route(base_url + 'manual_search', method='POST')
@custom_auth_basic(check_credentials)
def manual_search_json():
@ -1592,6 +1590,7 @@ def manual_search_json():
data = manual_search(episodePath, language, hi, providers_list, providers_auth, sceneName, 'series')
return dict(data=data)
@route(base_url + 'manual_get_subtitle', method='POST')
@custom_auth_basic(check_credentials)
def manual_get_subtitle():
@ -1621,6 +1620,7 @@ def manual_get_subtitle():
except OSError:
pass
@route(base_url + 'get_subtitle_movie', method='POST')
@custom_auth_basic(check_credentials)
def get_subtitle_movie():
@ -1648,6 +1648,7 @@ def get_subtitle_movie():
except OSError:
pass
@route(base_url + 'manual_search_movie', method='POST')
@custom_auth_basic(check_credentials)
def manual_search_movie_json():
@ -1665,6 +1666,7 @@ def manual_search_movie_json():
data = manual_search(moviePath, language, hi, providers_list, providers_auth, sceneName, 'movie')
return dict(data=data)
@route(base_url + 'manual_get_subtitle_movie', method='POST')
@custom_auth_basic(check_credentials)
def manual_get_subtitle_movie():
@ -1693,45 +1695,51 @@ def manual_get_subtitle_movie():
except OSError:
pass
def configured():
conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = conn.cursor()
c.execute("UPDATE system SET configured = 1")
conn.commit()
c.close()
@route(base_url + 'api/series/wanted')
def api_wanted():
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
data = c.execute("SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != '[]' ORDER BY table_episodes._rowid_ DESC").fetchall()
c.close()
return dict(subtitles=data)
@route(base_url + 'api/series/history')
def api_history():
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
data = c.execute("SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, strftime('%Y-%m-%d', datetime(table_history.timestamp, 'unixepoch')), table_history.description FROM table_history INNER JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId INNER JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId WHERE table_history.action = '1' ORDER BY id DESC").fetchall()
c.close()
return dict(subtitles=data)
@route(base_url + 'api/movies/wanted')
def api_wanted():
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
data = c.execute("SELECT table_movies.title, table_movies.missing_subtitles FROM table_movies WHERE table_movies.missing_subtitles != '[]' ORDER BY table_movies._rowid_ DESC").fetchall()
c.close()
return dict(subtitles=data)
@route(base_url + 'api/movies/history')
def api_history():
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
data = c.execute("SELECT table_movies.title, strftime('%Y-%m-%d', datetime(table_history_movie.timestamp, 'unixepoch')), table_history_movie.description FROM table_history_movie INNER JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId WHERE table_history_movie.action = '1' ORDER BY id DESC").fetchall()
c.close()
return dict(subtitles=data)
@route(base_url + 'test_url/<protocol>/<url:path>', method='GET')
@custom_auth_basic(check_credentials)
def test_url(protocol, url):
@ -1761,9 +1769,9 @@ import warnings
# Mute DeprecationWarning
warnings.simplefilter("ignore", DeprecationWarning)
server = CherryPyWSGIServer((str(ip), int(port)), app)
server = CherryPyWSGIServer((str(settings.general.ip), int(settings.general.port)), app)
try:
logging.info('BAZARR is started and waiting for request on http://' + str(ip) + ':' + str(port) + str(base_url))
logging.info('BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + str(settings.general.port) + str(base_url))
# print 'Bazarr is started and waiting for request on http://' + str(ip) + ':' + str(port) + str(base_url)
server.start()
except KeyboardInterrupt:

@ -1,10 +1,11 @@
from get_argv import config_dir
# coding=utf-8
import apprise
import os
import sqlite3
import logging
from get_argv import config_dir
def update_notifier():
# define apprise object
@ -16,7 +17,7 @@ def update_notifier():
notifiers_new = []
notifiers_old = []
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
notifiers_current = c_db.execute('SELECT name FROM table_settings_notifier').fetchall()
for x in results['schemas']:
@ -40,37 +41,41 @@ def update_notifier():
def get_notifier_providers():
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
providers = c_db.execute('SELECT name, url FROM table_settings_notifier WHERE enabled = 1').fetchall()
c_db.close()
return providers
def get_series_name(sonarrSeriesId):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
data = c_db.execute('SELECT title FROM table_shows WHERE sonarrSeriesId = ?', (sonarrSeriesId,)).fetchone()
c_db.close()
return data[0]
def get_episode_name(sonarrEpisodeId):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
data = c_db.execute('SELECT title, season, episode FROM table_episodes WHERE sonarrEpisodeId = ?', (sonarrEpisodeId,)).fetchone()
c_db.close()
return data[0], data[1], data[2]
def get_movies_name(radarrId):
conn_db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
conn_db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c_db = conn_db.cursor()
data = c_db.execute('SELECT title FROM table_movies WHERE radarrId = ?', (radarrId,)).fetchone()
c_db.close()
return data[0]
def send_notifications(sonarrSeriesId, sonarrEpisodeId, message):
providers = get_notifier_providers()
series = get_series_name(sonarrSeriesId)
@ -101,4 +106,5 @@ def send_notifications_movie(radarrId, message):
apobj.notify(
title='Bazarr notification',
body=movie + ' : ' + message,
)
)

@ -1,11 +1,10 @@
from get_argv import no_update
from get_settings import get_general_settings, automatic, get_radarr_settings, get_sonarr_settings
from get_series import update_series
from get_episodes import update_all_episodes, update_all_movies, sync_episodes
from get_episodes import sync_episodes, update_all_episodes, update_all_movies
from get_movies import update_movies
from list_subtitles import store_subtitles
from get_series import update_series
from config import settings
from get_subtitle import wanted_search_missing_subtitles
if no_update is False:
from check_update import check_and_apply_update, check_releases
else:
@ -18,12 +17,10 @@ from datetime import datetime
import pytz
from tzlocal import get_localzone
integration = get_general_settings()
def sonarr_full_update():
if integration[12] is True:
full_update = get_sonarr_settings()[5]
if settings.general.use_sonarr:
full_update = settings.sonarr.full_update
if full_update == "Daily":
scheduler.add_job(update_all_episodes, CronTrigger(hour=4), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_all_episodes',
@ -39,8 +36,8 @@ def sonarr_full_update():
def radarr_full_update():
if integration[13] is True:
full_update = get_radarr_settings()[5]
if settings.general.use_radarr:
full_update = settings.radarr.full_update
if full_update == "Daily":
scheduler.add_job(update_all_movies, CronTrigger(hour=5), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_all_movies', name='Update all movies subtitles from disk', replace_existing=True)
@ -64,7 +61,7 @@ else:
scheduler = BackgroundScheduler()
if no_update is False:
if automatic is True:
if settings.sonarr.auto_update:
scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_bazarr', name='Update bazarr from source on Github')
else:
scheduler.add_job(check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr', name='Update bazarr from source on Github')
@ -73,19 +70,21 @@ else:
scheduler.add_job(check_releases, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_release', name='Update release info')
if integration[12] is True:
if settings.general.use_sonarr:
scheduler.add_job(update_series, IntervalTrigger(minutes=1), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_series', name='Update series list from Sonarr')
scheduler.add_job(sync_episodes, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr')
if integration[13] is True:
if settings.general.use_radarr:
scheduler.add_job(update_movies, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_movies', name='Update movies list from Radarr')
if integration[12] is True or integration[13] is True:
if settings.general.use_sonarr or settings.general.use_radarr:
scheduler.add_job(wanted_search_missing_subtitles, IntervalTrigger(hours=3), max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
sonarr_full_update()
radarr_full_update()
scheduler.start()
def shutdown_scheduler():
scheduler.shutdown(wait=True)
scheduler.shutdown(wait=True)

@ -1,12 +1,15 @@
from get_argv import config_dir
# coding=utf-8
import os
import sqlite3
from get_argv import config_dir
from scheduler import execute_now
from config import settings
# Check if database exist
if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
if os.path.exists(os.path.join(config_dir, 'db', 'bazarr.db')):
# Open database connection
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
# Execute tables modifications
@ -70,13 +73,9 @@ if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
except:
pass
else:
from scheduler import execute_now
from get_settings import get_general_settings
integration = get_general_settings()
if integration[12] is True:
if settings.general.use_sonarr:
execute_now('sync_episodes')
if integration[13] is True:
if settings.general.use_radarr:
execute_now('update_movies')
try:
@ -85,11 +84,7 @@ if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
except:
pass
else:
from scheduler import execute_now
from get_settings import get_general_settings
integration = get_general_settings()
if integration[12] is True:
if settings.general.use_sonarr:
execute_now('sync_episodes')
try:
@ -98,11 +93,8 @@ if os.path.exists(os.path.join(config_dir, 'db/bazarr.db')) == True:
except:
pass
else:
from scheduler import execute_now
from get_settings import get_general_settings
integration = get_general_settings()
if integration[13] is True:
if settings.general.use_radarr:
execute_now('update_movies')
db.close()
db.close()

@ -1,12 +1,14 @@
from get_argv import config_dir
# coding=utf-8
import os
import sqlite3
import time
from get_argv import config_dir
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
# Open database connection
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
# Get Sonarr API URL from database config table
@ -21,7 +23,7 @@ def history_log(action, sonarrSeriesId, sonarrEpisodeId, description):
def history_log_movie(action, radarrId, description):
# Open database connection
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
db = sqlite3.connect(os.path.join(config_dir, 'db', 'bazarr.db'), timeout=30)
c = db.cursor()
history = c.execute('''INSERT INTO table_history_movie(action, radarrId, timestamp, description) VALUES (?, ?, ?, ?)''', (action, radarrId, time.time(), description))

@ -220,9 +220,9 @@
end
if missing_languages is not None:
from get_subtitle import search_active
from get_settings import get_general_settings
from config import settings
for language in missing_languages:
if episode[10] is not None and get_general_settings()[25] and language in episode[10]:
if episode[10] is not None and settings.general.adaptive_searching and language in episode[10]:
for lang in ast.literal_eval(episode[10]):
if language in lang:
if search_active(lang[1]):

@ -47,14 +47,12 @@
</div>
% include('menu.tpl')
% from get_argv import config_dir
% import os
% from get_settings import get_general_settings
% from config import settings
<div id="fondblanc" class="ui container">
<div class="ui top attached tabular menu">
<a id="series_tab" class="tabs item active" data-enabled="{{get_general_settings()[12]}}" data-tab="series">Series</a>
<a id="movies_tab" class="tabs item" data-enabled="{{get_general_settings()[13]}}" data-tab="movies">Movies</a>
<a id="series_tab" class="tabs item active" data-enabled="{{settings.general.use_sonarr}}" data-tab="series">Series</a>
<a id="movies_tab" class="tabs item" data-enabled="{{settings.general.use_radarr}}" data-tab="movies">Movies</a>
</div>
<div class="ui bottom attached tab segment" data-tab="series">
<div class="content">

@ -24,9 +24,9 @@
% import os
% import sqlite3
% from get_settings import get_general_settings
% from config import settings
%if get_general_settings()[24]:
%if settings.general.only_monitored:
% monitored_only_query_string = ' AND monitored = "True"'
%else:
% monitored_only_query_string = ""
@ -50,13 +50,13 @@
<div class="sixteen wide column">
<div class="ui inverted borderless labeled icon massive menu six item">
<div class="ui container">
% if get_general_settings()[12]:
% if settings.general.use_sonarr:
<a class="item" href="{{base_url}}series">
<i class="play icon"></i>
Series
</a>
% end
% if get_general_settings()[13]:
% if settings.general.use_radarr:
<a class="item" href="{{base_url}}movies">
<i class="film icon"></i>
Movies
@ -68,12 +68,12 @@
</a>
<a class="item" href="{{base_url}}wanted">
<i class="warning sign icon">
% if get_general_settings()[12]:
% if settings.general.use_sonarr:
<div class="floating ui tiny yellow label" style="left:90% !important;top:0.5em !important;">
{{wanted_series[0]}}
</div>
% end
% if get_general_settings()[13]:
% if settings.general.use_radarr:
<div class="floating ui tiny green label" style="left:90% !important;top:3em !important;">
{{wanted_movies[0]}}
</div>
@ -179,10 +179,10 @@
});
});
% from get_settings import get_general_settings
% ip = get_general_settings()[0]
% port = get_general_settings()[1]
% base_url = get_general_settings()[2]
% from config import settings
% ip = settings.general.ip
% port = settings.general.port
% base_url = settings.general.base_url
if ("{{ip}}" === "0.0.0.0") {
public_ip = window.location.hostname;

@ -80,8 +80,8 @@
<body>
%import ast
%from get_languages import *
%from get_settings import *
%single_language = get_general_settings()[7]
%from config import settings
%single_language = settings.general.single_language
<div style="display: none;"><img src="{{base_url}}image_proxy_movies{{details[3]}}"></div>
<div id='loader' class="ui page dimmer">
<div id="loader_text" class="ui indeterminate text loader">Loading...</div>
@ -187,7 +187,7 @@
</table>
<%
for missing_subs_language in missing_subs_languages:
if details[14] is not None and get_general_settings()[25] and missing_subs_language in details[14]:
if details[14] is not None and settings.general.adaptive_searching and missing_subs_language in details[14]:
for lang in ast.literal_eval(details[14]):
if missing_subs_language in lang:
if search_active(lang[1]):
@ -513,5 +513,5 @@
$(document).ajaxStop(function(){
window.location.reload();
});
};
}
</script>

@ -68,7 +68,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_general_ip" type="text" value="{{settings_general[0]}}">
<input name="settings_general_ip" type="text" value="{{settings.general.ip}}">
</div>
</div>
</div>
@ -92,7 +92,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_general_port" type="text" value="{{settings_general[1]}}">
<input name="settings_general_port" type="text" value="{{settings.general.port}}">
</div>
</div>
</div>
@ -115,10 +115,10 @@
</div>
<div class="five wide column">
<div class="ui fluid input">
%if settings_general[2] is None:
%if settings.general.base_url is None:
% base_url = "/"
%else:
% base_url = settings_general[2]
% base_url = settings.general.base_url
%end
<input name="settings_general_baseurl" type="text" value="{{base_url}}">
</div>
@ -141,7 +141,7 @@
<label>Enable debug logging</label>
</div>
<div class="five wide column">
<div id="settings_debug" class="ui toggle checkbox" data-debug={{settings_general[4]}}>
<div id="settings_debug" class="ui toggle checkbox" data-debug={{settings.general.debug}}>
<input name="settings_general_debug" type="checkbox">
<label></label>
</div>
@ -216,7 +216,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_proxy_url" name="settings_proxy_url" type="text" value="{{settings_proxy[1]}}">
<input id="settings_proxy_url" name="settings_proxy_url" type="text" value="{{settings.proxy.url}}">
</div>
</div>
</div>
@ -229,7 +229,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_proxy_port" name="settings_proxy_port" type="text" value="{{settings_proxy[2]}}">
<input id="settings_proxy_port" name="settings_proxy_port" type="text" value="{{settings.proxy.port}}">
</div>
</div>
</div>
@ -242,7 +242,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_proxy_username" name="settings_proxy_username" type="text" value="{{settings_proxy[3]}}">
<input id="settings_proxy_username" name="settings_proxy_username" type="text" value="{{settings.proxy.username}}">
</div>
</div>
</div>
@ -261,7 +261,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_proxy_password" name="settings_proxy_password" type="password" value="{{settings_proxy[4]}}">
<input id="settings_proxy_password" name="settings_proxy_password" type="password" value="{{settings.proxy.password}}">
</div>
</div>
</div>
@ -281,7 +281,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_proxy_exclude" name="settings_proxy_exclude" type="text" value="{{settings_proxy[5]}}">
<input id="settings_proxy_exclude" name="settings_proxy_exclude" type="text" value="{{settings.proxy.exclude}}">
</div>
</div>
</div>
@ -335,7 +335,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_auth_username" name="settings_auth_username" type="text" autocomplete="nope" value="{{settings_auth[1]}}">
<input id="settings_auth_username" name="settings_auth_username" type="text" autocomplete="nope" value="{{settings.auth.username}}">
</div>
</div>
</div>
@ -348,7 +348,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_auth_password" name="settings_auth_password" type="password" autocomplete="new-password" value="{{settings_auth[2]}}">
<input id="settings_auth_password" name="settings_auth_password" type="password" autocomplete="new-password" value="{{settings.auth.password}}">
</div>
</div>
</div>
@ -372,7 +372,7 @@
<label>Use Sonarr</label>
</div>
<div class="one wide column">
<div id="settings_use_sonarr" class="ui toggle checkbox" data-enabled={{settings_general[12]}}>
<div id="settings_use_sonarr" class="ui toggle checkbox" data-enabled={{settings.general.use_sonarr}}>
<input name="settings_general_use_sonarr" type="checkbox">
<label></label>
</div>
@ -391,7 +391,7 @@
<label>Use Radarr</label>
</div>
<div class="one wide column">
<div id="settings_use_radarr" class="ui toggle checkbox" data-enabled={{settings_general[13]}}>
<div id="settings_use_radarr" class="ui toggle checkbox" data-enabled={{settings.general.use_radarr}}>
<input name="settings_general_use_radarr" type="checkbox">
<label></label>
</div>
@ -411,8 +411,8 @@
<div class="twelve wide column">
<div class="ui grid">
%import ast
%if settings_general[3] is not None:
% path_substitutions = ast.literal_eval(settings_general[3])
%if settings.general.path_mappings is not None:
% path_substitutions = ast.literal_eval(settings.general.path_mappings)
%else:
% path_substitutions = []
%end
@ -485,8 +485,8 @@
<div class="twelve wide column">
<div class="ui grid">
%import ast
%if settings_general[14] is not None:
% path_substitutions_movie = ast.literal_eval(settings_general[14])
%if settings.general.path_mappings_movie is not None:
% path_substitutions_movie = ast.literal_eval(settings.general.path_mappings_movie)
%else:
% path_substitutions_movie = []
%end
@ -566,7 +566,7 @@
<label>Use post-processing</label>
</div>
<div class="one wide column">
<div id="settings_use_postprocessing" class="ui toggle checkbox" data-postprocessing={{settings_general[10]}}>
<div id="settings_use_postprocessing" class="ui toggle checkbox" data-postprocessing={{settings.general.use_postprocessing}}>
<input name="settings_general_use_postprocessing" type="checkbox">
<label></label>
</div>
@ -586,7 +586,7 @@
</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[11] if settings_general[11] != None else ''}}">
<input name="settings_general_postprocessing_cmd" type="text" value="{{settings.general.postprocessing_cmd if settings.general.postprocessing_cmd != None else ''}}">
</div>
</div>
</div>
@ -660,7 +660,7 @@
<label>Automatic</label>
</div>
<div class="one wide column">
<div id="settings_automatic_div" class="ui toggle checkbox" data-automatic={{settings_general[6]}}>
<div id="settings_automatic_div" class="ui toggle checkbox" data-automatic={{settings.general.auto_update}}>
<input name="settings_general_automatic" type="checkbox">
<label></label>
</div>
@ -706,7 +706,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_sonarr_ip" name="settings_sonarr_ip" class="sonarr_config" type="text" value="{{settings_sonarr[0]}}">
<input id="settings_sonarr_ip" name="settings_sonarr_ip" class="sonarr_config" type="text" value="{{settings.sonarr.ip}}">
</div>
</div>
</div>
@ -724,7 +724,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_sonarr_port" name="settings_sonarr_port" class="sonarr_config" type="text" value="{{settings_sonarr[1]}}">
<input id="settings_sonarr_port" name="settings_sonarr_port" class="sonarr_config" type="text" value="{{settings.sonarr.port}}">
</div>
</div>
</div>
@ -741,7 +741,7 @@
</div>
<div class="five wide column">
<div class="ui fluid input">
<input id="settings_sonarr_baseurl" name="settings_sonarr_baseurl" class="sonarr_config" type="text" value="{{settings_sonarr[2]}}">
<input id="settings_sonarr_baseurl" name="settings_sonarr_baseurl" class="sonarr_config" type="text" value="{{settings.sonarr.base_url}}">
</div>
</div>
<div class="collapsed center aligned column">
@ -756,7 +756,7 @@
<label>SSL enabled</label>
</div>
<div class="one wide column">
<div id="sonarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings_sonarr[3]}}>
<div id="sonarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings.sonarr.ssl}}>
<input id="settings_sonarr_ssl" name="settings_sonarr_ssl" type="checkbox">
<label></label>
</div>
@ -770,7 +770,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_sonarr_apikey" name="settings_sonarr_apikey" class="sonarr_config" type="text" value="{{settings_sonarr[4]}}">
<input id="settings_sonarr_apikey" name="settings_sonarr_apikey" class="sonarr_config" type="text" value="{{settings.sonarr.apikey}}">
</div>
</div>
</div>
@ -832,7 +832,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_radarr_ip" name="settings_radarr_ip" type="text" class="radarr_config" value="{{settings_radarr[0]}}">
<input id="settings_radarr_ip" name="settings_radarr_ip" type="text" class="radarr_config" value="{{settings.radarr.ip}}">
</div>
</div>
</div>
@ -850,7 +850,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_radarr_port" name="settings_radarr_port" type="text" class="radarr_config" value="{{settings_radarr[1]}}">
<input id="settings_radarr_port" name="settings_radarr_port" type="text" class="radarr_config" value="{{settings.radarr.port}}">
</div>
</div>
</div>
@ -867,7 +867,7 @@
</div>
<div class="five wide column">
<div class="ui fluid input">
<input id="settings_radarr_baseurl" name="settings_radarr_baseurl" type="text" class="radarr_config" value="{{settings_radarr[2]}}">
<input id="settings_radarr_baseurl" name="settings_radarr_baseurl" type="text" class="radarr_config" value="{{settings.radarr.base_url}}">
</div>
</div>
<div class="collapsed center aligned column">
@ -882,7 +882,7 @@
<label>SSL enabled</label>
</div>
<div class="one wide column">
<div id="radarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings_radarr[3]}}>
<div id="radarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings.radarr.ssl}}>
<input id="settings_radarr_ssl" name="settings_radarr_ssl" type="checkbox">
<label></label>
</div>
@ -896,7 +896,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input id="settings_radarr_apikey" name="settings_radarr_apikey" type="text" class="radarr_config" value="{{settings_radarr[4]}}">
<input id="settings_radarr_apikey" name="settings_radarr_apikey" type="text" class="radarr_config" value="{{settings.radarr.apikey}}">
</div>
</div>
</div>
@ -945,7 +945,7 @@
<label>Use scene name when available</label>
</div>
<div class="one wide column">
<div id="settings_scenename" class="ui toggle checkbox" data-scenename={{settings_general[9]}}>
<div id="settings_scenename" class="ui toggle checkbox" data-scenename={{settings.general.use_scenename}}>
<input name="settings_general_scenename" type="checkbox">
<label></label>
</div>
@ -966,7 +966,7 @@
<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[8]}}">
<input name="settings_general_minimum_score" type="number" min="0" max="100" step="5" onkeydown="return false" value="{{settings.general.minimum_score}}">
</div>
</div>
</div>
@ -986,7 +986,7 @@
<div class="two wide column">
<div class='field'>
<div class="ui input">
<input name="settings_general_minimum_score_movies" type="number" min="0" max="100" step="5" onkeydown="return false" value="{{settings_general[22]}}">
<input name="settings_general_minimum_score_movies" type="number" min="0" max="100" step="5" onkeydown="return false" value="{{settings.general.minimum_score_movie}}">
</div>
</div>
</div>
@ -1004,7 +1004,7 @@
<label>Use embedded subtitles</label>
</div>
<div class="one wide column">
<div id="settings_embedded" class="ui toggle checkbox" data-embedded={{settings_general[23]}}>
<div id="settings_embedded" class="ui toggle checkbox" data-embedded={{settings.general.use_embedded_subs}}>
<input name="settings_general_embedded" type="checkbox">
<label></label>
</div>
@ -1023,7 +1023,7 @@
<label>Download only monitored</label>
</div>
<div class="one wide column">
<div id="settings_only_monitored" class="ui toggle checkbox" data-monitored={{settings_general[24]}}>
<div id="settings_only_monitored" class="ui toggle checkbox" data-monitored={{settings.general.only_monitored}}>
<input name="settings_general_only_monitored" type="checkbox">
<label></label>
</div>
@ -1042,7 +1042,7 @@
<label>Adaptive searching</label>
</div>
<div class="one wide column">
<div id="settings_adaptive_searching" class="ui toggle checkbox" data-adaptive={{settings_general[25]}}>
<div id="settings_adaptive_searching" class="ui toggle checkbox" data-adaptive={{settings.general.adaptive_searching}}>
<input name="settings_general_adaptive_searching" type="checkbox">
<label></label>
</div>
@ -1172,7 +1172,7 @@
<label>Single language</label>
</div>
<div class="one wide column">
<div id="settings_single_language" class="ui toggle checkbox" data-single-language={{settings_general[7]}}>
<div id="settings_single_language" class="ui toggle checkbox" data-single-language={{settings.general.single_language}}>
<input name="settings_general_single_language" type="checkbox">
<label></label>
</div>
@ -1217,7 +1217,7 @@
</div>
<div class="one wide column">
<div class="nine wide column">
<div id="settings_serie_default_enabled_div" class="ui toggle checkbox" data-enabled="{{settings_general[15]}}">
<div id="settings_serie_default_enabled_div" class="ui toggle checkbox" data-enabled="{{settings.general.serie_default_enabled}}">
<input name="settings_serie_default_enabled" id="settings_serie_default_enabled" type="checkbox">
<label></label>
</div>
@ -1239,7 +1239,7 @@
<div class="eleven wide column">
<div class='field'>
<select name="settings_serie_default_languages" id="settings_serie_default_languages" multiple="" class="ui fluid search selection dropdown">
%if settings_general[7] is False:
%if settings.general.single_language is False:
<option value="">Languages</option>
%else:
<option value="None">None</option>
@ -1255,7 +1255,7 @@
</div>
<div class="eleven wide column">
<div class="nine wide column">
<div id="settings_serie_default_hi_div" class="ui toggle checkbox" data-hi="{{settings_general[17]}}">
<div id="settings_serie_default_hi_div" class="ui toggle checkbox" data-hi="{{settings.general.serie_default_hi}}">
<input name="settings_serie_default_hi" id="settings_serie_default_hi" type="checkbox">
<label></label>
</div>
@ -1274,7 +1274,7 @@
</div>
<div class="one wide column">
<div class="nine wide column">
<div id="settings_movie_default_enabled_div" class="ui toggle checkbox" data-enabled="{{settings_general[18]}}">
<div id="settings_movie_default_enabled_div" class="ui toggle checkbox" data-enabled="{{settings.general.movie_default_enabled}}">
<input name="settings_movie_default_enabled" id="settings_movie_default_enabled" type="checkbox">
<label></label>
</div>
@ -1296,7 +1296,7 @@
<div class="eleven wide column">
<div class='field'>
<select name="settings_movie_default_languages" id="settings_movie_default_languages" multiple="" class="ui fluid search selection dropdown">
%if settings_general[7] is False:
%if settings.general.single_language is False:
<option value="">Languages</option>
%else:
<option value="None">None</option>
@ -1312,7 +1312,7 @@
</div>
<div class="eleven wide column">
<div class="nine wide column">
<div id="settings_movie_default_hi_div" class="ui toggle checkbox" data-hi="{{settings_general[20]}}">
<div id="settings_movie_default_hi_div" class="ui toggle checkbox" data-hi="{{settings.general.movie_default_hi}}">
<input name="settings_movie_default_hi" id="settings_movie_default_hi" type="checkbox">
<label></label>
</div>
@ -1520,7 +1520,7 @@
// Load default value for Settings_auth_type
$('#settings_auth_type').dropdown('clear');
$('#settings_auth_type').dropdown('set selected','{{!settings_auth[0]}}');
$('#settings_auth_type').dropdown('set selected','{{!settings.auth.type}}');
// Remove value from Password input when changing to Form login to prevent bad password saving
$("#settings_auth_type").on('change', function() {
@ -1528,7 +1528,7 @@
$('#settings_auth_password').val('');
}
else {
$('#settings_auth_password').val('{{settings_auth[2]}}');
$('#settings_auth_password').val('{{settings.auth.password}}');
}
});
@ -1665,32 +1665,32 @@
$('#settings_loglevel').dropdown('clear');
$('#settings_loglevel').dropdown('set selected','{{!settings_general[4]}}');
$('#settings_loglevel').dropdown('set selected','{{!settings.general.debug}}');
$('#settings_page_size').dropdown('clear');
$('#settings_page_size').dropdown('set selected','{{!settings_general[21]}}');
$('#settings_page_size').dropdown('set selected','{{!settings.general.page_size}}');
$('#settings_proxy_type').dropdown('clear');
$('#settings_proxy_type').dropdown('set selected','{{!settings_proxy[0]}}');
$('#settings_proxy_type').dropdown('set selected','{{!settings.proxy.type}}');
$('#settings_providers').dropdown('clear');
$('#settings_providers').dropdown('set selected',{{!enabled_providers}});
$('#settings_languages').dropdown('clear');
$('#settings_languages').dropdown('set selected',{{!enabled_languages}});
$('#settings_branch').dropdown('clear');
$('#settings_branch').dropdown('set selected','{{!settings_general[5]}}');
$('#settings_branch').dropdown('set selected','{{!settings.general.branch}}');
$('#settings_sonarr_sync').dropdown('clear');
$('#settings_sonarr_sync').dropdown('set selected','{{!settings_sonarr[5]}}');
$('#settings_sonarr_sync').dropdown('set selected','{{!settings.sonarr.full_update}}');
$('#settings_radarr_sync').dropdown('clear');
$('#settings_radarr_sync').dropdown('set selected','{{!settings_radarr[5]}}');
$('#settings_radarr_sync').dropdown('set selected','{{!settings.radarr.full_update}}');
$('#settings_loglevel').dropdown();
$('#settings_providers').dropdown();
$('#settings_languages').dropdown();
$('#settings_serie_default_languages').dropdown();
$('#settings_movie_default_languages').dropdown();
%if settings_general[16] is not None:
$('#settings_serie_default_languages').dropdown('set selected',{{!settings_general[16]}});
%if settings.general.serie_default_language is not None:
$('#settings_serie_default_languages').dropdown('set selected',{{!settings.general.serie_default_language}});
%end
%if settings_general[19] is not None:
$('#settings_movie_default_languages').dropdown('set selected',{{!settings_general[19]}});
%if settings.general.movie_default_language is not None:
$('#settings_movie_default_languages').dropdown('set selected',{{!settings.general.movie_default_language}});
%end
$('#settings_branch').dropdown();
$('#settings_sonarr_sync').dropdown();

@ -49,8 +49,8 @@
<div class="ui basic icon buttons" style="float: right;">
<div id="shutdown" class="ui icon button" data-tooltip="Shutdown" data-inverted=""><i class="red power off icon"></i></div>
<div id="restart" class="ui icon button" data-tooltip="Restart" data-inverted=""><i class="redo alternate icon"></i></div>
% from get_settings import get_auth_settings
% if get_auth_settings()[0] is not 'None':
% from config import settings
% if settings.auth.type is not 'None':
<div id="logout" class="ui icon button" data-tooltip="Logout" data-inverted=""><i class="sign-out icon"></i></div>
% end
</div>
@ -136,8 +136,7 @@
</div>
</div>
</div>
% from get_settings import get_general_settings
% if get_general_settings()[12]:
% if settings.general.use_sonarr:
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Sonarr version</label>
@ -151,7 +150,7 @@
</div>
</div>
% end
% if get_general_settings()[13]:
% if settings.general.use_radarr:
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Radarr version</label>
@ -385,10 +384,10 @@
})
});
% from get_settings import get_general_settings
% ip = get_general_settings()[0]
% port = get_general_settings()[1]
% base_url = get_general_settings()[2]
% from config import settings
% ip = settings.general.ip
% port = settings.general.port
% base_url = settings.general.base_url
if ("{{ip}}" === "0.0.0.0") {
public_ip = window.location.hostname;

@ -36,9 +36,9 @@
% import os
% import sqlite3
% from get_settings import get_general_settings
% from config import settings
%if get_general_settings()[24]:
%if settings.general.only_monitored:
% monitored_only_query_string = ' AND monitored = "True"'
%else:
% monitored_only_query_string = ""
@ -54,17 +54,15 @@
<div id="loader_text" class="ui indeterminate text loader">Loading...</div>
</div>
% include('menu.tpl')
% import os
<div id="fondblanc" class="ui container">
<div class="ui top attached tabular menu">
<a id="series_tab" class="tabs item active" data-enabled="{{get_general_settings()[12]}}" data-tab="series">Series
<a id="series_tab" class="tabs item active" data-enabled="{{settings.general.use_sonarr}}" data-tab="series">Series
<div class="ui tiny yellow label">
{{wanted_series[0]}}
</div>
</a>
<a id="movies_tab" class="tabs item" data-enabled="{{get_general_settings()[13]}}" data-tab="movies">Movies
<a id="movies_tab" class="tabs item" data-enabled="{{settings.general.use_radarr}}" data-tab="movies">Movies
<div class="ui tiny green label">
{{wanted_movies[0]}}
</div>

@ -65,9 +65,9 @@
missing_languages = ast.literal_eval(row[1])
if missing_languages is not None:
from get_subtitle import search_active
from get_settings import get_general_settings
from config import settings
for language in missing_languages:
if row[6] is not None and get_general_settings()[25] and language in row[6]:
if row[6] is not None and settings.general.adaptive_searching and language in row[6]:
for lang in ast.literal_eval(row[6]):
if language in lang:
active = search_active(lang[1])

@ -72,9 +72,9 @@
missing_languages = ast.literal_eval(row[3])
if missing_languages is not None:
from get_subtitle import search_active
from get_settings import get_general_settings
from config import settings
for language in missing_languages:
if row[9] is not None and get_general_settings()[25] and language in row[9]:
if row[9] is not None and settings.general.adaptive_searching and language in row[9]:
for lang in ast.literal_eval(row[9]):
if language in lang:
active = search_active(lang[1])

Loading…
Cancel
Save