mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-01-08 04:00:03 -08:00
549 lines
32 KiB
Python
549 lines
32 KiB
Python
from __future__ import annotations
|
|
|
|
import copy
|
|
import logging
|
|
import os
|
|
import shutil
|
|
from itertools import chain
|
|
|
|
import configobj
|
|
|
|
import nzb2media
|
|
|
|
log = logging.getLogger(__name__)
|
|
log.addHandler(logging.NullHandler())
|
|
|
|
|
|
class Section(configobj.Section):
|
|
def isenabled(self):
|
|
# checks if subsection enabled, returns true/false if subsection
|
|
# specified otherwise returns true/false in {}
|
|
if not self.sections:
|
|
try:
|
|
value = list(ConfigObj.find_key(self, 'enabled'))[0]
|
|
except Exception:
|
|
value = 0
|
|
if int(value) == 1:
|
|
return self
|
|
else:
|
|
to_return = copy.deepcopy(self)
|
|
for section_name, subsections in to_return.items():
|
|
for subsection in subsections:
|
|
try:
|
|
value = list(ConfigObj.find_key(subsections, 'enabled'))[0]
|
|
except Exception:
|
|
value = 0
|
|
if int(value) != 1:
|
|
del to_return[section_name][subsection]
|
|
# cleanout empty sections and subsections
|
|
for key in [k for (k, v) in to_return.items() if not v]:
|
|
del to_return[key]
|
|
return to_return
|
|
return None
|
|
|
|
def findsection(self, key):
|
|
to_return = copy.deepcopy(self)
|
|
for subsection in to_return:
|
|
try:
|
|
value = list(ConfigObj.find_key(to_return[subsection], key))[0]
|
|
except Exception:
|
|
value = None
|
|
if not value:
|
|
del to_return[subsection]
|
|
else:
|
|
for category in to_return[subsection]:
|
|
if category != key:
|
|
del to_return[subsection][category]
|
|
# cleanout empty sections and subsections
|
|
for key in [k for (k, v) in to_return.items() if not v]:
|
|
del to_return[key]
|
|
return to_return
|
|
|
|
def __getitem__(self, key):
|
|
if key in self.keys():
|
|
return dict.__getitem__(self, key)
|
|
to_return = copy.deepcopy(self)
|
|
for section, subsections in to_return.items():
|
|
if section in key:
|
|
continue
|
|
if isinstance(subsections, Section) and subsections.sections:
|
|
for subsection, options in subsections.items():
|
|
if subsection in key:
|
|
continue
|
|
if key in options:
|
|
return options[key]
|
|
del subsections[subsection]
|
|
elif section not in key:
|
|
del to_return[section]
|
|
# cleanout empty sections and subsections
|
|
for key in [k for (k, v) in to_return.items() if not v]:
|
|
del to_return[key]
|
|
return to_return
|
|
|
|
|
|
class ConfigObj(configobj.ConfigObj, Section):
|
|
def __init__(self, infile, *args, **kw):
|
|
if infile is None:
|
|
infile = nzb2media.CONFIG_FILE
|
|
super().__init__(os.fspath(infile), *args, **kw)
|
|
self.interpolation = False
|
|
|
|
@staticmethod
|
|
def find_key(node, value):
|
|
if isinstance(node, list):
|
|
for i in node:
|
|
yield from ConfigObj.find_key(i, value)
|
|
elif isinstance(node, dict):
|
|
if value in node:
|
|
yield node[value]
|
|
for j in node.values():
|
|
yield from ConfigObj.find_key(j, value)
|
|
|
|
@staticmethod
|
|
def migrate():
|
|
global CFG_NEW, CFG_OLD
|
|
CFG_NEW = None
|
|
CFG_OLD = None
|
|
try:
|
|
# check for autoProcessMedia.cfg and create if it does not exist
|
|
if not nzb2media.CONFIG_FILE.is_file():
|
|
shutil.copyfile(nzb2media.CONFIG_SPEC_FILE, nzb2media.CONFIG_FILE)
|
|
CFG_OLD = Config(nzb2media.CONFIG_FILE)
|
|
except Exception as error:
|
|
log.error(f'Error {error} when copying to .cfg')
|
|
try:
|
|
# check for autoProcessMedia.cfg.spec and create if it does not exist
|
|
if not nzb2media.CONFIG_SPEC_FILE.is_file():
|
|
shutil.copyfile(nzb2media.CONFIG_FILE, nzb2media.CONFIG_SPEC_FILE)
|
|
CFG_NEW = Config(nzb2media.CONFIG_SPEC_FILE)
|
|
except Exception as error:
|
|
log.error(f'Error {error} when copying to .spec')
|
|
# check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail
|
|
if CFG_NEW is None or CFG_OLD is None:
|
|
return False
|
|
subsections = {}
|
|
# gather all new-style and old-style sub-sections
|
|
for newsection in CFG_NEW:
|
|
if CFG_NEW[newsection].sections:
|
|
subsections.update({newsection: CFG_NEW[newsection].sections})
|
|
for section in CFG_OLD:
|
|
if CFG_OLD[section].sections:
|
|
subsections.update({section: CFG_OLD[section].sections})
|
|
for option, value in CFG_OLD[section].items():
|
|
if option in {'category', 'cpsCategory', 'sbCategory', 'srCategory', 'hpCategory', 'mlCategory', 'gzCategory', 'raCategory', 'ndCategory', 'W3Category'}:
|
|
if not isinstance(value, list):
|
|
value = [value]
|
|
# add subsection
|
|
subsections.update({section: value})
|
|
CFG_OLD[section].pop(option)
|
|
continue
|
|
|
|
def cleanup_values(values, section):
|
|
for option, value in values.items():
|
|
if section in {'CouchPotato'}:
|
|
if option == ['outputDirectory']:
|
|
CFG_NEW['Torrent'][option] = os.path.split(os.path.normpath(value))[0]
|
|
values.pop(option)
|
|
if section in {'CouchPotato', 'HeadPhones', 'Gamez', 'Mylar'}:
|
|
if option in {'username', 'password'}:
|
|
values.pop(option)
|
|
if section in {'Mylar'}:
|
|
if option == 'wait_for': # remove old format
|
|
values.pop(option)
|
|
if section in {'SickBeard', 'NzbDrone'}:
|
|
if option == 'failed_fork': # change this old format
|
|
values['failed'] = 'auto'
|
|
values.pop(option)
|
|
if option == 'outputDirectory': # move this to new location format
|
|
CFG_NEW['Torrent'][option] = os.path.split(os.path.normpath(value))[0]
|
|
values.pop(option)
|
|
if section in {'Torrent'}:
|
|
if option in {'compressedExtensions', 'mediaExtensions', 'metaExtensions', 'minSampleSize'}:
|
|
CFG_NEW['Extensions'][option] = value
|
|
values.pop(option)
|
|
if option == 'useLink': # Sym links supported now as well.
|
|
if value in {'1', 1}:
|
|
value = 'hard'
|
|
elif value in {'0', 0}:
|
|
value = 'no'
|
|
values[option] = value
|
|
if option == 'forceClean':
|
|
CFG_NEW['General']['force_clean'] = value
|
|
values.pop(option)
|
|
if option == 'qBittorrenHost': # We had a typo that is now fixed.
|
|
CFG_NEW['Torrent']['qBittorrentHost'] = value
|
|
values.pop(option)
|
|
if section in {'Transcoder'}:
|
|
if option in {'niceness'}:
|
|
CFG_NEW['Posix'][option] = value
|
|
values.pop(option)
|
|
if option == 'remote_path':
|
|
if value and value not in ['0', '1', 0, 1]:
|
|
value = 1
|
|
elif not value:
|
|
value = 0
|
|
values[option] = value
|
|
# remove any options that we no longer need so they don't migrate into our new config
|
|
if not list(ConfigObj.find_key(CFG_NEW, option)):
|
|
try:
|
|
values.pop(option)
|
|
except Exception:
|
|
pass
|
|
return values
|
|
|
|
def process_section(section, subsections=None):
|
|
if subsections:
|
|
for subsection in subsections:
|
|
if subsection in CFG_OLD.sections:
|
|
values = cleanup_values(CFG_OLD[subsection], section)
|
|
if subsection not in CFG_NEW[section].sections:
|
|
CFG_NEW[section][subsection] = {}
|
|
for option, value in values.items():
|
|
CFG_NEW[section][subsection][option] = value
|
|
elif subsection in CFG_OLD[section].sections:
|
|
values = cleanup_values(CFG_OLD[section][subsection], section)
|
|
if subsection not in CFG_NEW[section].sections:
|
|
CFG_NEW[section][subsection] = {}
|
|
for option, value in values.items():
|
|
CFG_NEW[section][subsection][option] = value
|
|
else:
|
|
values = cleanup_values(CFG_OLD[section], section)
|
|
if section not in CFG_NEW.sections:
|
|
CFG_NEW[section] = {}
|
|
for option, value in values.items():
|
|
CFG_NEW[section][option] = value
|
|
|
|
# convert old-style categories to new-style sub-sections
|
|
for section in CFG_OLD.keys():
|
|
subsection = None
|
|
if section in list(chain.from_iterable(subsections.values())):
|
|
subsection = section
|
|
section = ''.join([k for k, v in subsections.items() if subsection in v])
|
|
process_section(section, subsection)
|
|
elif section in subsections.keys():
|
|
subsection = subsections[section]
|
|
process_section(section, subsection)
|
|
elif section in CFG_OLD.keys():
|
|
process_section(section, subsection)
|
|
# migrate SiCRKAGE settings from SickBeard SECTION to new dedicated SiCRKAGE SECTION
|
|
if CFG_OLD['SickBeard']['tv']['enabled'] and CFG_OLD['SickBeard']['tv']['fork'] == 'sickrage-api':
|
|
for option, value in CFG_OLD['SickBeard']['tv'].items():
|
|
if option in CFG_NEW['SiCKRAGE']['tv']:
|
|
CFG_NEW['SiCKRAGE']['tv'][option] = value
|
|
# set API version to 1 if API key detected and no SSO username is set
|
|
if CFG_NEW['SiCKRAGE']['tv']['apikey'] and not CFG_NEW['SiCKRAGE']['tv']['sso_username']:
|
|
CFG_NEW['SiCKRAGE']['tv']['api_version'] = 1
|
|
# disable SickBeard SECTION
|
|
CFG_NEW['SickBeard']['tv']['enabled'] = 0
|
|
CFG_NEW['SickBeard']['tv']['fork'] = 'auto'
|
|
# create a backup of our old config
|
|
CFG_OLD.filename = f'{nzb2media.CONFIG_FILE}.old'
|
|
CFG_OLD.write()
|
|
# write our new config to autoProcessMedia.cfg
|
|
CFG_NEW.filename = nzb2media.CONFIG_FILE
|
|
CFG_NEW.write()
|
|
return True
|
|
|
|
@staticmethod
|
|
def addnzbget():
|
|
# load configs into memory
|
|
cfg_new = Config(None)
|
|
try:
|
|
if 'NZBPO_NDCATEGORY' in os.environ and 'NZBPO_SBCATEGORY' in os.environ:
|
|
if os.environ['NZBPO_NDCATEGORY'] == os.environ['NZBPO_SBCATEGORY']:
|
|
_cat = os.environ['NZBPO_NDCATEGORY']
|
|
msg = f'{_cat} category is set for SickBeard and Sonarr. Please check your config in NZBGet'
|
|
log.warning(msg)
|
|
if 'NZBPO_RACATEGORY' in os.environ and 'NZBPO_CPSCATEGORY' in os.environ:
|
|
if os.environ['NZBPO_RACATEGORY'] == os.environ['NZBPO_CPSCATEGORY']:
|
|
_cat = os.environ['NZBPO_RACATEGORY']
|
|
msg = f'{_cat} category is set for CouchPotato and Radarr. Please check your config in NZBGet'
|
|
log.warning(msg)
|
|
if 'NZBPO_RACATEGORY' in os.environ and 'NZBPO_W3CATEGORY' in os.environ:
|
|
if os.environ['NZBPO_RACATEGORY'] == os.environ['NZBPO_W3CATEGORY']:
|
|
_cat = os.environ['NZBPO_RACATEGORY']
|
|
msg = f'{_cat} category is set for Watcher3 and Radarr. Please check your config in NZBGet'
|
|
log.warning(msg)
|
|
if 'NZBPO_W3CATEGORY' in os.environ and 'NZBPO_CPSCATEGORY' in os.environ:
|
|
if os.environ['NZBPO_W3CATEGORY'] == os.environ['NZBPO_CPSCATEGORY']:
|
|
_cat = os.environ['NZBPO_W3CATEGORY']
|
|
msg = f'{_cat} category is set for CouchPotato and Watcher3. Please check your config in NZBGet'
|
|
log.warning(msg)
|
|
if 'NZBPO_LICATEGORY' in os.environ and 'NZBPO_HPCATEGORY' in os.environ:
|
|
if os.environ['NZBPO_LICATEGORY'] == os.environ['NZBPO_HPCATEGORY']:
|
|
_cat = os.environ['NZBPO_LICATEGORY']
|
|
msg = f'{_cat} category is set for HeadPhones and Lidarr. Please check your config in NZBGet'
|
|
log.warning(msg)
|
|
section = 'Nzb'
|
|
key = 'NZBOP_DESTDIR'
|
|
if key in os.environ:
|
|
option = 'default_downloadDirectory'
|
|
value = os.environ[key]
|
|
cfg_new[section][option] = value
|
|
section = 'General'
|
|
env_keys = ['AUTO_UPDATE', 'CHECK_MEDIA', 'REQUIRE_LAN', 'SAFE_MODE', 'NO_EXTRACT_FAILED']
|
|
cfg_keys = ['auto_update', 'check_media', 'require_lan', 'safe_mode', 'no_extract_failed']
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
cfg_new[section][option] = value
|
|
section = 'Network'
|
|
env_keys = ['MOUNTPOINTS']
|
|
cfg_keys = ['mount_points']
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
cfg_new[section][option] = value
|
|
section = 'CouchPotato'
|
|
env_cat_key = 'NZBPO_CPSCATEGORY'
|
|
env_keys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'METHOD', 'DELETE_FAILED', 'REMOTE_PATH', 'WAIT_FOR', 'WATCH_DIR', 'OMDBAPIKEY']
|
|
cfg_keys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'method', 'delete_failed', 'remote_path', 'wait_for', 'watch_dir', 'omdbapikey']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_CPS{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['Radarr'].sections:
|
|
cfg_new['Radarr'][env_cat_key]['enabled'] = 0
|
|
if os.environ[env_cat_key] in cfg_new['Watcher3'].sections:
|
|
cfg_new['Watcher3'][env_cat_key]['enabled'] = 0
|
|
section = 'Watcher3'
|
|
env_cat_key = 'NZBPO_W3CATEGORY'
|
|
env_keys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'METHOD', 'DELETE_FAILED', 'REMOTE_PATH', 'WAIT_FOR', 'WATCH_DIR', 'OMDBAPIKEY']
|
|
cfg_keys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'method', 'delete_failed', 'remote_path', 'wait_for', 'watch_dir', 'omdbapikey']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_W3{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['Radarr'].sections:
|
|
cfg_new['Radarr'][env_cat_key]['enabled'] = 0
|
|
if os.environ[env_cat_key] in cfg_new['CouchPotato'].sections:
|
|
cfg_new['CouchPotato'][env_cat_key]['enabled'] = 0
|
|
section = 'SickBeard'
|
|
env_cat_key = 'NZBPO_SBCATEGORY'
|
|
env_keys = ['ENABLED', 'HOST', 'PORT', 'APIKEY', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'REMOTE_PATH', 'PROCESS_METHOD']
|
|
cfg_keys = ['enabled', 'host', 'port', 'apikey', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy', 'remote_path', 'process_method']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_SB{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['SiCKRAGE'].sections:
|
|
cfg_new['SiCKRAGE'][env_cat_key]['enabled'] = 0
|
|
if os.environ[env_cat_key] in cfg_new['NzbDrone'].sections:
|
|
cfg_new['NzbDrone'][env_cat_key]['enabled'] = 0
|
|
section = 'SiCKRAGE'
|
|
env_cat_key = 'NZBPO_SRCATEGORY'
|
|
env_keys = ['ENABLED', 'HOST', 'PORT', 'APIKEY', 'API_VERSION', 'SSO_USERNAME', 'SSO_PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'REMOTE_PATH', 'PROCESS_METHOD']
|
|
cfg_keys = ['enabled', 'host', 'port', 'apikey', 'api_version', 'sso_username', 'sso_password', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy', 'remote_path', 'process_method']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_SR{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['SickBeard'].sections:
|
|
cfg_new['SickBeard'][env_cat_key]['enabled'] = 0
|
|
if os.environ[env_cat_key] in cfg_new['NzbDrone'].sections:
|
|
cfg_new['NzbDrone'][env_cat_key]['enabled'] = 0
|
|
section = 'HeadPhones'
|
|
env_cat_key = 'NZBPO_HPCATEGORY'
|
|
env_keys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WAIT_FOR', 'WATCH_DIR', 'REMOTE_PATH', 'DELETE_FAILED']
|
|
cfg_keys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'wait_for', 'watch_dir', 'remote_path', 'delete_failed']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_HP{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['Lidarr'].sections:
|
|
cfg_new['Lidarr'][env_cat_key]['enabled'] = 0
|
|
section = 'Mylar'
|
|
env_cat_key = 'NZBPO_MYCATEGORY'
|
|
env_keys = ['ENABLED', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'APIKEY', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'REMOTE_PATH']
|
|
cfg_keys = ['enabled', 'host', 'port', 'username', 'password', 'apikey', 'ssl', 'web_root', 'watch_dir', 'remote_path']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_MY{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
section = 'Gamez'
|
|
env_cat_key = 'NZBPO_GZCATEGORY'
|
|
env_keys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'LIBRARY', 'REMOTE_PATH']
|
|
cfg_keys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'watch_dir', 'library', 'remote_path']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_GZ{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
section = 'LazyLibrarian'
|
|
env_cat_key = 'NZBPO_LLCATEGORY'
|
|
env_keys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'REMOTE_PATH']
|
|
cfg_keys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'watch_dir', 'remote_path']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_LL{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
section = 'NzbDrone'
|
|
env_cat_key = 'NZBPO_NDCATEGORY'
|
|
env_keys = ['ENABLED', 'HOST', 'APIKEY', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'WAIT_FOR', 'DELETE_FAILED', 'REMOTE_PATH', 'IMPORTMODE']
|
|
# new cfgKey added for importMode
|
|
cfg_keys = ['enabled', 'host', 'apikey', 'port', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy', 'wait_for', 'delete_failed', 'remote_path', 'importMode']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_ND{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['SickBeard'].sections:
|
|
cfg_new['SickBeard'][env_cat_key]['enabled'] = 0
|
|
if os.environ[env_cat_key] in cfg_new['SiCKRAGE'].sections:
|
|
cfg_new['SiCKRAGE'][env_cat_key]['enabled'] = 0
|
|
section = 'Radarr'
|
|
env_cat_key = 'NZBPO_RACATEGORY'
|
|
env_keys = ['ENABLED', 'HOST', 'APIKEY', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'WAIT_FOR', 'DELETE_FAILED', 'REMOTE_PATH', 'OMDBAPIKEY', 'IMPORTMODE']
|
|
# new cfgKey added for importMode
|
|
cfg_keys = ['enabled', 'host', 'apikey', 'port', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy', 'wait_for', 'delete_failed', 'remote_path', 'omdbapikey', 'importMode']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_RA{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['CouchPotato'].sections:
|
|
cfg_new['CouchPotato'][env_cat_key]['enabled'] = 0
|
|
if os.environ[env_cat_key] in cfg_new['Wacther3'].sections:
|
|
cfg_new['Watcher3'][env_cat_key]['enabled'] = 0
|
|
section = 'Lidarr'
|
|
env_cat_key = 'NZBPO_LICATEGORY'
|
|
env_keys = ['ENABLED', 'HOST', 'APIKEY', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'WAIT_FOR', 'DELETE_FAILED', 'REMOTE_PATH']
|
|
cfg_keys = ['enabled', 'host', 'apikey', 'port', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy', 'wait_for', 'delete_failed', 'remote_path']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_LI{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
if os.environ[env_cat_key] in cfg_new['HeadPhones'].sections:
|
|
cfg_new['HeadPhones'][env_cat_key]['enabled'] = 0
|
|
section = 'Extensions'
|
|
env_keys = ['COMPRESSEDEXTENSIONS', 'MEDIAEXTENSIONS', 'METAEXTENSIONS']
|
|
cfg_keys = ['compressedExtensions', 'mediaExtensions', 'metaExtensions']
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
cfg_new[section][option] = value
|
|
section = 'Posix'
|
|
env_keys = ['NICENESS', 'IONICE_CLASS', 'IONICE_CLASSDATA']
|
|
cfg_keys = ['niceness', 'ionice_class', 'ionice_classdata']
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
cfg_new[section][option] = value
|
|
section = 'Transcoder'
|
|
env_keys = ['TRANSCODE', 'DUPLICATE', 'IGNOREEXTENSIONS', 'OUTPUTFASTSTART', 'OUTPUTVIDEOPATH', 'PROCESSOUTPUT', 'AUDIOLANGUAGE', 'ALLAUDIOLANGUAGES', 'SUBLANGUAGES', 'ALLSUBLANGUAGES', 'EMBEDSUBS', 'BURNINSUBTITLE', 'EXTRACTSUBS', 'EXTERNALSUBDIR', 'OUTPUTDEFAULT', 'OUTPUTVIDEOEXTENSION', 'OUTPUTVIDEOCODEC', 'VIDEOCODECALLOW', 'OUTPUTVIDEOPRESET', 'OUTPUTVIDEOFRAMERATE', 'OUTPUTVIDEOBITRATE', 'OUTPUTAUDIOCODEC', 'AUDIOCODECALLOW', 'OUTPUTAUDIOBITRATE', 'OUTPUTQUALITYPERCENT', 'GETSUBS', 'OUTPUTAUDIOTRACK2CODEC', 'AUDIOCODEC2ALLOW', 'OUTPUTAUDIOTRACK2BITRATE', 'OUTPUTAUDIOOTHERCODEC', 'AUDIOOTHERCODECALLOW', 'OUTPUTAUDIOOTHERBITRATE', 'OUTPUTSUBTITLECODEC', 'OUTPUTAUDIOCHANNELS', 'OUTPUTAUDIOTRACK2CHANNELS', 'OUTPUTAUDIOOTHERCHANNELS', 'OUTPUTVIDEORESOLUTION']
|
|
cfg_keys = ['transcode', 'duplicate', 'ignoreExtensions', 'outputFastStart', 'outputVideoPath', 'processOutput', 'audioLanguage', 'allAudioLanguages', 'subLanguages', 'allSubLanguages', 'embedSubs', 'burnInSubtitle', 'extractSubs', 'externalSubDir', 'outputDefault', 'outputVideoExtension', 'outputVideoCodec', 'VideoCodecAllow', 'outputVideoPreset', 'outputVideoFramerate', 'outputVideoBitrate', 'outputAudioCodec', 'AudioCodecAllow', 'outputAudioBitrate', 'outputQualityPercent', 'getSubs', 'outputAudioTrack2Codec', 'AudioCodec2Allow', 'outputAudioTrack2Bitrate', 'outputAudioOtherCodec', 'AudioOtherCodecAllow', 'outputAudioOtherBitrate', 'outputSubtitleCodec', 'outputAudioChannels', 'outputAudioTrack2Channels', 'outputAudioOtherChannels', 'outputVideoResolution']
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
cfg_new[section][option] = value
|
|
section = 'WakeOnLan'
|
|
env_keys = ['WAKE', 'HOST', 'PORT', 'MAC']
|
|
cfg_keys = ['wake', 'host', 'port', 'mac']
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_WOL{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
cfg_new[section][option] = value
|
|
section = 'UserScript'
|
|
env_cat_key = 'NZBPO_USCATEGORY'
|
|
env_keys = ['USER_SCRIPT_MEDIAEXTENSIONS', 'USER_SCRIPT_PATH', 'USER_SCRIPT_PARAM', 'USER_SCRIPT_RUNONCE', 'USER_SCRIPT_SUCCESSCODES', 'USER_SCRIPT_CLEAN', 'USDELAY', 'USREMOTE_PATH']
|
|
cfg_keys = ['user_script_mediaExtensions', 'user_script_path', 'user_script_param', 'user_script_runOnce', 'user_script_successCodes', 'user_script_clean', 'delay', 'remote_path']
|
|
if env_cat_key in os.environ:
|
|
for index, env_key in enumerate(env_keys):
|
|
key = f'NZBPO_{env_key}'
|
|
if key in os.environ:
|
|
option = cfg_keys[index]
|
|
value = os.environ[key]
|
|
if os.environ[env_cat_key] not in cfg_new[section].sections:
|
|
cfg_new[section][os.environ[env_cat_key]] = {}
|
|
cfg_new[section][os.environ[env_cat_key]][option] = value
|
|
cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1
|
|
except Exception as error:
|
|
log.debug(f'Error {error} when applying NZBGet config')
|
|
try:
|
|
# write our new config to autoProcessMedia.cfg
|
|
cfg_new.filename = nzb2media.CONFIG_FILE
|
|
cfg_new.write()
|
|
except Exception as error:
|
|
log.debug(f'Error {error} when writing changes to .cfg')
|
|
return cfg_new
|
|
|
|
|
|
configobj.Section = Section
|
|
configobj.ConfigObj = ConfigObj
|
|
Config = ConfigObj
|