dam/src/gen_image

38 lines
1.1 KiB
Bash

#!/bin/bash
# doc gen_image {
#
# DESCRIPTION
# gen_image - Generates image from list of lossless audio files
#
# USAGE
# gen_image </path/to/output/file> <file_1> [<file_2>] [<...>]
#
# DEPENDENCIES src/med_convert
#
# }
gen_image() {
local TARGET="${1}"; shift
local TARGET_DIR=$(dirname "${TARGET}")
local fileList=("${@}")
if [[ ${#fileList[@]} -eq 1 ]]; then
cat ${fileList[@]} > joined.flac
else
shntool join -O always ${fileList[@]} -d "${TARGET_DIR}" -o flac -q
if [[ $? -ne 0 ]]; then
med_convert wav ${fileList[@]}
[[ $? -ne 0 ]] && return 1
echo ${fileList[@]}
fileList=($(printf '%s\n' ${fileList[@]} | sed 's|flac|wav|'))
echo ${fileList[@]}
shntool join -O always ${fileList[@]} -d "${TARGET_DIR}" -o flac -q
[[ $? -ne 0 ]] && return 1
local WARN=true
fi
fi
metaflac --remove-all --dont-use-padding "${TARGET_DIR}/joined.flac"
mv "${TARGET_DIR}/joined.flac" "${TARGET}"
[[ ${WARN} == "true" ]] && return 2 || return 0
}