From 6f3c8c68d4b3a5dc4d790460f70f2d62ada6da35 Mon Sep 17 00:00:00 2001 From: Ade Date: Sat, 10 May 2014 18:53:58 +1200 Subject: [PATCH] Lossless min/max filter filter results if calculated target size outside bitrate range --- data/interfaces/default/config.html | 26 +++++++++++++++++++++++--- headphones/__init__.py | 8 +++++++- headphones/searcher.py | 28 ++++++++++++++++++++++++++++ headphones/webserve.py | 8 ++++++-- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index d38fa710..9e48eadb 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -470,7 +470,14 @@
- + +
+ + Reject if target size is not in bitrate range: \ + to\ + kbps + +
Preferred Bitrate: kbps
Reject if less than % or more than % of the target size (leave blank for no limit)

@@ -1587,6 +1594,15 @@ } }); + if ($("#lossless_only").is(":checked")) + { + $("#lossless_only_options").show(); + } + else + { + $("#lossless_only_options").hide(); + } + if ($("#preferred_bitrate").is(":checked")) { $("#preferred_bitrate_options").show(); @@ -1632,18 +1648,22 @@ if ($("#preferred_bitrate").is(":checked")) { $("#preferred_bitrate_options").slideDown("fast"); + $("#lossless_only_options").slideUp("fast"); } if ($("#preferred_quality0").is(":checked")) { $("#preferred_bitrate_options").slideUp("fast"); + $("#lossless_only_options").slideUp("fast"); } if ($("#preferred_quality1").is(":checked")) { $("#preferred_bitrate_options").slideUp("fast"); + $("#lossless_only_options").slideUp("fast"); } - if ($("#preferred_quality3").is(":checked")) + if ($("#lossless_only").is(":checked")) { - $("#preferred_bitrate_options").slideUp("fast"); + $("#lossless_only_options").slideDown("fast"); + $("#preferred_bitrate_options").slideUp("fast"); } if ($("#nzb_downloader_sabnzbd").is(":checked")) { diff --git a/headphones/__init__.py b/headphones/__init__.py index 380a31bf..4a9ab38f 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -103,6 +103,8 @@ PREFERRED_BITRATE_HIGH_BUFFER = None PREFERRED_BITRATE_LOW_BUFFER = None PREFERRED_BITRATE_ALLOW_LOSSLESS = False DETECT_BITRATE = False +LOSSLESS_BITRATE_FROM = None +LOSSLESS_BITRATE_TO = None ADD_ARTISTS = False CORRECT_METADATA = False MOVE_FILES = False @@ -358,7 +360,7 @@ def initialize(): PUSHBULLET_ENABLED, PUSHBULLET_APIKEY, PUSHBULLET_DEVICEID, PUSHBULLET_ONSNATCH, \ MIRROR, CUSTOMHOST, CUSTOMPORT, CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, \ XBMC_NOTIFY, LMS_ENABLED, LMS_HOST, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, SYNOINDEX_ENABLED, ALBUM_COMPLETION_PCT, PREFERRED_BITRATE_HIGH_BUFFER, \ - PREFERRED_BITRATE_LOW_BUFFER, PREFERRED_BITRATE_ALLOW_LOSSLESS, CACHE_SIZEMB, JOURNAL_MODE, UMASK, ENABLE_HTTPS, HTTPS_CERT, HTTPS_KEY, \ + PREFERRED_BITRATE_LOW_BUFFER, PREFERRED_BITRATE_ALLOW_LOSSLESS, LOSSLESS_BITRATE_FROM, LOSSLESS_BITRATE_TO, CACHE_SIZEMB, JOURNAL_MODE, UMASK, ENABLE_HTTPS, HTTPS_CERT, HTTPS_KEY, \ PLEX_ENABLED, PLEX_SERVER_HOST, PLEX_CLIENT_HOST, PLEX_USERNAME, PLEX_PASSWORD, PLEX_UPDATE, PLEX_NOTIFY, PUSHALOT_ENABLED, PUSHALOT_APIKEY, \ PUSHALOT_ONSNATCH, SONGKICK_ENABLED, SONGKICK_APIKEY, SONGKICK_LOCATION, SONGKICK_FILTER_ENABLED @@ -438,6 +440,8 @@ def initialize(): 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)) + LOSSLESS_BITRATE_FROM = check_setting_int(CFG, 'General', 'lossless_bitrate_from', '') + LOSSLESS_BITRATE_TO = check_setting_int(CFG, 'General', 'lossless_bitrate_to', '') ADD_ARTISTS = bool(check_setting_int(CFG, 'General', 'auto_add_artists', 1)) CORRECT_METADATA = bool(check_setting_int(CFG, 'General', 'correct_metadata', 0)) MOVE_FILES = bool(check_setting_int(CFG, 'General', 'move_files', 0)) @@ -862,6 +866,8 @@ def config_write(): 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']['lossless_bitrate_from'] = LOSSLESS_BITRATE_FROM + new_config['General']['lossless_bitrate_to'] = LOSSLESS_BITRATE_TO new_config['General']['auto_add_artists'] = int(ADD_ARTISTS) new_config['General']['correct_metadata'] = int(CORRECT_METADATA) new_config['General']['move_files'] = int(MOVE_FILES) diff --git a/headphones/searcher.py b/headphones/searcher.py index 1cc78b84..8c2a699d 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -218,6 +218,34 @@ def sort_search_results(resultlist, album, new): finallist = sorted(resultlist, key=lambda title: (title[5], int(title[1])), reverse=True) + # lossless - ignore results if target size outside bitrate range + elif headphones.PREFERRED_QUALITY == 3 and (headphones.LOSSLESS_BITRATE_FROM or headphones.LOSSLESS_BITRATE_TO): + + finallist = [] + tracks = myDB.select('SELECT TrackDuration from tracks WHERE AlbumID=?', [album['AlbumID']]) + + if len(tracks): + + albumlength = sum([pair[0] for pair in tracks]) + mintargetsize = 0 + maxtargetsize = 0 + if headphones.LOSSLESS_BITRATE_FROM: + mintargetsize = albumlength/1000 * int(headphones.LOSSLESS_BITRATE_FROM) * 128 + if headphones.LOSSLESS_BITRATE_TO: + maxtargetsize = albumlength/1000 * int(headphones.LOSSLESS_BITRATE_TO) * 128 + + if mintargetsize > 0 or maxtargetsize > 0: + for i, result in reversed(list(enumerate(resultlist))): + if int(result[1]) < mintargetsize and mintargetsize > 0 or int(result[1]) > maxtargetsize and maxtargetsize > 0: + if int(result[1]) < mintargetsize: + logger.info("%s is too small for this album - not considering it. (Size: %s, Minsize: %s)", result[0], helpers.bytes_to_mb(result[1]), helpers.bytes_to_mb(mintargetsize)) + else: + logger.info("%s is too large for this album - not considering it. (Size: %s, Maxsize: %s)", result[0], helpers.bytes_to_mb(result[1]), helpers.bytes_to_mb(maxtargetsize)) + del resultlist[i] + + if len (resultlist): + finallist = sorted(resultlist, key=lambda title: (title[5], int(title[1])), reverse=True) + else: finallist = sorted(resultlist, key=lambda title: (title[5], int(title[1])), reverse=True) diff --git a/headphones/webserve.py b/headphones/webserve.py index 6db4c1f3..709de4f0 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1000,6 +1000,8 @@ class WebInterface(object): "pref_bitrate_low" : headphones.PREFERRED_BITRATE_LOW_BUFFER, "pref_bitrate_allow_lossless" : checked(headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS), "detect_bitrate" : checked(headphones.DETECT_BITRATE), + "lossless_bitrate_from" : headphones.LOSSLESS_BITRATE_FROM, + "lossless_bitrate_to" : headphones.LOSSLESS_BITRATE_TO, "move_files" : checked(headphones.MOVE_FILES), "rename_files" : checked(headphones.RENAME_FILES), "correct_metadata" : checked(headphones.CORRECT_METADATA), @@ -1136,8 +1138,8 @@ class WebInterface(object): xbmc_update=0, xbmc_notify=0, nma_enabled=False, nma_apikey=None, nma_priority=0, nma_onsnatch=0, pushalot_enabled=False, pushalot_apikey=None, pushalot_onsnatch=0, synoindex_enabled=False, lms_enabled=0, lms_host=None, pushover_enabled=0, pushover_onsnatch=0, pushover_keys=None, pushover_priority=0, pushover_apitoken=None, pushbullet_enabled=0, pushbullet_onsnatch=0, pushbullet_apikey=None, pushbullet_deviceid=None, twitter_enabled=0, twitter_onsnatch=0, osx_notify_enabled=0, osx_notify_onsnatch=0, osx_notify_app=None, boxcar_enabled=0, boxcar_onsnatch=0, boxcar_token=None, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None, - preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, preferred_bitrate_allow_lossless=0, cache_sizemb=None, enable_https=0, https_cert=None, https_key=None, file_permissions=None, folder_permissions=None, - plex_enabled=0, plex_server_host=None, plex_client_host=None, plex_username=None, plex_password=None, plex_update=0, plex_notify=0, + preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, preferred_bitrate_allow_lossless=0, lossless_bitrate_from=None, lossless_bitrate_to=None, cache_sizemb=None, enable_https=0, https_cert=None, https_key=None, + file_permissions=None, folder_permissions=None, plex_enabled=0, plex_server_host=None, plex_client_host=None, plex_username=None, plex_password=None, plex_update=0, plex_notify=0, songkick_enabled=0, songkick_apikey=None, songkick_location=None, songkick_filter_enabled=0, encoder_multicore=False, encoder_multicore_count=0, mpc_enabled=False, **kwargs ): headphones.HTTP_HOST = http_host @@ -1216,6 +1218,8 @@ class WebInterface(object): headphones.PREFERRED_BITRATE_LOW_BUFFER = preferred_bitrate_low_buffer headphones.PREFERRED_BITRATE_ALLOW_LOSSLESS = preferred_bitrate_allow_lossless headphones.DETECT_BITRATE = detect_bitrate + headphones.LOSSLESS_BITRATE_FROM = lossless_bitrate_from + headphones.LOSSLESS_BITRATE_TO = lossless_bitrate_to headphones.MOVE_FILES = move_files headphones.CORRECT_METADATA = correct_metadata headphones.RENAME_FILES = rename_files