diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 29727398..09b3e014 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -227,7 +227,7 @@ -



Torrent:


+

Torrent:


@@ -420,17 +420,33 @@

Path to Encoder:

- -

Prowl Notification:

-
-

Enabled Prowl Notification


+ +

Prowl Notification:


+

Enable Prowl Notifications


-

API key:



+

API key:



Notify on snatch?


Priority (-2,-1,0,1 or 2):

- + + + +

Muscbrainz Mirror: diff --git a/headphones/__init__.py b/headphones/__init__.py index 9ced7560..6f0f38c0 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -11,7 +11,7 @@ from lib.configobj import ConfigObj import cherrypy -from headphones import updater, searcher, importer, versioncheck, logger, postprocessor, version, sab, librarysync +from headphones import versioncheck, logger, version from headphones.common import * FULL_PATH = None @@ -134,6 +134,8 @@ PROWL_ENABLED = True PROWL_PRIORITY = 1 PROWL_KEYS = None PROWL_ONSNATCH = True +MIRRORLIST = ["musicbrainz.org","tbueter.com","localhost"] +MIRROR = None def CheckSection(sec): """ Check if INI section exists, if not create it """ @@ -195,7 +197,7 @@ 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 + ENCODERLOSSLESS, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, MIRRORLIST, MIRROR if __INITIALIZED__: return False @@ -207,7 +209,7 @@ def initialize(): CheckSection('Newznab') CheckSection('NZBsorg') CheckSection('Newzbin') - CheckSection('Prowl') + CheckSection('Prowl') # Set global variables based on config file or use defaults try: @@ -296,10 +298,12 @@ def initialize(): ENCODERVBRCBR = check_setting_str(CFG, 'General', 'encodervbrcbr', 'cbr') ENCODERLOSSLESS = bool(check_setting_int(CFG, 'General', 'encoderlossless', 1)) - PROWL_ENABLED = bool(check_setting_int(CFG, 'Prowl', 'prowl_enabled', 0)) - PROWL_KEYS = check_setting_str(CFG, 'Prowl', 'prowl_keys', '') - PROWL_ONSNATCH = bool(check_setting_int(CFG, 'Prowl', 'prowl_onsnatch', 0)) - PROWL_PRIORITY = check_setting_int(CFG, 'Prowl', 'prowl_priority', 0) + PROWL_ENABLED = bool(check_setting_int(CFG, 'Prowl', 'prowl_enabled', 0)) + PROWL_KEYS = check_setting_str(CFG, 'Prowl', 'prowl_keys', '') + PROWL_ONSNATCH = bool(check_setting_int(CFG, 'Prowl', 'prowl_onsnatch', 0)) + PROWL_PRIORITY = check_setting_int(CFG, 'Prowl', 'prowl_priority', 0) + + MIRROR = check_setting_str(CFG, 'General', 'mirror', 'tbueter.com') if not LOG_DIR: LOG_DIR = os.path.join(DATA_DIR, 'logs') @@ -502,6 +506,8 @@ def config_write(): new_config['General']['encodervbrcbr'] = ENCODERVBRCBR new_config['General']['encoderlossless'] = ENCODERLOSSLESS + new_config['General']['mirror'] = MIRROR + new_config.write() @@ -512,6 +518,7 @@ def start(): if __INITIALIZED__: # Start our scheduled background tasks + from headphones import updater, searcher, librarysync, postprocessor SCHED.add_interval_job(updater.dbUpdate, hours=48) SCHED.add_interval_job(searcher.searchforalbum, minutes=SEARCH_INTERVAL) diff --git a/headphones/mb.py b/headphones/mb.py index 9afe0ef2..909ca7f7 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -13,9 +13,32 @@ import headphones from headphones import logger, db from headphones.helpers import multikeysort, replace_all -q = ws.Query() 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(): + + if headphones.MIRROR == "localhost": + mbhost = "localhost" + mbport = 7143 + sleepytime = 0 + elif headphones.MIRROR == "tbueter.com": + mbhost = "tbueter.com" + mbport = 3000 + sleepytime = 0 + else: + mbhost = "musicbrainz.org" + mbport = 80 + sleepytime = 1 + + service = ws.WebService(host=mbhost, port=mbport) + q = ws.Query(service) + + return (q, sleepytime) + + def findArtist(name, limit=1): with mb_lock: @@ -27,6 +50,8 @@ def findArtist(name, limit=1): chars = set('!?*') if any((c in chars) for c in name): name = '"'+name+'"' + + q, sleepytime = startmb() while attempt < 5: @@ -34,11 +59,11 @@ def findArtist(name, limit=1): artistResults = q.getArtists(ws.ArtistFilter(query=name, limit=limit)) break except WebServiceError, e: - logger.warn('Attempt to query MusicBrainz for %s failed: %s' % (name, e)) + logger.warn('Attempt to query MusicBrainz for %s failed: %s [%s:%i]' % (name, e, mbhost, mbport)) attempt += 1 time.sleep(5) - time.sleep(1) + time.sleep(sleepytime) if not artistResults: return False @@ -85,6 +110,8 @@ def findRelease(name, limit=1): chars = set('!?') if any((c in chars) for c in name): name = '"'+name+'"' + + q, sleepytime = startmb() while attempt < 5: @@ -96,7 +123,7 @@ def findRelease(name, limit=1): attempt += 1 time.sleep(5) - time.sleep(1) + time.sleep(sleepytime) if not releaseResults: return False @@ -126,6 +153,8 @@ def getArtist(artistid, extrasonly=False): artist = None attempt = 0 + q, sleepytime = startmb() + while attempt < 5: try: @@ -139,7 +168,7 @@ def getArtist(artistid, extrasonly=False): if not artist: return False - time.sleep(1) + time.sleep(sleepytime) artist_dict['artist_name'] = artist.name artist_dict['artist_sortname'] = artist.sortName @@ -215,6 +244,8 @@ def getReleaseGroup(rgid): releaseGroup = None attempt = 0 + q, sleepytime = startmb() + while attempt < 5: try: @@ -228,7 +259,7 @@ def getReleaseGroup(rgid): if not releaseGroup: return False - time.sleep(1) + time.sleep(sleepytime) # I think for now we have to make separate queries for each release, in order # to get more detailed release info (ASIN, track count, etc.) for release in releaseGroup.releases: @@ -257,7 +288,7 @@ def getReleaseGroup(rgid): logger.debug('%s is not an official live album. Skipping' % releaseResult.name) continue - time.sleep(1) + time.sleep(sleepytime) formats = { '2xVinyl': '2', @@ -345,6 +376,8 @@ def getRelease(releaseid): inc = ws.ReleaseIncludes(tracks=True, releaseEvents=True, releaseGroup=True, artist=True) results = None attempt = 0 + + q, sleepytime = startmb() while attempt < 5: @@ -359,7 +392,7 @@ def getRelease(releaseid): if not results: return False - time.sleep(1) + time.sleep(sleepytime) release['title'] = results.title release['id'] = u.extractUuid(results.id) @@ -414,6 +447,8 @@ def findArtistbyAlbum(name): f = ws.ReleaseGroupFilter(query=term, limit=1) results = None attempt = 0 + + q, sleepytime = startmb() while attempt < 5: @@ -425,7 +460,7 @@ def findArtistbyAlbum(name): attempt += 1 time.sleep(5) - time.sleep(1) + time.sleep(sleepytime) if not results: return False @@ -447,6 +482,8 @@ def findAlbumID(artist=None, album=None): f = ws.ReleaseGroupFilter(title=album, artistName=artist, limit=1) results = None attempt = 0 + + q, sleepytime = startmb() while attempt < 5: @@ -458,10 +495,10 @@ def findAlbumID(artist=None, album=None): attempt += 1 time.sleep(5) - time.sleep(1) + time.sleep(sleepytime) if not results: return False rgid = u.extractUuid(results[0].releaseGroup.id) - return rgid \ No newline at end of file + return rgid diff --git a/headphones/updater.py b/headphones/updater.py index a7cd3b95..4ca14e3b 100644 --- a/headphones/updater.py +++ b/headphones/updater.py @@ -1,6 +1,6 @@ import headphones -from headphones import logger, db, mb, importer +from headphones import logger, db, importer def dbUpdate(): @@ -15,4 +15,4 @@ def dbUpdate(): artistid = artist[0] importer.addArtisttoDB(artistid) - logger.info('Update complete') \ No newline at end of file + logger.info('Update complete') diff --git a/headphones/webserve.py b/headphones/webserve.py index c9386c64..951c4b4d 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -382,7 +382,9 @@ class WebInterface(object): "prowl_enabled": checked(headphones.PROWL_ENABLED), "prowl_onsnatch": checked(headphones.PROWL_ONSNATCH), "prowl_keys": headphones.PROWL_KEYS, - "prowl_priority": headphones.PROWL_PRIORITY + "prowl_priority": headphones.PROWL_PRIORITY, + "mirror_list": headphones.MIRRORLIST, + "mirror": headphones.MIRROR } return serve_template(templatename="config.html", title="Settings", config=config) config.exposed = True @@ -395,7 +397,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): + prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, mirror=None): headphones.HTTP_HOST = http_host headphones.HTTP_PORT = http_port @@ -459,6 +461,7 @@ class WebInterface(object): headphones.PROWL_ONSNATCH = prowl_onsnatch headphones.PROWL_KEYS = prowl_keys headphones.PROWL_PRIORITY = prowl_priority + headphones.MIRROR = mirror headphones.config_write()