flac
shnsplit
file
ffmpeg
./split-cue.sh cuefile.cue outdir audiofile.flac
flac
shnsplit
file
ffmpeg
./split-cue.sh cuefile.cue outdir audiofile.flac
#!/bin/bash | |
declare cuefile infile outdir filetype | |
# Filename type | |
function file::get_type () { | |
local -r mimetype | |
if [[ "$(file -b --mime-type "${1}")" =~ ^([a-z]+)/ ]]; then | |
echo "${BASH_REMATCH[1]}" | |
fi | |
return 1 | |
} | |
until [ $# -eq 0 ]; do | |
if [ -f "${1}" ]; then | |
filetype="$(file::get_type "${1}")" | |
if [ "${filetype}" = 'audio' ]; then | |
infile="${1}" | |
elif [ "${filetype}" = 'text' ] && [[ "${1}" =~ .cue$ ]]; then | |
cuefile="${1}" | |
fi | |
else | |
outdir="${1}" | |
fi | |
shift | |
done | |
if [ -z "${cuefile}" ] || [ -z "${infile}" ] || [ -z "${outdir}" ]; then | |
printf 'Usage: %s OUTDIR CUEFILE INFILE\n' "$0" >&2 | |
exit 1 | |
fi | |
mkdir -p "${outdir}" | |
shnsplit -o 'flac flac --best -o %f -' \ | |
-d "${outdir}" \ | |
-f "${cuefile}" \ | |
-t '%n - %t' \ | |
"${infile}" |