diff --git a/headphones/config.py b/headphones/config.py index 176c49cb..022ee806 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -42,6 +42,8 @@ _CONFIG_DEFINITIONS = { 'CONFIG_VERSION': (str, 'General', '0'), 'CORRECT_METADATA': (int, 'General', 0), 'CUE_SPLIT': (int, 'General', 1), + 'CUE_SPLIT_FLAC_PATH': (str, 'General', ''), + 'CUE_SPLIT_SHNTOOL_PATH': (str, 'General', ''), 'CUSTOMHOST': (str, 'General', 'localhost'), 'CUSTOMPORT': (int, 'General', 5000), 'CUSTOMSLEEP': (int, 'General', 1), diff --git a/headphones/cuesplit.py b/headphones/cuesplit.py index d2f9da7d..d9b3c7bc 100755 --- a/headphones/cuesplit.py +++ b/headphones/cuesplit.py @@ -72,11 +72,13 @@ CUE_META = None def check_splitter(command): - '''Check xld or shntools installed''' + '''Check xld or shntool installed''' try: env = os.environ.copy() if 'xld' in command: env['PATH'] += os.pathsep + '/Applications' + elif headphones.CONFIG.CUE_SPLIT_FLAC_PATH: + command = os.path.join(headphones.CONFIG.CUE_SPLIT_SHNTOOL_PATH, 'shntool') devnull = open(os.devnull) subprocess.Popen([command], stdout=devnull, stderr=devnull, env=env).communicate() except OSError as e: @@ -103,6 +105,8 @@ def split_baby(split_file, split_cmd): env = os.environ.copy() if 'xld' in split_cmd: env['PATH'] += os.pathsep + '/Applications' + elif headphones.CONFIG.CUE_SPLIT_FLAC_PATH: + env['PATH'] += os.pathsep + headphones.CONFIG.CUE_SPLIT_FLAC_PATH process = subprocess.Popen(split_cmd, startupinfo=startupinfo, @@ -588,9 +592,9 @@ def split(albumpath): splitter = 'shntool' if splitter == 'shntool' and not check_splitter(splitter): - raise ValueError('Command not found, ensure shntools with FLAC or xld (OS X) installed') + raise ValueError('Command not found, ensure shntool with FLAC or xld (OS X) installed') - # Determine if file can be split (only flac allowed for shntools) + # Determine if file can be split (only flac allowed for shntool) if 'xld' in splitter and wave.name_ext not in WAVE_FILE_TYPE_BY_EXTENSION.keys() or \ wave.type not in SHNTOOL_COMPATIBLE: raise ValueError('Cannot split, audio file has unsupported extension') @@ -627,7 +631,11 @@ def split(albumpath): with open(SPLIT_FILE_NAME, mode='w') as split_file: split_file.write(cue.breakpoints()) - cmd = ['shntool'] + if headphones.CONFIG.CUE_SPLIT_SHNTOOL_PATH: + cmd = [os.path.join(headphones.CONFIG.CUE_SPLIT_SHNTOOL_PATH, 'shntool')] + else: + cmd = ['shntool'] + cmd.extend(['split']) cmd.extend(['-f']) cmd.extend([SPLIT_FILE_NAME]) diff --git a/headphones/webserve.py b/headphones/webserve.py index d54c3a56..075c7819 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1033,6 +1033,8 @@ class WebInterface(object): "lossless_bitrate_to": headphones.CONFIG.LOSSLESS_BITRATE_TO, "freeze_db": checked(headphones.CONFIG.FREEZE_DB), "cue_split": checked(headphones.CONFIG.CUE_SPLIT), + "cue_split_flac_path": headphones.CONFIG.CUE_SPLIT_FLAC_PATH, + "cue_split_shntool_path": headphones.CONFIG.CUE_SPLIT_SHNTOOL_PATH, "move_files": checked(headphones.CONFIG.MOVE_FILES), "rename_files": checked(headphones.CONFIG.RENAME_FILES), "correct_metadata": checked(headphones.CONFIG.CORRECT_METADATA),