2018-12-14 22:18:52 +00:00
|
|
|
# coding=utf-8
|
2021-01-19 04:49:51 +00:00
|
|
|
|
2020-03-26 19:37:17 +00:00
|
|
|
import hashlib
|
2018-12-14 22:18:52 +00:00
|
|
|
import os
|
|
|
|
|
2020-10-10 14:26:56 +00:00
|
|
|
from subliminal.cache import region
|
|
|
|
|
2018-12-27 19:19:59 +00:00
|
|
|
from simpleconfigparser import simpleconfigparser
|
2018-12-14 22:18:52 +00:00
|
|
|
|
2019-01-02 19:43:40 +00:00
|
|
|
from get_args import args
|
2018-12-14 22:18:52 +00:00
|
|
|
|
2018-12-27 19:19:59 +00:00
|
|
|
defaults = {
|
|
|
|
'general': {
|
|
|
|
'ip': '0.0.0.0',
|
|
|
|
'port': '6767',
|
2019-12-30 19:18:42 +00:00
|
|
|
'base_url': '',
|
2018-12-27 19:19:59 +00:00
|
|
|
'path_mappings': '[]',
|
|
|
|
'debug': 'False',
|
|
|
|
'branch': 'master',
|
|
|
|
'auto_update': 'True',
|
|
|
|
'single_language': 'False',
|
|
|
|
'minimum_score': '90',
|
|
|
|
'use_scenename': 'True',
|
|
|
|
'use_postprocessing': 'False',
|
|
|
|
'postprocessing_cmd': '',
|
2020-05-15 18:12:31 +00:00
|
|
|
'postprocessing_threshold': '90',
|
|
|
|
'use_postprocessing_threshold': 'False',
|
|
|
|
'postprocessing_threshold_movie': '70',
|
|
|
|
'use_postprocessing_threshold_movie': 'False',
|
2018-12-27 19:19:59 +00:00
|
|
|
'use_sonarr': 'False',
|
|
|
|
'use_radarr': 'False',
|
|
|
|
'path_mappings_movie': '[]',
|
|
|
|
'serie_default_enabled': 'False',
|
2021-01-19 04:49:51 +00:00
|
|
|
'serie_default_profile': '',
|
2018-12-27 19:19:59 +00:00
|
|
|
'movie_default_enabled': 'False',
|
2021-01-19 04:49:51 +00:00
|
|
|
'movie_default_profile': '',
|
2018-12-27 19:19:59 +00:00
|
|
|
'page_size': '25',
|
2020-05-20 15:29:49 +00:00
|
|
|
'page_size_manual_search': '10',
|
2018-12-27 19:19:59 +00:00
|
|
|
'minimum_score_movie': '70',
|
|
|
|
'use_embedded_subs': 'True',
|
2020-05-31 14:41:18 +00:00
|
|
|
'embedded_subs_show_desired': 'True',
|
2019-06-04 00:16:37 +00:00
|
|
|
'utf8_encode': 'True',
|
2019-05-07 00:26:16 +00:00
|
|
|
'ignore_pgs_subs': 'False',
|
2020-07-29 10:28:24 +00:00
|
|
|
'ignore_vobsub_subs': 'False',
|
2018-12-27 22:10:10 +00:00
|
|
|
'adaptive_searching': 'False',
|
2019-01-24 14:00:03 +00:00
|
|
|
'enabled_providers': '',
|
2019-03-22 21:08:13 +00:00
|
|
|
'throtteled_providers': '{}',
|
2019-01-24 14:00:03 +00:00
|
|
|
'multithreading': 'True',
|
2019-03-26 19:49:03 +00:00
|
|
|
'chmod_enabled': 'False',
|
2019-02-27 20:55:06 +00:00
|
|
|
'chmod': '0640',
|
2019-01-24 20:39:23 +00:00
|
|
|
'subfolder': 'current',
|
2019-03-15 18:28:57 +00:00
|
|
|
'subfolder_custom': '',
|
2019-03-26 20:07:55 +00:00
|
|
|
'update_restart': 'True',
|
2019-03-17 18:53:36 +00:00
|
|
|
'upgrade_subs': 'True',
|
2019-09-11 10:50:33 +00:00
|
|
|
'upgrade_frequency': '12',
|
2019-03-19 04:08:53 +00:00
|
|
|
'days_to_upgrade_subs': '7',
|
2019-04-07 20:09:17 +00:00
|
|
|
'upgrade_manual': 'True',
|
2019-09-11 10:50:33 +00:00
|
|
|
'anti_captcha_provider': 'None',
|
2020-05-07 11:39:59 +00:00
|
|
|
'wanted_search_frequency': '3',
|
2020-07-29 13:11:45 +00:00
|
|
|
'wanted_search_frequency_movie': '3',
|
2020-08-01 13:12:56 +00:00
|
|
|
'subzero_mods': '',
|
|
|
|
'dont_notify_manual_actions': 'False'
|
2019-01-15 16:25:13 +00:00
|
|
|
},
|
2018-12-27 19:19:59 +00:00
|
|
|
'auth': {
|
|
|
|
'type': 'None',
|
|
|
|
'username': '',
|
|
|
|
'password': ''
|
2019-01-15 16:25:13 +00:00
|
|
|
},
|
2018-12-27 19:19:59 +00:00
|
|
|
'sonarr': {
|
|
|
|
'ip': '127.0.0.1',
|
|
|
|
'port': '8989',
|
|
|
|
'base_url': '/',
|
|
|
|
'ssl': 'False',
|
|
|
|
'apikey': '',
|
2019-01-06 17:15:43 +00:00
|
|
|
'full_update': 'Daily',
|
2019-09-11 10:50:33 +00:00
|
|
|
'full_update_day': '6',
|
|
|
|
'full_update_hour': '4',
|
2019-01-06 17:15:43 +00:00
|
|
|
'only_monitored': 'False',
|
2020-05-06 12:09:41 +00:00
|
|
|
'series_sync': '1',
|
|
|
|
'episodes_sync': '5',
|
2020-07-13 14:57:43 +00:00
|
|
|
'excluded_tags': '[]',
|
|
|
|
'excluded_series_types': '[]'
|
2019-10-05 21:15:57 +00:00
|
|
|
},
|
2018-12-27 19:19:59 +00:00
|
|
|
'radarr': {
|
|
|
|
'ip': '127.0.0.1',
|
|
|
|
'port': '7878',
|
|
|
|
'base_url': '/',
|
|
|
|
'ssl': 'False',
|
|
|
|
'apikey': '',
|
2019-01-06 17:15:43 +00:00
|
|
|
'full_update': 'Daily',
|
2019-09-11 10:50:33 +00:00
|
|
|
'full_update_day': '6',
|
|
|
|
'full_update_hour': '5',
|
2019-01-06 17:15:43 +00:00
|
|
|
'only_monitored': 'False',
|
2020-05-06 12:09:41 +00:00
|
|
|
'movies_sync': '5',
|
2020-07-12 20:37:20 +00:00
|
|
|
'excluded_tags': '[]'
|
2019-10-05 21:15:57 +00:00
|
|
|
},
|
2018-12-27 19:19:59 +00:00
|
|
|
'proxy': {
|
|
|
|
'type': 'None',
|
|
|
|
'url': '',
|
|
|
|
'port': '',
|
|
|
|
'username': '',
|
|
|
|
'password': '',
|
|
|
|
'exclude': 'localhost,127.0.0.1'
|
2019-01-15 16:25:13 +00:00
|
|
|
},
|
2018-12-27 22:10:10 +00:00
|
|
|
'opensubtitles': {
|
|
|
|
'username': '',
|
2019-01-03 20:57:21 +00:00
|
|
|
'password': '',
|
2019-01-04 20:01:18 +00:00
|
|
|
'use_tag_search': 'False',
|
2019-01-24 15:55:36 +00:00
|
|
|
'vip': 'False',
|
|
|
|
'ssl': 'False',
|
2019-01-04 20:01:18 +00:00
|
|
|
'timeout': '15',
|
|
|
|
'skip_wrong_fps': 'False'
|
2019-01-15 16:25:13 +00:00
|
|
|
},
|
2021-01-25 19:28:55 +00:00
|
|
|
'opensubtitlescom': {
|
|
|
|
'username': '',
|
|
|
|
'password': '',
|
|
|
|
'use_hash': 'True'
|
|
|
|
},
|
2018-12-27 22:10:10 +00:00
|
|
|
'addic7ed': {
|
|
|
|
'username': '',
|
2020-05-20 23:29:11 +00:00
|
|
|
'password': ''
|
2019-01-24 14:00:03 +00:00
|
|
|
},
|
2020-01-16 20:38:41 +00:00
|
|
|
'legendasdivx': {
|
|
|
|
'username': '',
|
2020-05-09 17:38:27 +00:00
|
|
|
'password': '',
|
|
|
|
'skip_wrong_fps': 'False'
|
2020-01-16 20:38:41 +00:00
|
|
|
},
|
2018-12-27 22:10:10 +00:00
|
|
|
'legendastv': {
|
|
|
|
'username': '',
|
|
|
|
'password': ''
|
2019-01-15 16:25:13 +00:00
|
|
|
},
|
2019-02-24 17:41:22 +00:00
|
|
|
'xsubs': {
|
|
|
|
'username': '',
|
|
|
|
'password': ''
|
|
|
|
},
|
2019-01-04 20:01:18 +00:00
|
|
|
'assrt': {
|
|
|
|
'token': ''
|
2019-04-07 20:09:17 +00:00
|
|
|
},
|
|
|
|
'anticaptcha': {
|
|
|
|
'anti_captcha_key': ''
|
|
|
|
},
|
|
|
|
'deathbycaptcha': {
|
|
|
|
'username': '',
|
|
|
|
'password': ''
|
2019-05-19 00:26:42 +00:00
|
|
|
},
|
|
|
|
'napisy24': {
|
|
|
|
'username': '',
|
|
|
|
'password': ''
|
2019-06-21 01:34:14 +00:00
|
|
|
},
|
|
|
|
'subscene': {
|
|
|
|
'username': '',
|
|
|
|
'password': ''
|
2019-07-18 23:21:22 +00:00
|
|
|
},
|
|
|
|
'betaseries': {
|
|
|
|
'token': ''
|
2019-09-03 03:22:38 +00:00
|
|
|
},
|
|
|
|
'analytics': {
|
|
|
|
'enabled': 'True'
|
2019-10-05 21:15:57 +00:00
|
|
|
},
|
|
|
|
'titlovi': {
|
|
|
|
'username': '',
|
|
|
|
'password': ''
|
2020-06-10 16:04:54 +00:00
|
|
|
},
|
|
|
|
'subsync': {
|
|
|
|
'use_subsync': 'False',
|
|
|
|
'use_subsync_threshold': 'False',
|
|
|
|
'subsync_threshold': '90',
|
|
|
|
'use_subsync_movie_threshold': 'False',
|
2020-08-19 19:40:33 +00:00
|
|
|
'subsync_movie_threshold': '70',
|
|
|
|
'debug': 'False'
|
2019-04-07 20:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-27 19:19:59 +00:00
|
|
|
|
2020-01-29 11:53:29 +00:00
|
|
|
settings = simpleconfigparser(defaults=defaults, interpolation=None)
|
2019-01-02 19:43:40 +00:00
|
|
|
settings.read(os.path.join(args.config_dir, 'config', 'config.ini'))
|
2018-12-14 22:18:52 +00:00
|
|
|
|
2020-04-21 10:24:25 +00:00
|
|
|
settings.general.base_url = settings.general.base_url if settings.general.base_url else '/'
|
2018-12-15 00:36:28 +00:00
|
|
|
base_url = settings.general.base_url
|
2019-11-06 01:49:08 +00:00
|
|
|
|
|
|
|
|
2020-03-11 10:58:45 +00:00
|
|
|
def save_settings(settings_items):
|
2020-04-24 15:19:18 +00:00
|
|
|
from database import database
|
2020-05-08 04:22:14 +00:00
|
|
|
|
|
|
|
configure_debug = False
|
|
|
|
configure_captcha = False
|
|
|
|
update_schedule = False
|
2020-05-19 13:27:13 +00:00
|
|
|
update_path_map = False
|
2020-05-08 04:22:14 +00:00
|
|
|
configure_proxy = False
|
2020-09-03 10:33:24 +00:00
|
|
|
exclusion_updated = False
|
2020-05-08 04:22:14 +00:00
|
|
|
|
2020-03-11 10:58:45 +00:00
|
|
|
for key, value in settings_items:
|
2020-04-25 12:23:22 +00:00
|
|
|
# Intercept database stored settings
|
2020-04-24 10:56:03 +00:00
|
|
|
if key == 'enabled_languages':
|
2020-04-24 15:19:18 +00:00
|
|
|
database.execute("UPDATE table_settings_languages SET enabled=0")
|
|
|
|
for item in value:
|
|
|
|
database.execute("UPDATE table_settings_languages SET enabled=1 WHERE code2=?", (item,))
|
2020-04-24 10:56:03 +00:00
|
|
|
continue
|
|
|
|
|
2020-04-29 02:39:30 +00:00
|
|
|
# Make sure that text based form values aren't pass as list unless they are language list
|
|
|
|
if isinstance(value, list) and len(value) == 1 and key not in ['settings-general-serie_default_language',
|
|
|
|
'settings-general-movie_default_language']:
|
2020-04-24 15:19:18 +00:00
|
|
|
value = value[0]
|
|
|
|
|
2020-04-29 02:39:30 +00:00
|
|
|
# Make sure empty language list are stored correctly due to bug in bootstrap-select
|
|
|
|
if key in ['settings-general-serie_default_language', 'settings-general-movie_default_language'] and value == ['null']:
|
|
|
|
value = []
|
|
|
|
|
2020-03-11 10:58:45 +00:00
|
|
|
settings_keys = key.split('-')
|
|
|
|
|
|
|
|
if value == 'true':
|
|
|
|
value = 'True'
|
|
|
|
elif value == 'false':
|
|
|
|
value = 'False'
|
|
|
|
|
2020-03-26 19:37:17 +00:00
|
|
|
if key == 'settings-auth-password':
|
2021-01-14 21:02:17 +00:00
|
|
|
if value != settings.auth.password:
|
|
|
|
value = hashlib.md5(value.encode('utf-8')).hexdigest()
|
2020-03-26 19:37:17 +00:00
|
|
|
|
2020-05-08 04:22:14 +00:00
|
|
|
if key == 'settings-general-debug':
|
|
|
|
configure_debug = True
|
|
|
|
|
|
|
|
if key in ['settings-general-anti_captcha_provider', 'settings-anticaptcha-anti_captcha_key',
|
|
|
|
'settings-deathbycaptcha-username', 'settings-deathbycaptcha-password']:
|
|
|
|
configure_captcha = True
|
|
|
|
|
2020-05-15 01:21:09 +00:00
|
|
|
if key in ['update_schedule', 'settings-general-use_sonarr', 'settings-general-use_radarr',
|
|
|
|
'settings-general-auto_update', 'settings-general-upgrade_subs']:
|
2020-05-08 04:22:14 +00:00
|
|
|
update_schedule = True
|
|
|
|
|
2020-05-19 13:27:13 +00:00
|
|
|
if key in ['settings-general-path_mappings', 'settings-general-path_mappings_movie']:
|
|
|
|
update_path_map = True
|
|
|
|
|
2020-05-08 04:22:14 +00:00
|
|
|
if key in ['settings-proxy-type', 'settings-proxy-url', 'settings-proxy-port', 'settings-proxy-username',
|
|
|
|
'settings-proxy-password']:
|
|
|
|
configure_proxy = True
|
|
|
|
|
2020-09-01 16:30:31 +00:00
|
|
|
if key in ['settings-sonarr-excluded_tags', 'settings-sonarr-only_monitored',
|
|
|
|
'settings-sonarr-excluded_series_types', 'settings.radarr.excluded_tags',
|
|
|
|
'settings-radarr-only_monitored']:
|
|
|
|
exclusion_updated = True
|
|
|
|
|
2020-10-10 14:26:56 +00:00
|
|
|
if key == 'settings-addic7ed-username':
|
|
|
|
if key != settings.addic7ed.username:
|
|
|
|
region.delete('addic7ed_data')
|
|
|
|
|
|
|
|
if key == 'settings-legendasdivx-username':
|
|
|
|
if key != settings.legendasdivx.username:
|
|
|
|
region.delete('legendasdivx_cookies2')
|
|
|
|
|
|
|
|
if key == 'settings-opensubtitles-username':
|
|
|
|
if key != settings.opensubtitles.username:
|
|
|
|
region.delete('os_token')
|
|
|
|
|
|
|
|
if key == 'settings-subscene-username':
|
|
|
|
if key != settings.subscene.username:
|
|
|
|
region.delete('subscene_cookies2')
|
|
|
|
|
|
|
|
if key == 'settings-titlovi-username':
|
|
|
|
if key != settings.titlovi.username:
|
|
|
|
region.delete('titlovi_token')
|
|
|
|
|
2020-03-11 10:58:45 +00:00
|
|
|
if settings_keys[0] == 'settings':
|
|
|
|
settings[settings_keys[1]][settings_keys[2]] = str(value)
|
|
|
|
|
|
|
|
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
|
|
|
|
settings.write(handle)
|
|
|
|
|
2020-05-08 04:22:14 +00:00
|
|
|
# Reconfigure Bazarr to reflect changes
|
|
|
|
if configure_debug:
|
|
|
|
from logger import configure_logging
|
|
|
|
configure_logging(settings.general.getboolean('debug') or args.debug)
|
|
|
|
|
|
|
|
if configure_captcha:
|
|
|
|
configure_captcha_func()
|
|
|
|
|
|
|
|
if update_schedule:
|
2020-05-10 14:56:48 +00:00
|
|
|
from api import scheduler
|
|
|
|
scheduler.update_configurable_tasks()
|
2020-05-08 04:22:14 +00:00
|
|
|
|
2020-05-19 13:27:13 +00:00
|
|
|
if update_path_map:
|
|
|
|
from helper import path_mappings
|
|
|
|
path_mappings.update()
|
|
|
|
|
2020-05-08 04:22:14 +00:00
|
|
|
if configure_proxy:
|
|
|
|
configure_proxy_func()
|
2020-03-11 10:58:45 +00:00
|
|
|
|
2020-09-01 16:30:31 +00:00
|
|
|
if exclusion_updated:
|
|
|
|
from event_handler import event_stream
|
|
|
|
event_stream(type='badges_series')
|
|
|
|
event_stream(type='badges_movies')
|
|
|
|
|
2020-03-11 10:58:45 +00:00
|
|
|
|
2019-11-06 01:49:08 +00:00
|
|
|
def url_sonarr():
|
|
|
|
if settings.sonarr.getboolean('ssl'):
|
|
|
|
protocol_sonarr = "https"
|
|
|
|
else:
|
|
|
|
protocol_sonarr = "http"
|
|
|
|
|
|
|
|
if settings.sonarr.base_url == '':
|
|
|
|
settings.sonarr.base_url = "/"
|
|
|
|
if not settings.sonarr.base_url.startswith("/"):
|
|
|
|
settings.sonarr.base_url = "/" + settings.sonarr.base_url
|
|
|
|
if settings.sonarr.base_url.endswith("/"):
|
|
|
|
settings.sonarr.base_url = settings.sonarr.base_url[:-1]
|
|
|
|
|
|
|
|
return protocol_sonarr + "://" + settings.sonarr.ip + ":" + settings.sonarr.port + settings.sonarr.base_url
|
|
|
|
|
|
|
|
|
|
|
|
def url_sonarr_short():
|
|
|
|
if settings.sonarr.getboolean('ssl'):
|
|
|
|
protocol_sonarr = "https"
|
|
|
|
else:
|
|
|
|
protocol_sonarr = "http"
|
|
|
|
|
|
|
|
if settings.sonarr.base_url == '':
|
|
|
|
settings.sonarr.base_url = "/"
|
|
|
|
if not settings.sonarr.base_url.startswith("/"):
|
|
|
|
settings.sonarr.base_url = "/" + settings.sonarr.base_url
|
|
|
|
if settings.sonarr.base_url.endswith("/"):
|
|
|
|
settings.sonarr.base_url = settings.sonarr.base_url[:-1]
|
|
|
|
return protocol_sonarr + "://" + settings.sonarr.ip + ":" + settings.sonarr.port
|
|
|
|
|
|
|
|
|
|
|
|
def url_radarr():
|
|
|
|
if settings.radarr.getboolean('ssl'):
|
|
|
|
protocol_radarr = "https"
|
|
|
|
else:
|
|
|
|
protocol_radarr = "http"
|
|
|
|
|
|
|
|
if settings.radarr.base_url == '':
|
|
|
|
settings.radarr.base_url = "/"
|
|
|
|
if not settings.radarr.base_url.startswith("/"):
|
|
|
|
settings.radarr.base_url = "/" + settings.radarr.base_url
|
|
|
|
if settings.radarr.base_url.endswith("/"):
|
|
|
|
settings.radarr.base_url = settings.radarr.base_url[:-1]
|
|
|
|
|
|
|
|
return protocol_radarr + "://" + settings.radarr.ip + ":" + settings.radarr.port + settings.radarr.base_url
|
|
|
|
|
|
|
|
|
|
|
|
def url_radarr_short():
|
|
|
|
if settings.radarr.getboolean('ssl'):
|
|
|
|
protocol_radarr = "https"
|
|
|
|
else:
|
|
|
|
protocol_radarr = "http"
|
|
|
|
|
|
|
|
if settings.radarr.base_url == '':
|
|
|
|
settings.radarr.base_url = "/"
|
|
|
|
if not settings.radarr.base_url.startswith("/"):
|
|
|
|
settings.radarr.base_url = "/" + settings.radarr.base_url
|
|
|
|
if settings.radarr.base_url.endswith("/"):
|
|
|
|
settings.radarr.base_url = settings.radarr.base_url[:-1]
|
|
|
|
|
|
|
|
return protocol_radarr + "://" + settings.radarr.ip + ":" + settings.radarr.port
|
2020-05-08 04:22:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def configure_captcha_func():
|
|
|
|
# set anti-captcha provider and key
|
|
|
|
if settings.general.anti_captcha_provider == 'anti-captcha' and settings.anticaptcha.anti_captcha_key != "":
|
|
|
|
os.environ["ANTICAPTCHA_CLASS"] = 'AntiCaptchaProxyLess'
|
|
|
|
os.environ["ANTICAPTCHA_ACCOUNT_KEY"] = str(settings.anticaptcha.anti_captcha_key)
|
|
|
|
elif settings.general.anti_captcha_provider == 'death-by-captcha' and settings.deathbycaptcha.username != "" and \
|
|
|
|
settings.deathbycaptcha.password != "":
|
|
|
|
os.environ["ANTICAPTCHA_CLASS"] = 'DeathByCaptchaProxyLess'
|
|
|
|
os.environ["ANTICAPTCHA_ACCOUNT_KEY"] = str(':'.join(
|
|
|
|
{settings.deathbycaptcha.username, settings.deathbycaptcha.password}))
|
|
|
|
else:
|
|
|
|
os.environ["ANTICAPTCHA_CLASS"] = ''
|
|
|
|
|
2020-05-19 13:27:13 +00:00
|
|
|
|
2020-05-08 04:22:14 +00:00
|
|
|
def configure_proxy_func():
|
|
|
|
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 = settings.proxy.type + '://' + settings.proxy.url + ':' + settings.proxy.port
|
|
|
|
os.environ['HTTP_PROXY'] = str(proxy)
|
|
|
|
os.environ['HTTPS_PROXY'] = str(proxy)
|
2020-05-19 13:27:13 +00:00
|
|
|
os.environ['NO_PROXY'] = str(settings.proxy.exclude)
|