From 5f328eba5f2e04395e2eb813943584ad0676ab18 Mon Sep 17 00:00:00 2001 From: echel0n Date: Mon, 19 May 2014 19:14:06 -0700 Subject: [PATCH] Converted NZB providers to new dynamic config style format. --- .../interfaces/default/config_providers.tmpl | 17 ++++++--- sickbeard/__init__.py | 37 ++++++++++++------- sickbeard/providers/omgwtfnzbs.py | 15 +++++--- sickbeard/providers/womble.py | 3 +- sickbeard/webserve.py | 20 ++++++++-- 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/gui/slick/interfaces/default/config_providers.tmpl b/gui/slick/interfaces/default/config_providers.tmpl index 5f2b5886..ed2d72b9 100644 --- a/gui/slick/interfaces/default/config_providers.tmpl +++ b/gui/slick/interfaces/default/config_providers.tmpl @@ -204,20 +204,27 @@ var show_nzb_providers = #if $sickbeard.USE_NZBS then "true" else "false"#; #end for -
+#for $curNzbProvider in [$curProvider for $curProvider in $sickbeard.providers.sortedProviderList() if $curProvider.providerType == $GenericProvider.NZB]: +
+ #if $hasattr($curNzbProvider, 'username'):
+ #end if + + #if $hasattr($curNzbProvider, 'api_key'):
-
+ #end if +
+#end for #for $curTorrentProvider in [$curProvider for $curProvider in $sickbeard.providers.sortedProviderList() if $curProvider.providerType == $GenericProvider.TORRENT]:
@@ -256,7 +263,7 @@ var show_nzb_providers = #if $sickbeard.USE_NZBS then "true" else "false"#;
diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 03713de1..19eb4bd8 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -640,12 +640,6 @@ def initialize(consoleLogging=True): NEWZBIN_USERNAME = check_setting_str(CFG, 'Newzbin', 'newzbin_username', '') NEWZBIN_PASSWORD = check_setting_str(CFG, 'Newzbin', 'newzbin_password', '') - WOMBLE = bool(check_setting_int(CFG, 'Womble', 'womble', 0)) - - OMGWTFNZBS = bool(check_setting_int(CFG, 'omgwtfnzbs', 'omgwtfnzbs', 0)) - OMGWTFNZBS_USERNAME = check_setting_str(CFG, 'omgwtfnzbs', 'omgwtfnzbs_username', '') - OMGWTFNZBS_APIKEY = check_setting_str(CFG, 'omgwtfnzbs', 'omgwtfnzbs_apikey', '') - SAB_USERNAME = check_setting_str(CFG, 'SABnzbd', 'sab_username', '') SAB_PASSWORD = check_setting_str(CFG, 'SABnzbd', 'sab_password', '') SAB_APIKEY = check_setting_str(CFG, 'SABnzbd', 'sab_apikey', '') @@ -1033,6 +1027,17 @@ def initialize(consoleLogging=True): curTorrentProvider.backlog_only = bool(check_setting_int(CFG, curTorrentProvider.getID().upper(), curTorrentProvider.getID() + '_backlog_only', 0)) + + for curNzbProvider in [curProvider for curProvider in providers.sortedProviderList() if + curProvider.providerType == GenericProvider.NZB]: + curNzbProvider.enabled = bool( + check_setting_int(CFG, curNzbProvider.getID().upper(), curNzbProvider.getID(), 0)) + if hasattr(curNzbProvider, 'api_key'): + curNzbProvider.api_key = check_setting_str(CFG, curNzbProvider.getID().upper(), + curNzbProvider.getID() + '_api_key', '') + if hasattr(curNzbProvider, 'username'): + curNzbProvider.username = check_setting_str(CFG, curNzbProvider.getID().upper(), + curNzbProvider.getID() + '_username', '') try: url = 'http://raw.github.com/echel0n/sickrage-init/master/settings.ini' clear_cache = ElementTree.XML(helpers.getURL(url)).find('cache/clear').text @@ -1426,6 +1431,18 @@ def save_config(): new_config[curTorrentProvider.getID().upper()][curTorrentProvider.getID() + '_backlog_only'] = int( curTorrentProvider.backlog_only) + for curNzbProvider in [curProvider for curProvider in providers.sortedProviderList() if + curProvider.providerType == GenericProvider.NZB]: + new_config[curNzbProvider.getID().upper()] = {} + new_config[curNzbProvider.getID().upper()][curNzbProvider.getID()] = int(curNzbProvider.enabled) + + if hasattr(curNzbProvider, 'api_key'): + new_config[curNzbProvider.getID().upper()][ + curNzbProvider.getID() + '_api_key'] = curNzbProvider.api_key + if hasattr(curNzbProvider, 'username'): + new_config[curNzbProvider.getID().upper()][ + curNzbProvider.getID() + '_username'] = curNzbProvider.username + new_config['NZBs'] = {} new_config['NZBs']['nzbs'] = int(NZBS) new_config['NZBs']['nzbs_uid'] = NZBS_UID @@ -1436,14 +1453,6 @@ def save_config(): new_config['Newzbin']['newzbin_username'] = NEWZBIN_USERNAME new_config['Newzbin']['newzbin_password'] = helpers.encrypt(NEWZBIN_PASSWORD, ENCRYPTION_VERSION) - new_config['Womble'] = {} - new_config['Womble']['womble'] = int(WOMBLE) - - new_config['omgwtfnzbs'] = {} - new_config['omgwtfnzbs']['omgwtfnzbs'] = int(OMGWTFNZBS) - new_config['omgwtfnzbs']['omgwtfnzbs_username'] = OMGWTFNZBS_USERNAME - new_config['omgwtfnzbs']['omgwtfnzbs_apikey'] = OMGWTFNZBS_APIKEY - new_config['SABnzbd'] = {} new_config['SABnzbd']['sab_username'] = SAB_USERNAME new_config['SABnzbd']['sab_password'] = helpers.encrypt(SAB_PASSWORD, ENCRYPTION_VERSION) diff --git a/sickbeard/providers/omgwtfnzbs.py b/sickbeard/providers/omgwtfnzbs.py index e1d473ef..79dd1132 100644 --- a/sickbeard/providers/omgwtfnzbs.py +++ b/sickbeard/providers/omgwtfnzbs.py @@ -42,16 +42,19 @@ except ImportError: class OmgwtfnzbsProvider(generic.NZBProvider): def __init__(self): generic.NZBProvider.__init__(self, "omgwtfnzbs") + self.enabled = False + self.username = None + self.api_key = None self.cache = OmgwtfnzbsCache(self) self.url = 'https://omgwtfnzbs.org/' self.supportsBacklog = True def isEnabled(self): - return sickbeard.OMGWTFNZBS + return self.enabled def _checkAuth(self): - if not sickbeard.OMGWTFNZBS_USERNAME or not sickbeard.OMGWTFNZBS_APIKEY: + if not self.username or not self.api_key: raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.") return True @@ -98,8 +101,8 @@ class OmgwtfnzbsProvider(generic.NZBProvider): self._checkAuth() - params = {'user': sickbeard.OMGWTFNZBS_USERNAME, - 'api': sickbeard.OMGWTFNZBS_APIKEY, + params = {'user': self.username, + 'api': self.api_key, 'eng': 1, 'catid': '19,20', # SD,HD 'retention': sickbeard.USENET_RETENTION, @@ -155,8 +158,8 @@ class OmgwtfnzbsCache(tvcache.TVCache): self.minTime = 20 def _getRSSData(self): - params = {'user': sickbeard.OMGWTFNZBS_USERNAME, - 'api': sickbeard.OMGWTFNZBS_APIKEY, + params = {'user': provider.username, + 'api': provider.api_key, 'eng': 1, 'catid': '19,20'} # SD,HD diff --git a/sickbeard/providers/womble.py b/sickbeard/providers/womble.py index 719c7209..aaf05254 100644 --- a/sickbeard/providers/womble.py +++ b/sickbeard/providers/womble.py @@ -26,11 +26,12 @@ from sickbeard import tvcache class WombleProvider(generic.NZBProvider): def __init__(self): generic.NZBProvider.__init__(self, "Womble's Index") + self.enabled = False self.cache = WombleCache(self) self.url = 'http://newshost.co.za/' def isEnabled(self): - return sickbeard.WOMBLE + return self.enabled class WombleCache(tvcache.TVCache): diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 01690007..1430d838 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1562,11 +1562,13 @@ class ConfigProviders: provider_list.append(curProvider) # dynamically set providers enabled/disabled - for provider in sickbeard.providers.sortedProviderList(): + providers = sickbeard.providers.sortedProviderList() + for provider in providers: if provider.getID() != curProvider or not hasattr(provider, 'enabled'): continue provider.enabled = curEnabled + break # dynamically load provider settings for curTorrentProvider in [curProvider for curProvider in sickbeard.providers.sortedProviderList() if @@ -1656,8 +1658,20 @@ class ConfigProviders: except: curTorrentProvider.backlog_only = 0 - sickbeard.OMGWTFNZBS_USERNAME = kwargs['omgwtfnzbs_username'].strip() - sickbeard.OMGWTFNZBS_APIKEY = kwargs['omgwtfnzbs_apikey'].strip() + for curNzbProvider in [curProvider for curProvider in sickbeard.providers.sortedProviderList() if + curProvider.providerType == sickbeard.GenericProvider.NZB]: + + if hasattr(curNzbProvider, 'api_key'): + try: + curNzbProvider.api_key = str(kwargs[curNzbProvider.getID() + '_api_key']).strip() + except: + curNzbProvider.api_key = None + + if hasattr(curNzbProvider, 'username'): + try: + curNzbProvider.username = str(kwargs[curNzbProvider.getID() + '_username']).strip() + except: + curNzbProvider.username = None sickbeard.NEWZNAB_DATA = '!!!'.join([x.configStr() for x in sickbeard.newznabProviderList]) sickbeard.PROVIDER_ORDER = provider_list