From 98a48731023fb9ea5fe2082e8e1fde522e503ddb Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 14 Mar 2012 02:41:48 +0000 Subject: [PATCH] Added custom server options to specify host & port for mb server, added username & password fields for headphones musicbrainz server --- data/interfaces/default/config.html | 48 ++++++++++++++++++++++++----- headphones/__init__.py | 20 ++++++++++-- headphones/mb.py | 19 +++++++++--- headphones/webserve.py | 14 +++++++-- 4 files changed, 85 insertions(+), 16 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 09b3e014..b74bd2a9 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -432,21 +432,29 @@ -

Muscbrainz Mirror:

%for mirror in config['mirror_list']: <% if mirror == headphones.MIRROR: selected = 'selected="selected"' else: selected = '' - if mirror == "localhost": - mirrortext = " (use localhost:7143)" - else: - mirrortext = '' %> - + %endfor + +
+

Host:

+

Port:

+

Sleep Interval:

+
+ +
+

Username:

+

Password:

+ what is this?

+
@@ -457,6 +465,27 @@ <%def name="javascriptIncludes()"> diff --git a/headphones/__init__.py b/headphones/__init__.py index 9a2d921c..4ea75404 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -134,8 +134,13 @@ PROWL_ENABLED = True PROWL_PRIORITY = 1 PROWL_KEYS = None PROWL_ONSNATCH = True -MIRRORLIST = ["musicbrainz.org","headphones","tbueter.com","localhost"] +MIRRORLIST = ["musicbrainz.org","headphones","tbueter.com","custom"] MIRROR = None +CUSTOMHOST = None +CUSTOMPORT = None +CUSTOMSLEEP = None +HPUSER = None +HPPASS = None def CheckSection(sec): """ Check if INI section exists, if not create it """ @@ -197,7 +202,8 @@ def initialize(): NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, \ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \ ENCODERFOLDER, ENCODER, BITRATE, SAMPLINGFREQUENCY, ENCODE, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRCBR, \ - ENCODERLOSSLESS, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, MIRRORLIST, MIRROR + ENCODERLOSSLESS, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, MIRRORLIST, MIRROR, CUSTOMHOST, CUSTOMPORT, \ + CUSTOMSLEEP, HPUSER, HPPASS if __INITIALIZED__: return False @@ -304,6 +310,11 @@ def initialize(): PROWL_PRIORITY = check_setting_int(CFG, 'Prowl', 'prowl_priority', 0) MIRROR = check_setting_str(CFG, 'General', 'mirror', 'headphones') + CUSTOMHOST = check_setting_str(CFG, 'General', 'customhost', 'localhost') + CUSTOMPORT = check_setting_int(CFG, 'General', 'customport', 5000) + CUSTOMSLEEP = check_setting_int(CFG, 'General', 'customsleep', 1) + HPUSER = check_setting_str(CFG, 'General', 'hpuser', 'username') + HPPASS = check_setting_str(CFG, 'General', 'hppass', 'password') if not LOG_DIR: LOG_DIR = os.path.join(DATA_DIR, 'logs') @@ -507,6 +518,11 @@ def config_write(): new_config['General']['encoderlossless'] = ENCODERLOSSLESS new_config['General']['mirror'] = MIRROR + new_config['General']['customhost'] = CUSTOMHOST + new_config['General']['customport'] = CUSTOMPORT + new_config['General']['customsleep'] = CUSTOMSLEEP + new_config['General']['hpuser'] = HPUSER + new_config['General']['hppass'] = HPPASS new_config.write() diff --git a/headphones/mb.py b/headphones/mb.py index 829d9bf9..993848da 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -19,19 +19,25 @@ mb_lock = threading.Lock() # Quick fix to add mirror switching on the fly. Need to probably return the mbhost & mbport that's # being used, so we can send those values to the log def startmb(forcemb=False): + + # just in case someone switches to the headphones server mid-query + hpuser=None + hppass=None if forcemb or headphones.MIRROR == "musicbrainz.org": mbhost = "musicbrainz.org" mbport = 80 sleepytime = 1 - elif headphones.MIRROR == "localhost": - mbhost = "localhost" - mbport = 7143 - sleepytime = 0 + elif headphones.MIRROR == "custom": + mbhost = headphones.CUSTOMHOST + mbport = headphones.CUSTOMPORT + sleepytime = headphones.CUSTOMSLEEP elif headphones.MIRROR == "headphones": mbhost = "178.63.142.150" mbport = 5000 sleepytime = 0 + hpuser = headphones.HPUSER + hppass = headphones.HPPASS else: mbhost = "tbueter.com" mbport = 5000 @@ -40,8 +46,11 @@ def startmb(forcemb=False): service = ws.WebService(host=mbhost, port=mbport) q = ws.Query(service) - return (q, sleepytime) + logger.debug('Using the following server values:\nMBHost: %s ; MBPort: %i ; Sleep Interval: %i ' % (mbhost, mbport, sleepytime)) + if headphones.MIRROR == "headphones": + logger.debug('Headphones Username: %s ; Headphones Password: %s ' % (hpuser, len(hppass) * '*')) + return (q, sleepytime) def findArtist(name, limit=1): diff --git a/headphones/webserve.py b/headphones/webserve.py index 951c4b4d..561bf15d 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -384,7 +384,12 @@ class WebInterface(object): "prowl_keys": headphones.PROWL_KEYS, "prowl_priority": headphones.PROWL_PRIORITY, "mirror_list": headphones.MIRRORLIST, - "mirror": headphones.MIRROR + "mirror": headphones.MIRROR, + "customhost": headphones.CUSTOMHOST, + "customport": headphones.CUSTOMPORT, + "customsleep": headphones.CUSTOMSLEEP, + "hpuser": headphones.HPUSER, + "hppass": headphones.HPPASS } return serve_template(templatename="config.html", title="Settings", config=config) config.exposed = True @@ -397,7 +402,7 @@ class WebInterface(object): torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=10, use_isohunt=0, use_kat=0, use_mininova=0, rename_files=0, correct_metadata=0, cleanup_files=0, add_album_art=0, embed_album_art=0, embed_lyrics=0, destination_dir=None, folder_format=None, file_format=None, include_extras=0, interface=None, log_dir=None, encode=0, encoder=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0, - prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, mirror=None): + prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None): headphones.HTTP_HOST = http_host headphones.HTTP_PORT = http_port @@ -462,6 +467,11 @@ class WebInterface(object): headphones.PROWL_KEYS = prowl_keys headphones.PROWL_PRIORITY = prowl_priority headphones.MIRROR = mirror + headphones.CUSTOMHOST = customhost + headphones.CUSTOMPORT = customport + headphones.CUSTOMSLEEP = customsleep + headphones.HPUSER = hpuser + headphones.HPPASS headphones.config_write()