diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html
index f77bf985..bf9790d8 100644
--- a/data/interfaces/default/config.html
+++ b/data/interfaces/default/config.html
@@ -350,6 +350,10 @@
Preferred Bitrate: kbps
Reject if
less than % or
more than % of the target size (leave blank for no limit)
+
+
+
+
diff --git a/headphones/__init__.py b/headphones/__init__.py
index 6a4421a9..dbf1c384 100644
--- a/headphones/__init__.py
+++ b/headphones/__init__.py
@@ -96,6 +96,7 @@ PREFERRED_QUALITY = None
PREFERRED_BITRATE = None
PREFERRED_BITRATE_HIGH_BUFFER = None
PREFERRED_BITRATE_LOW_BUFFER = None
+PREFERRED_BITRATE_ALLOW_LOSSLESS = False
DETECT_BITRATE = False
ADD_ARTISTS = False
CORRECT_METADATA = False
@@ -284,7 +285,7 @@ def initialize():
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, \
XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, SYNOINDEX_ENABLED, ALBUM_COMPLETION_PCT, PREFERRED_BITRATE_HIGH_BUFFER, \
- PREFERRED_BITRATE_LOW_BUFFER,CACHE_SIZEMB
+ PREFERRED_BITRATE_LOW_BUFFER, PREFERRED_BITRATE_ALLOW_LOSSLESS, CACHE_SIZEMB
if __INITIALIZED__:
return False
@@ -344,6 +345,7 @@ def initialize():
PREFERRED_BITRATE = check_setting_str(CFG, 'General', 'preferred_bitrate', '')
PREFERRED_BITRATE_HIGH_BUFFER = check_setting_int(CFG, 'General', 'preferred_bitrate_high_buffer', '')
PREFERRED_BITRATE_LOW_BUFFER = check_setting_int(CFG, 'General', 'preferred_bitrate_low_buffer', '')
+ PREFERRED_BITRATE_ALLOW_LOSSLESS = bool(check_setting_int(CFG, 'General', 'preferred_bitrate_allow_lossless', 0))
DETECT_BITRATE = bool(check_setting_int(CFG, 'General', 'detect_bitrate', 0))
ADD_ARTISTS = bool(check_setting_int(CFG, 'General', 'auto_add_artists', 1))
CORRECT_METADATA = bool(check_setting_int(CFG, 'General', 'correct_metadata', 0))
@@ -666,6 +668,7 @@ def config_write():
new_config['General']['preferred_bitrate'] = PREFERRED_BITRATE
new_config['General']['preferred_bitrate_high_buffer'] = PREFERRED_BITRATE_HIGH_BUFFER
new_config['General']['preferred_bitrate_low_buffer'] = PREFERRED_BITRATE_LOW_BUFFER
+ new_config['General']['preferred_bitrate_allow_lossless'] = int(PREFERRED_BITRATE_ALLOW_LOSSLESS)
new_config['General']['detect_bitrate'] = int(DETECT_BITRATE)
new_config['General']['auto_add_artists'] = int(ADD_ARTISTS)
new_config['General']['correct_metadata'] = int(CORRECT_METADATA)
diff --git a/headphones/searcher.py b/headphones/searcher.py
index a1911137..272c16df 100644
--- a/headphones/searcher.py
+++ b/headphones/searcher.py
@@ -584,6 +584,7 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
else:
logger.info('Target size: %s' % helpers.bytes_to_mb(targetsize))
newlist = []
+ flac_list = []
if headphones.PREFERRED_BITRATE_HIGH_BUFFER:
high_size_limit = targetsize * int(headphones.PREFERRED_BITRATE_HIGH_BUFFER)/100
@@ -598,6 +599,11 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
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))
+
+ # Add lossless nzbs to the "flac list" which we can use if there are no good lossy matches
+ if 'flac' in result[0].lower():
+ flac_list.append((result[0], result[1], result[2], result[3]))
+
continue
if low_size_limit and (result[1] < low_size_limit):
@@ -608,6 +614,11 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
newlist.append((result[0], result[1], result[2], result[3], delta))
nzblist = sorted(newlist, key=lambda title: title[4])
+
+ if not len(nzblist) and len(flac_list) and headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS:
+ logger.info("Since there were no appropriate lossy matches, going to use lossless instead")
+ nzblist = sorted(flac_list, key=lambda title: title[1], reverse=True)
+
except Exception, e:
diff --git a/headphones/webserve.py b/headphones/webserve.py
index 8bee2eb9..8eeb982f 100644
--- a/headphones/webserve.py
+++ b/headphones/webserve.py
@@ -617,6 +617,7 @@ class WebInterface(object):
"pref_bitrate" : headphones.PREFERRED_BITRATE,
"pref_bitrate_high" : headphones.PREFERRED_BITRATE_HIGH_BUFFER,
"pref_bitrate_low" : headphones.PREFERRED_BITRATE_LOW_BUFFER,
+ "pref_bitrate_allow_lossless" : checked(headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS),
"detect_bitrate" : checked(headphones.DETECT_BITRATE),
"move_files" : checked(headphones.MOVE_FILES),
"rename_files" : checked(headphones.RENAME_FILES),
@@ -708,7 +709,7 @@ class WebInterface(object):
delete_lossless_files=0, prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, xbmc_enabled=0, xbmc_host=None, xbmc_username=None, xbmc_password=None,
xbmc_update=0, xbmc_notify=0, nma_enabled=False, nma_apikey=None, nma_priority=0, nma_onsnatch=0, synoindex_enabled=False,
pushover_enabled=0, pushover_onsnatch=0, pushover_keys=None, pushover_priority=0, mirror=None, customhost=None, customport=None,
- customsleep=None, hpuser=None, hppass=None, preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, cache_sizemb=None, **kwargs):
+ customsleep=None, hpuser=None, hppass=None, preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, preferred_bitrate_allow_lossless=0, cache_sizemb=None, **kwargs):
headphones.HTTP_HOST = http_host
headphones.HTTP_PORT = http_port
@@ -765,6 +766,7 @@ class WebInterface(object):
headphones.PREFERRED_BITRATE = preferred_bitrate
headphones.PREFERRED_BITRATE_HIGH_BUFFER = preferred_bitrate_high_buffer
headphones.PREFERRED_BITRATE_LOW_BUFFER = preferred_bitrate_low_buffer
+ headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS = preferred_bitrate_allow_lossless
headphones.DETECT_BITRATE = detect_bitrate
headphones.MOVE_FILES = move_files
headphones.CORRECT_METADATA = correct_metadata