#! /bin/sh

# cuesplit - split files based on cue information

# usage: cuesplit <file>

# Copyright Jean-Philippe Guillemin <jp.guillemin@free.fr> based on <unknown> author. This program is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your option)
# any later version. Please take a look at http://www.gnu.org/copyleft/gpl.htm

which cuebreakpoints 1>/dev/null || exit
which shnsplit 1>/dev/null || exit
which cuetag 1>/dev/null || exit


if [ $# -lt 1 ]; then
	echo "usage: cuesplit <file>"
	exit
fi

file="$1"

cuefile="${file%.*}.cue"
if [ ! -e "$cuefile" ] ; then
	cuefile="$(ls *.cue)"
fi
soundfile="$file"

echo "Spliting $soundfile using cue file $cuefile"

cuebreakpoints "$cuefile" | shnsplit -o "${soundfile##*.}" "$soundfile"

cuetag "$cuefile" split-track*."${soundfile##*.}"





