From 7c482b3604e668ff638db56c18a3fe965c2d1485 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 5 Dec 2012 03:02:24 -0500 Subject: [PATCH 1/6] Don't append the mbid onour downloads since we already know the folder name --- headphones/searcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index 7e61d937..41d5bb7f 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -525,7 +525,7 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): if data and bestqual: logger.info(u'Found best result: %s - %s' % (bestqual[2], bestqual[0], helpers.bytes_to_mb(bestqual[1]))) # Get rid of any dodgy chars here so we can prevent sab from renaming our downloads - nzb_folder_name = helpers.sab_sanitize_foldername(bestqual[0]) + '.' + albums[2] + nzb_folder_name = helpers.sab_sanitize_foldername(bestqual[0]) if headphones.SAB_HOST and not headphones.BLACKHOLE: nzb = classes.NZBDataSearchResult() From 3b757cfce0a83e1fceb687eb04ea3cdfe2489fc2 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 5 Dec 2012 05:06:49 -0500 Subject: [PATCH 2/6] Fixed the encoder adding 'lame', 'ffmpeg', 'xld' to the end of the encoder path which was breaking encoding on windows. Also prevent Headphones from daemonizing under Windows --- Headphones.py | 5 ++++- data/interfaces/default/config.html | 2 +- headphones/__init__.py | 20 +++++++++++++++++--- headphones/music_encoder.py | 23 +++++++++++++++-------- headphones/webserve.py | 4 ++-- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Headphones.py b/Headphones.py index a3896a0f..1982818d 100644 --- a/Headphones.py +++ b/Headphones.py @@ -109,7 +109,10 @@ def main(): headphones.initialize() if headphones.DAEMON: - headphones.daemonize() + if sys.platform == "win32": + print "Daemonize not supported under Windows, starting normally" + else: + headphones.daemonize() #configure the connection to the musicbrainz database headphones.mb.startmb() diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 58baf946..742ade22 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -546,7 +546,7 @@
- +
diff --git a/headphones/__init__.py b/headphones/__init__.py index 2da69469..63373819 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -169,6 +169,7 @@ FOLDER_PERMISSIONS = None MUSIC_ENCODER = False ENCODERFOLDER = None +ENCODER_PATH = None ENCODER = None XLDPROFILE = None BITRATE = None @@ -268,7 +269,7 @@ def initialize(): LIBRARYSCAN, LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS,\ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \ - ENCODERFOLDER, ENCODER, XLDPROFILE, BITRATE, SAMPLINGFREQUENCY, MUSIC_ENCODER, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, \ + ENCODERFOLDER, ENCODER_PATH, ENCODER, XLDPROFILE, BITRATE, SAMPLINGFREQUENCY, MUSIC_ENCODER, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, \ ENCODERVBRCBR, ENCODERLOSSLESS, DELETE_LOSSLESS_FILES, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, \ PUSHOVER_ENABLED, PUSHOVER_PRIORITY, PUSHOVER_KEYS, PUSHOVER_ONSNATCH, MIRRORLIST, \ MIRROR, CUSTOMHOST, CUSTOMPORT, CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, \ @@ -405,7 +406,8 @@ def initialize(): INTERFACE = check_setting_str(CFG, 'General', 'interface', 'default') FOLDER_PERMISSIONS = check_setting_str(CFG, 'General', 'folder_permissions', '0755') - ENCODERFOLDER = check_setting_str(CFG, 'General', 'encoderfolder', '') + ENCODERFOLDER = check_setting_str(CFG, 'General', 'encoderfolder', '') + ENCODER_PATH = check_setting_str(CFG, 'General', 'encoder_path', '') ENCODER = check_setting_str(CFG, 'General', 'encoder', 'ffmpeg') XLDPROFILE = check_setting_str(CFG, 'General', 'xldprofile', '') BITRATE = check_setting_int(CFG, 'General', 'bitrate', 192) @@ -493,6 +495,18 @@ def initialize(): FOLDER_FORMAT = replace_all(FOLDER_FORMAT, folder_values) CONFIG_VERSION = '2' + + if CONFIG_VERSION == '2': + + # Update the config to use direct path to the encoder rather than the encoder folder + if ENCODERFOLDER: + if ENCODER == "xld": + ENCODER_PATH = os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING), 'xld') + elif ENCODER == "ffmpeg": + ENCODER_PATH = os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING), 'ffmpeg') + elif ENCODER == "lame": + ENCODER_PATH = os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING), 'lame') + CONFIG_VERSION = '3' if not LOG_DIR: LOG_DIR = os.path.join(DATA_DIR, 'logs') @@ -749,7 +763,7 @@ def config_write(): new_config['General']['xldprofile'] = XLDPROFILE new_config['General']['bitrate'] = int(BITRATE) new_config['General']['samplingfrequency'] = int(SAMPLINGFREQUENCY) - new_config['General']['encoderfolder'] = ENCODERFOLDER + new_config['General']['encoder_path'] = ENCODER_PATH new_config['General']['advancedencoder'] = ADVANCEDENCODER new_config['General']['encoderoutputformat'] = ENCODEROUTPUTFORMAT new_config['General']['encoderquality'] = ENCODERQUALITY diff --git a/headphones/music_encoder.py b/headphones/music_encoder.py index 4e057e20..f0ede2bd 100644 --- a/headphones/music_encoder.py +++ b/headphones/music_encoder.py @@ -85,15 +85,22 @@ def encode(albumPath): musicTemp = os.path.normpath(os.path.splitext(music)[0] + '.' + encoderFormat) musicTempFiles.append(os.path.join(tempDirEncode, musicTemp)) - if XLD: - if headphones.ENCODERFOLDER: - encoder = os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING), 'xld') - else: + if headphones.ENCODER_PATH: + encoder = headphones.ENCODER_PATH.encode(headphones.SYS_ENCODING) + else: + if XLD: encoder = os.path.join('/Applications', 'xld') - elif headphones.ENCODER=='lame': - encoder=os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING),'lame') - elif headphones.ENCODER=='ffmpeg': - encoder=os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING),'ffmpeg') + elif headphones.ENCODER =='lame': + if headphones.SYS_PLATFORM == "win32": + ## NEED THE DEFAULT LAME INSTALL ON WIN! + encoder = "C:/Program Files/lame/lame.exe" + else: + encoder="lame" + elif headphones.ENCODER =='ffmpeg': + if headphones.SYS_PLATFORM == "win32": + encoder = "C:/Program Files/ffmpeg/ffmpeg.exe" + else: + encoder="ffmpeg" i=0 for music in musicFiles: diff --git a/headphones/webserve.py b/headphones/webserve.py index 4e04246f..813416b6 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -626,7 +626,7 @@ class WebInterface(object): "encoder": headphones.ENCODER, "xldprofile": headphones.XLDPROFILE, "bitrate": int(headphones.BITRATE), - "encoderfolder": headphones.ENCODERFOLDER, + "encoderfolder": headphones.ENCODER_PATH, "advancedencoder": headphones.ADVANCEDENCODER, "encoderoutputformat": headphones.ENCODEROUTPUTFORMAT, "samplingfrequency": headphones.SAMPLINGFREQUENCY, @@ -770,7 +770,7 @@ class WebInterface(object): headphones.XLDPROFILE = xldprofile headphones.BITRATE = int(bitrate) headphones.SAMPLINGFREQUENCY = int(samplingfrequency) - headphones.ENCODERFOLDER = encoderfolder + headphones.ENCODER_PATH = encoderfolder headphones.ADVANCEDENCODER = advancedencoder headphones.ENCODEROUTPUTFORMAT = encoderoutputformat headphones.ENCODERVBRCBR = encodervbrcbr From c2bd06e685eddd31431e7c0491edab59f705e3f3 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 5 Dec 2012 22:34:36 -0500 Subject: [PATCH 3/6] Updated fmpeg path on windows, took out the 'Optional' from the Path to Encoder on config page just to avoid some confusion --- data/interfaces/default/config.html | 2 +- headphones/music_encoder.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 742ade22..58baf946 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -546,7 +546,7 @@
- +
diff --git a/headphones/music_encoder.py b/headphones/music_encoder.py index f0ede2bd..1f03aca7 100644 --- a/headphones/music_encoder.py +++ b/headphones/music_encoder.py @@ -98,7 +98,7 @@ def encode(albumPath): encoder="lame" elif headphones.ENCODER =='ffmpeg': if headphones.SYS_PLATFORM == "win32": - encoder = "C:/Program Files/ffmpeg/ffmpeg.exe" + encoder = "C:/Program Files/ffmpeg/bin/ffmpeg.exe" else: encoder="ffmpeg" From ae687716579fe1095d9378b825a15d756b97eebe Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 8 Dec 2012 21:16:32 -0500 Subject: [PATCH 4/6] Typos --- headphones/searcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index 41d5bb7f..4b77479b 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -476,11 +476,11 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): for result in resultlist: if high_size_limit and (result[1] > high_size_limit): - logger.info(result[0] + "is too large for this album - not considering it. (Size: " + helpers.bytes_to_mb(result[1]) + ", Maxsize: " + helpers.bytes_to_mb(high_size_limit)) + logger.info(result[0] + " is too large for this album - not considering it. (Size: " + helpers.bytes_to_mb(result[1]) + ", Maxsize: " + helpers.bytes_to_mb(high_size_limit)) continue if low_size_limit and (result[1] < low_size_limit): - logger.info(result[0] + "is too small for this album - not considering it. (Size: " + helpers.bytes_to_mb(result[1]) + ", Minsize: " + helpers.bytes_to_mb(low_size_limit)) + logger.info(result[0] + " is too small for this album - not considering it. (Size: " + helpers.bytes_to_mb(result[1]) + ", Minsize: " + helpers.bytes_to_mb(low_size_limit)) continue delta = abs(targetsize - result[1]) From 875c3e1393fd0a390c58c595690a3869954b1454 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 8 Dec 2012 21:29:45 -0500 Subject: [PATCH 5/6] Added minimum search interval time of 6 hours --- headphones/__init__.py | 7 ++++++- headphones/webserve.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/headphones/__init__.py b/headphones/__init__.py index 63373819..2d99b679 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -350,7 +350,7 @@ def initialize(): AUTOWANT_UPCOMING = bool(check_setting_int(CFG, 'General', 'autowant_upcoming', 1)) AUTOWANT_ALL = bool(check_setting_int(CFG, 'General', 'autowant_all', 0)) - SEARCH_INTERVAL = check_setting_int(CFG, 'General', 'search_interval', 360) + SEARCH_INTERVAL = check_setting_int(CFG, 'General', 'search_interval', 1440) LIBRARYSCAN = bool(check_setting_int(CFG, 'General', 'libraryscan', 1)) LIBRARYSCAN_INTERVAL = check_setting_int(CFG, 'General', 'libraryscan_interval', 300) DOWNLOAD_SCAN_INTERVAL = check_setting_int(CFG, 'General', 'download_scan_interval', 5) @@ -529,6 +529,11 @@ def initialize(): os.makedirs(CACHE_DIR) except OSError: logger.error('Could not create cache dir. Check permissions of datadir: ' + DATA_DIR) + + # Sanity check for search interval. Set it to at least 6 hours + if SEARCH_INTERVAL < 360: + logger.info("Search interval too low. Resetting to 6 hour minimum") + SEARCH_INTERVAL = 360 # Initialize the database logger.info('Checking to see if the database has all tables....') diff --git a/headphones/webserve.py b/headphones/webserve.py index 813416b6..f7b52f01 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -832,6 +832,11 @@ class WebInterface(object): headphones.EXTRAS = ','.join(str(n) for n in temp_extras_list) + # Sanity checking + if headphones.SEARCH_INTERVAL < 360: + logger.info("Search interval too low. Resetting to 6 hour minimum") + headphones.SEARCH_INTERVAL = 360 + # Write the config headphones.config_write() From 76c828dc3f31323b66838740ba9d163653db0903 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 8 Dec 2012 22:19:47 -0500 Subject: [PATCH 6/6] Add user-agent for newznab providers --- headphones/searcher.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index 4b77479b..bbe14128 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -274,12 +274,17 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): } searchURL = newznab_host[0] + '/api?' + urllib.urlencode(params) - + + # Add a user-agent + request = urllib2.Request(searchURL) + request.add_header('User-Agent', 'headphones/0.0 +https://github.com/rembo10/headphones') + opener = urllib2.build_opener() + logger.info(u'Parsing results from %s' % (searchURL, newznab_host[0])) try: - data = urllib2.urlopen(searchURL, timeout=20).read() - except urllib2.URLError, e: + data = opener.open(request).read() + except Exception, e: logger.warn('Error fetching data from %s: %s' % (newznab_host[0], e)) data = False