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/headphones/__init__.py b/headphones/__init__.py
index 2da69469..2d99b679 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, \
@@ -349,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)
@@ -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')
@@ -515,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....')
@@ -749,7 +768,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..1f03aca7 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/bin/ffmpeg.exe"
+ else:
+ encoder="ffmpeg"
i=0
for music in musicFiles:
diff --git a/headphones/searcher.py b/headphones/searcher.py
index 7e61d937..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
@@ -476,11 +481,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])
@@ -525,7 +530,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()
diff --git a/headphones/webserve.py b/headphones/webserve.py
index 4e04246f..f7b52f01 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
@@ -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()