Skip to content

Instantly share code, notes, and snippets.

@lpenaud
Created October 8, 2024 19:18
Show Gist options
  • Save lpenaud/c62e457d31d3b9c5043882195e4d4d4e to your computer and use it in GitHub Desktop.
Save lpenaud/c62e457d31d3b9c5043882195e4d4d4e to your computer and use it in GitHub Desktop.
Split cue file

Split cue file to flac tracks

Dependencies

  • flac
  • shnsplit
  • file

Optional dependencies

  • ffmpeg

Commands

./split-cue.sh cuefile.cue outdir audiofile.flac

Links

#!/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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment