From 32e57ade1511a62f96f839203b3664bf644610fe Mon Sep 17 00:00:00 2001 From: Jesse Mullan Date: Sat, 1 Nov 2014 15:29:57 -0700 Subject: [PATCH] Fix more config saving options --- data/interfaces/default/config.html | 43 +++++++++++----------- headphones/config.py | 4 ++- headphones/searcher.py | 12 +++---- headphones/webserve.py | 55 ++++++++++++++++++++++------- 4 files changed, 73 insertions(+), 41 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index beb3697a..5da01780 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -86,7 +86,7 @@
API
- + @@ -414,7 +414,8 @@
Headphones Indexer
- + +
@@ -434,7 +435,7 @@
Custom Newznab Providers
- +
@@ -488,7 +489,7 @@
NZBs.org
- +
@@ -500,7 +501,7 @@
omgwtfnzbs
- +
@@ -521,7 +522,7 @@
The Pirate Bay
- +
@@ -538,7 +539,7 @@
Kick Ass Torrents
- +
@@ -555,7 +556,7 @@
Waffles.fm
- +
@@ -576,7 +577,7 @@
rutracker.org
- +
@@ -597,7 +598,7 @@
What.cd
- +
@@ -618,7 +619,7 @@
Mininova
- +
@@ -2031,16 +2032,16 @@ }); initActions(); initConfigCheckbox("#headphones_indexer"); - initConfigCheckbox("#usenewznab"); - initConfigCheckbox("#usenzbsorg"); - initConfigCheckbox("#useomgwtfnzbs"); - initConfigCheckbox("#usekat"); - initConfigCheckbox("#usepiratebay"); - initConfigCheckbox("#usemininova"); - initConfigCheckbox("#usewaffles"); - initConfigCheckbox("#userutracker"); - initConfigCheckbox("#usewhatcd"); - initConfigCheckbox("#useapi"); + initConfigCheckbox("#use_newznab"); + initConfigCheckbox("#use_nzbsorg"); + initConfigCheckbox("#use_omgwtfnzbs"); + initConfigCheckbox("#use_kat"); + initConfigCheckbox("#use_piratebay"); + initConfigCheckbox("#use_mininova"); + initConfigCheckbox("#use_waffles"); + initConfigCheckbox("#use_rutracker"); + initConfigCheckbox("#use_whatcd"); + initConfigCheckbox("#api_enabled"); initConfigCheckbox("#enable_https"); diff --git a/headphones/config.py b/headphones/config.py index eb152a8c..a1bb552d 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -316,8 +316,10 @@ class Config(object): def add_extra_newznab(self, newznab): """ Add a new extra newznab """ + extra_newznabs = self.EXTRA_NEWZNABS for item in newznab: - self.EXTRA_NEWZNABS.append(item) + extra_newznabs.append(item) + self.EXTRA_NEWZNABS = extra_newznabs def __getattr__(self, name): """ diff --git a/headphones/searcher.py b/headphones/searcher.py index a9067be5..c2ad11df 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -148,17 +148,17 @@ def get_seed_ratio(provider): """ if provider == 'rutracker.org': - seed_ratio = headphones.RUTRACKER_RATIO + seed_ratio = headphones.CONFIG.RUTRACKER_RATIO elif provider == 'Kick Ass Torrents': - seed_ratio = headphones.KAT_RATIO + seed_ratio = headphones.CONFIG.KAT_RATIO elif provider == 'What.cd': - seed_ratio = headphones.WHATCD_RATIO + seed_ratio = headphones.CONFIG.WHATCD_RATIO elif provider == 'The Pirate Bay': - seed_ratio = headphones.PIRATEBAY_RATIO + seed_ratio = headphones.CONFIG.PIRATEBAY_RATIO elif provider == 'Waffles.fm': - seed_ratio = headphones.WAFFLES_RATIO + seed_ratio = headphones.CONFIG.WAFFLES_RATIO elif provider == 'Mininova': - seed_ratio = headphones.MININOVA_RATIO + seed_ratio = headphones.CONFIG.MININOVA_RATIO else: seed_ratio = None diff --git a/headphones/webserve.py b/headphones/webserve.py index 22b1a65f..c977fc2e 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1170,18 +1170,45 @@ class WebInterface(object): def configUpdate(self, **kwargs): # Handle the variable config options. Note - keys with False values aren't getting passed - headphones.CONFIG.clear_extra_newznabs() - for kwarg in kwargs: - if kwarg.startswith('newznab_host'): - newznab_number = kwarg[12:] - if len(newznab_number): - newznab_host = kwargs.get('newznab_host' + newznab_number) - newznab_api = kwargs.get('newznab_api' + newznab_number) - try: - newznab_enabled = int(kwargs.get('newznab_enabled' + newznab_number)) - except KeyError: - newznab_enabled = 0 - headphones.CONFIG.add_extra_newznab((newznab_host, newznab_api, newznab_enabled)) + + checked_configs = [ + "launch_browser", "enable_https", "api_enabled", "use_blackhole", "headphones_indexer", "use_newznab", "newznab_enabled", + "use_nzbsorg", "use_omgwtfnzbs", "use_kat", "use_piratebay", "use_mininova", "use_waffles", "use_rutracker", "use_whatcd", + "preferred_bitrate_allow_lossless", "detect_bitrate", "freeze_db", "move_files", "rename_files", "correct_metadata", + "cleanup_files", "keep_nfo", "add_album_art", "embed_album_art", "embed_lyrics", "replace_existing_folders", "file_underscores", + "include_extras", "autowant_upcoming", "autowant_all", "autowant_manually_added", "keep_torrent_files", "music_encoder", + "encoderlossless", "encoder_multicore", "delete_lossless_files", "growl_enabled", "growl_onsnatch", "prowl_enabled", + "prowl_onsnatch", "xbmc_enabled", "xbmc_update", "xbmc_notify", "lms_enabled", "plex_enabled", "plex_update", "plex_notify", + "nma_enabled", "nma_onsnatch", "pushalot_enabled", "pushalot_onsnatch", "synoindex_enabled", "pushover_enabled", + "pushover_onsnatch", "pushbullet_enabled", "pushbullet_onsnatch", "subsonic_enabled", "twitter_enabled", "twitter_onsnatch", + "osx_notify_enabled", "osx_notify_onsnatch", "boxcar_enabled", "boxcar_onsnatch", "songkick_enabled", "songkick_filter_enabled", + "mpc_enabled" + ] + for checked_config in checked_configs: + if checked_config not in kwargs: + # checked items should be zero or one. if they were not sent then the item was not checked + kwargs[checked_config] = 0 + + for plain_config, use_config in [(x[4:], x) for x in kwargs if x.startswith('use_')]: + # the use prefix is fairly nice in the html, but does not match the actual config + kwargs[plain_config] = kwargs[use_config] + del kwargs[use_config] + + extra_newznabs = [] + for kwarg in [x for x in kwargs if x.startswith('newznab_host')]: + newznab_host_key = kwarg + newznab_number = kwarg[12:] + if len(newznab_number): + newznab_api_key = 'newznab_api' + newznab_number + newznab_enabled_key = 'newznab_enabled' + newznab_number + newznab_host = kwargs.get(newznab_host_key, '') + newznab_api = kwargs.get(newznab_api_key, '') + newznab_enabled = int(kwargs.get(newznab_enabled_key, 0)) + for key in [newznab_host_key, newznab_api_key, newznab_enabled_key]: + if key in kwargs: + del kwargs[key] + extra_newznabs.append((newznab_host, newznab_api, newznab_enabled)) + # Convert the extras to list then string. Coming in as 0 or 1 (append new extras to the end) temp_extras_list = [] @@ -1208,8 +1235,10 @@ class WebInterface(object): del kwargs[extra] headphones.CONFIG.EXTRAS = ','.join(str(n) for n in temp_extras_list) - + headphones.CONFIG.clear_extra_newznabs() headphones.CONFIG.process_kwargs(kwargs) + for extra_newznab in extra_newznabs: + headphones.CONFIG.add_extra_newznab(extra_newznab) # Sanity checking if headphones.CONFIG.SEARCH_INTERVAL < 360: