From 1458314c1796b04f60d920ad005bb688e82efaf8 Mon Sep 17 00:00:00 2001 From: Prinz23 Date: Wed, 13 Jun 2018 22:35:36 +0200 Subject: [PATCH] Add base mapping logic for NZBGet. --- sickbeard/__init__.py | 5 ++++- sickbeard/helpers.py | 2 +- sickbeard/webserve.py | 9 ++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 7ca118ac..b02a0a0d 100755 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -268,6 +268,7 @@ NZBGET_HOST = None NZBGET_USE_HTTPS = False NZBGET_PRIORITY = 100 NZBGET_SCRIPT_VERSION = None +NZBGET_MAP = None SAB_USERNAME = None SAB_PASSWORD = None @@ -615,7 +616,7 @@ def initialize(console_logging=True): # Search Settings/NZB search global USE_NZBS, NZB_METHOD, NZB_DIR, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ NZBGET_USE_HTTPS, NZBGET_HOST, NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_PRIORITY, \ - NZBGET_SCRIPT_VERSION + NZBGET_SCRIPT_VERSION, NZBGET_MAP # Search Settings/Torrent search global USE_TORRENTS, TORRENT_METHOD, TORRENT_DIR, TORRENT_HOST, TORRENT_USERNAME, TORRENT_PASSWORD, \ TORRENT_LABEL, TORRENT_PATH, TORRENT_SEED_TIME, TORRENT_PAUSED, TORRENT_HIGH_BANDWIDTH, TORRENT_VERIFY_CERT @@ -924,6 +925,7 @@ def initialize(console_logging=True): NZBGET_HOST = check_setting_str(CFG, 'NZBget', 'nzbget_host', '') NZBGET_USE_HTTPS = bool(check_setting_int(CFG, 'NZBget', 'nzbget_use_https', 0)) NZBGET_PRIORITY = check_setting_int(CFG, 'NZBget', 'nzbget_priority', 100) + NZBGET_MAP = check_setting_str(CFG, 'NZBget', 'nzbget_map', '') try: ng_script_file = ek.ek(os.path.join, ek.ek(os.path.dirname, ek.ek(os.path.dirname, __file__)), @@ -1766,6 +1768,7 @@ def save_config(): new_config['NZBget']['nzbget_host'] = NZBGET_HOST new_config['NZBget']['nzbget_use_https'] = int(NZBGET_USE_HTTPS) new_config['NZBget']['nzbget_priority'] = NZBGET_PRIORITY + new_config['NZBget']['nzbget_map'] = NZBGET_MAP new_config['TORRENT'] = {} new_config['TORRENT']['torrent_username'] = TORRENT_USERNAME diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 098c0146..30388e8a 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1728,7 +1728,7 @@ def path_mapper(search, replace, subject): replace = re.sub(r'[\\]', delim, replace) path = re.sub(r'[\\]', delim, subject) result = re.sub('(?i)^%s' % search, replace, path) - result = os.path.normpath(re.sub(delim, '/', result)) + result = ek.ek(os.path.normpath, re.sub(delim, '/', result)) return result, result != subject diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 54a44a9c..643b385f 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -2996,7 +2996,14 @@ class HomePostProcess(Home): logger.log('Calling SickGear-NG.py script %s is not current version %s, please update.' % (kwargs.get('ppVersion', '0'), sickbeard.NZBGET_SCRIPT_VERSION), logger.ERROR) - result = processTV.processDir(dir.decode('utf-8') if dir else None, nzbName.decode('utf-8') if nzbName else None, + if isinstance(dir, basestring): + dir = dir.decode('utf-8') + if isinstance(client, basestring) and 'nzbget' == client and \ + isinstance(sickbeard.NZBGET_MAP, basestring) and sickbeard.NZBGET_MAP: + m = sickbeard.NZBGET_MAP.split('=') + dir, not_used = helpers.path_mapper(m[0], m[1], dir) + + result = processTV.processDir(dir if dir else None, nzbName.decode('utf-8') if nzbName else None, process_method=process_method, type=type, cleanup='cleanup' in kwargs and kwargs['cleanup'] in ['on', '1'], force=force in ['on', '1'],