#/usr/bin/sh
function checkarg(){
    if test -z $1; then usage;else shift;fi
};
function usage(){
    echo "dagmp3cd - grabs one or more tracks from a cd and encodes them in mp3"
    echo "	also sets ID3 tags using CDDB data if MPEG::MP3Info perl module "
    echo "	is available."
    echo "	In other words, it uses dagrab to get wav files from CD tracks"
    echo "	and CDDB information like track and album name"
    echo "	and then encodes the tracks in files named like"
    echo "	01-song_title.mp3 with information on album,author and song title"
    echo "	embedded in it as ID3 tags. It requires a direct connection to"
    echo "	the internet or a local copy of the CDDB entry for your disk"
    echo "usage: $prog [-del] [dagrab options] <-n|track list>"
    echo "  -del :delete wav file after encoding"
    echo "  examples:"
    echo "  encode all the tracks in a cd:"
    echo "  dagmp3cd -n"
    echo "    the same, disabling jitter correction (faster,but if your drive"
    echo "    does not do it by hardware you will get clicks in your file)"
    echo "      dagmp3cd -o0 -n"
    echo "    encode track 1 and 2 and delete the wavs:"
    echo "      dagmp3cd -d 1 2"
    exit;
};
prog=$0;
case $1 in
  -del)
    shift
    checkarg $*
    dagrab -vC -e 'dagmp3enc -d %s @AUT @DIS @NUM @TRK @trk' $*;;
  *)
    checkarg $*
    dagrab -vC -e 'dagmp3enc %s @AUT @DIS @NUM @TRK @trk' $*;;
esac