#!/bin/sh
#    RipEnc 0.7--Frontend to rip, encode, and name mp3's
#    Copyright (C) 1999 by Michael J. Parmeley <mjparme@asde.com> 

#    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.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software Foundation,
#    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


trap 'forcequit' INT
trap 'forcequit' KILL
trap 'forcequit' TERM

RCDIR=~/.ripenc
TEMPDIR=${RCDIR}
SAVETO=~
TEMPSAVETO=${SAVETO}
ENCODER=bladeenc
RIPPER=cdparanoia
METHOD=cddb
XMCDLIB=/var/X11R6/lib/xmcd
NCONVENT=artist-name_of_song.mp3
select=1
WHOLE=no
DEVICE=/dev/cdrom
SMALL=no
ID3TOOL=none
BITRATE=128
RCREAD=0

forcequit ()
{
    if [ "${ABORT}" = "1" ] ;
     then
      echo ; echo "I am assuming you just want to quit the viewing of the log.  If you want to quit RipEnc press CtrlC again"
      ABORT=0
      return
    fi
    echo
    echo Aborting Ripenc...
    cleantemp
    if [ "${RCREAD}"=="1" ] ;
    then
        saverc
    fi
    exit 1
}

cleantemp ()
{
    checkrm ${TEMPDIR}/ripname.txt
    checkrm ${TEMPDIR}/cdnames.txt
    checkrm ${TEMPDIR}/id3info.txt
    checkrm ${TEMPDIR}/toc1
    checkrm ${TEMPDIR}/toc2
    checkrm ${TEMPDIR}/tracks.txt
    checkrm ${TEMPDIR}/tmprip
    checkrm ${TEMPDIR}/tracks.new
}

checkrm ()
{
    if [ -f $1 ] ;
    then
        rm $1
    fi
}       

saverc ()
{
        echo SAVETO="'"${SAVETO}"'" > ${RCDIR}/ripencrc
        echo ENCODER="'"${ENCODER}"'" >> ${RCDIR}/ripencrc
        echo RIPPER="'"${RIPPER}"'" >> ${RCDIR}/ripencrc
        echo METHOD="'"${METHOD}"'" >> ${RCDIR}/ripencrc
        echo XMCDLIB="'"${XMCDLIB}"'" >> ${RCDIR}/ripencrc
        echo NCONVENT="'"${NCONVENT}"'" >> ${RCDIR}/ripencrc
        echo select="'"${select}"'" >> ${RCDIR}/ripencrc
        echo WHOLE="'"${WHOLE}"'" >> ${RCDIR}/ripencrc
        echo DEVICE="'"${DEVICE}"'" >> ${RCDIR}/ripencrc
        echo SMALL="'"${SMALL}"'" >> ${RCDIR}/ripencrc
        echo ID3TOOL="'"${ID3TOOL}"'" >> ${RCDIR}/ripencrc
        echo BITRATE="'"${BITRATE}"'" >> ${RCDIR}/ripencrc
}

testsaveto ()
{
        if [ ! "${SAVETO}" = "" ] && [ ! -d ${SAVETO} ] ;
        then
                echo -n ${SAVETO} "does not exist, create [y/n]? "
                read create
                if [ "${create}" = "y" ] ;
                then
                    mkdir -p ${SAVETO}
                else
                 SAVETO=${OLDSAVETO}
         	fi
       fi
       if [ "${SAVETO}" = "" ] ;
        then
         SAVETO=${OLDSAVETO}
       fi
}

checkoldrc ()
{
        # Make the .ripenc directory to store all the files used by ripenc
        mkdir -p ${RCDIR}
        if [ -f ~/.ripencrc ] || [ -f ~/.ripencsed ] ;
        then
                mv ~/.ripencrc ${RCDIR}/ripencrc &> /dev/nul
                mv ~/.ripencsed ${RCDIR}/ripencsed &> /dev/null
        fi
}

checkforsed ()
{
        if [ ! -f ${RCDIR}/ripencsed ] ;
        then
                echo "/^$/d" > ${RCDIR}/ripencsed
                echo "s/ /_/g" >> ${RCDIR}/ripencsed
                echo "s/'//g" >> ${RCDIR}/ripencsed
                echo "s/*//g" >> ${RCDIR}/ripencsed
                echo "s/,//g" >> ${RCDIR}/ripencsed
                echo "s/)//g" >> ${RCDIR}/ripencsed
                echo "s/(//g" >> ${RCDIR}/ripencsed
                echo "s/\.//g" >> ${RCDIR}/ripencsed
        fi
}

getcddb ()
{
        export XMCD_LIBDIR=${XMCDLIB}
        cda -dev ${DEVICE} on
        echo ; echo "Getting CDDB information for CD..." ; echo
        cda -dev $DEVICE toc > $TEMPDIR/toc1
        sed -e '/Total Time/d' -e '/Disc ID/d' -e '/^$/d' -e 's/\.//g' -e 's/\[//g' -e 's/\]//g' ${TEMPDIR}/toc1 > ${TEMPDIR}/toc2
        CHECKVARIOUS=`sed -e '1p' ${TEMPDIR}/toc1 | cut -d"/" -f1 | tr A-Z a-z | sed -e 's/ //g'`
        if [ "$CHECKVARIOUS" = "variousartists" -o "$CHECKVARIOUS" = "[soundtrack]" -o "$CHECKVARIOUS" = "various" ] ;
        then
                ALBUM=`sed -ne '1p' ${TEMPDIR}/toc2 | cut -d "/" -f2- | tr a-z A-Z`
                sed -e '1d' ${TEMPDIR}/toc2 | cut -d" " -f5- | tr A-Z a-z | sed -e 's/\//-/g' -e 's/ - /-/g' -e 's/ -- /-/g' -f ${RCDIR}/ripencsed > ${TEMPDIR}/cdnames.txt
                rm ${TEMPDIR}/toc[1-2]
        else
                ARTIST=`sed -ne '1p' ${TEMPDIR}/toc2 | cut -d "/" -f1`
                ALBUM=`sed -ne '1p' ${TEMPDIR}/toc2 | cut -d"/" -f2-`
                sed -e '1d' ${TEMPDIR}/toc2 | cut -d" " -f5- | sed -e 's/\///g' -f ${RCDIR}/ripencsed > ${TEMPDIR}/cdnames.txt 
                rm ${TEMPDIR}/toc[1-2]
        fi
        cda -dev ${DEVICE} off
        if [ "${WHOLE}" = "yes" ] ;
        then 
                sed -e '=' ${TEMPDIR}/cdnames.txt | sed -e 'N' -e 's/\n/ /g' >> ${TEMPDIR}/ripname.txt
                rip
        else
                choosecddb
        fi 
}

manual ()
{
        echo -n "What is the name of the Artist? "
        read ARTIST 
        echo -n "What is the name of the Album? "
        read ALBUM
        snum=0
        while [ "$snum" != "" ] ;
        do
                echo
                echo -n "What song number do you wish to rip (hit enter to end selecting songs)? "
                read snum
                if [ "$snum" = "" ] ;
                 then
                   continue
                fi
                echo -n "What is the name of song #"$snum"? "
                read sname
                sname=`echo $sname | sed -f ${RCDIR}/ripencsed`
                echo $snum $sname >> ${TEMPDIR}/ripname.txt
        done
        confirm
}

showmenu ()
{
        clear
        n=0
        if [ ! -f ${TEMPDIR}/tracks.txt ]
        then
          cp ${TEMPDIR}/cdnames.txt ${TEMPDIR}/tracks.txt
        fi
        echo ; echo -e "\033[1mTracklist\033[0m"
        echo "-----------------------"
        sed -e '=' ${TEMPDIR}/tracks.txt | sed -e 'N' -e 's/\n/ /g' | awk '$2 !~ /+/ { print "  "$1"  " $2}'
        echo ; echo -e "\033[1mSongs to Rip/Encode\033[0m"
        echo "-------------------"
        sed -e '=' ${TEMPDIR}/tracks.txt | sed -e 'N' -e 's/\n/ /g' | awk '$2 ~ /+/ { print "  "$1"     "$3 }'
        echo 
        echo "Enter a track number to toggle whether or not to rip it, or enter to continue"
        read choice
}

toggle ()
{
        sed -e ''$1's/^/+ /' ${TEMPDIR}/tracks.txt > ${TEMPDIR}/tracks.new
        sed -e ''$1's/^+ +//' ${TEMPDIR}/tracks.new > ${TEMPDIR}/tracks.txt
        rm -f ${TEMPDIR}/tracks.new
}

choosecddb ()
{
        showmenu
        while test "${choice}" != ""
        do
                toggle ${choice}
                showmenu
        done
        sed -e '=' ${TEMPDIR}/tracks.txt | sed -e 'N' -e 's/\n/ /g' | sed -ne 's/+//p' > ${TEMPDIR}/ripname.txt
        rip
}

confirm()
{
        echo
        echo "These are the files you have chosen to be ripped"
        echo
        cat ${TEMPDIR}/ripname.txt
        echo
        echo -n "Does this look right to you [y/n]? "
        read uhoh
        if [ "${uhoh}" = "n" ] ;
        then
                if [ "${confirm}" = "1" ] ;
                then
                        rm ${TEMPDIR}/ripname.txt
                        choosecddb
                else
                        rm ${TEMPDIR}/ripname.txt
                        manual
                fi
        else
                rip  
        fi
}

rip()
{
        echo
        SAVETEMP=${SAVETO}
        
        if [ "${ID3TOOL}" != "none" ] ;
         then
            ID3ARTIST=`echo ${ARTIST} | tr _ \ `
            ID3ALBUM=`echo ${ALBUM} | tr _ \ `
            cp ${TEMPDIR}/ripname.txt ${TEMPDIR}/id3info.txt

            echo -n "What is the publishing year? " ; read ID3YEAR
        fi

        ARTIST=`echo ${ARTIST} | sed -f ${RCDIR}/ripencsed`
        ALBUM=`echo ${ALBUM} | sed -f ${RCDIR}/ripencsed`
        cat ${TEMPDIR}/ripname.txt | while read num title
        do
                ARTIST=`echo ${ARTIST} | sed -f ${TEMPDIR}/ripencsed`
                formatnum=`printf '%02d' ${num}`
                if [ "$CHECKVARIOUS" = "variousartists" -o "$CHECKVARIOUS" = "[soundtrack]" -o "$CHECKVARIOUS" = "various" ] ;
                then
                        if [ "$select" = "1" ] ;
                        then
                                NAME=`echo ${title} | tr A-Z a-z`
                        fi
                        if [ "${select}" = "2" ] ;
                        then
                                NAME=`echo ${formatnum}-${title} | tr A-Z a-z`
                        fi
                        if [ "${select}" = "3" ] ;
                        then
                                NAME=${title}
                        fi
                        if [ "${select}" = "4" ] ;
                        then
                                NAME=${formatnum}-${title}
                        fi
                        ARTIST="VARIOUS ARTIST CD"
                else
                        if [ "$select" = "1" ] ;
                        then
                                NAME=`echo $ARTIST-$title | tr A-Z a-z`
                        fi
                        if [ "${select}" = "2" ] ;
                        then
                                NAME=`echo ${formatnum}-${ARTIST}-${title} | tr A-Z a-z`
                        fi
                        if [ "${select}" = "3" ] ;
                        then
                                NAME=${ARTIST}-${title}
                        fi
                        if [ "${select}" = "4" ] ;
                        then
                                NAME=${formatnum}-${ARTIST}-${title}
                        fi
                        if [ "${select}" = "5" ] ;
                        then
                            NAME=${formatnum}-${title}
                            CREATE=`echo ${ARTIST}--${ALBUM} | sed -e 's/ //g' -e 's/\///g'`
                            mkdir -p ${SAVETO}/$CREATE
                            SAVETO=`echo ${SAVETO}/${ARTIST}--${ALBUM} | sed -e 's/ //g'`
                        fi
                        if [ "${select}" = "6" ] ;
                        then
                           NAME=${formatnum}-${title}
                           ARTIST=`echo ${ARTIST} | sed -e 's/ //g' -e 's/\///g'`
                           ALBUM=`echo ${ALBUM} | sed -e 's/ //g' -e 's/\///g'`
                           mkdir -p ${SAVETO}/${ARTIST}/${ALBUM}
                           SAVETO=`echo ${SAVETO}/${ARTIST}/${ALBUM} | sed -e 's/ //g'`
                        fi
                fi
                echo
                echo -n "Now ripping the song " ; echo -n ${title} ; echo -n " by " ; echo -n ${ARTIST} ; echo -n " from the album " ; echo ${ALBUM}
                echo
                echo ${SAVETO}/${NAME}.wav >> ${TEMPDIR}/encode
                case ${RIPPER} in 
                        cdparanoia)
                                cdparanoia -d ${DEVICE} -w ${num} $SAVETO/$NAME.wav
                                ;;
                        cdda2wav)
                                cdda2wav -D ${DEVICE} -t ${num} ${SAVETO}/${NAME}.wav
                                rm ${SAVETO}/*.cddb
                                rm ${SAVETO}/*.inf
                                ;;
                           tosha)
                                tosha -q -f wav -d ${DEVICE} -t ${num} -o ${SAVETO}/${NAME}.wav
                                ;;
                          dagrab)
                                dagrab -d ${DEVICE} -f ${SAVETO}/${NAME}.wav ${num}
                                ;;
                            none)
                               echo "Not Ripping"
                esac
            if [ "${ENCODER}" != "none" ] && [ "${SMALL}" = "yes" ] ;
             then
               encodeit
             fi
      SAVETO=$SAVETEMP
           if [ "${ENCODER}" != "none" ] && [ "${SMALL}" != "yes" ] && [ ! -f ${TEMPDIR}/lock.encode ] ;
            then
             encodeit >> ${TEMPDIR}/encode.log &
             echo $! > ${TEMPDIR}/lock.encode
           fi
        done
SAVETO=$SAVETEMP
}

encodeit ()
{
        e=0 
        while [ "${e}" != "" ]  ;
         do 
           e=`head -1 ${TEMPDIR}/encode` 
            case ${ENCODER} in
                bladeenc)
                        bladeenc -DELETE -QUIT -${BITRATE} ${e} < /dev/null 
                        ;;
                8hz-mp3)
                        ENEW=`echo ${e} | sed -e 's/.wav/.mp3/g'`
                        8hz-mp3 -b ${BITRATE} ${e} ${ENEW}
                        rm ${e}   
                        ;;
                  l3enc)
                       ENEW=`echo ${e} | sed -e 's/.wav/.mp3/g'`
                       l3enc -br ${BITRATE} ${e} ${ENEW}
                       rm ${e}
                       ;;
                  none)
                      echo "Not Encoding"
                      ;;
            esac
          grep -vx "${e}" ${TEMPDIR}/encode >> ${TEMPDIR}/encodetemp
          mv ${TEMPDIR}/encodetemp ${TEMPDIR}/encode
            if [ "${ID3TOOL}" != "none" ] ;
             then
               i=`head -1 ${TEMPDIR}/id3info.txt`
               id3num=`echo $i | cut -d" " -f1`
               id3title=`echo $i | cut -d" " -f2- | tr _ \ `
               ENEW=`echo ${e} | sed -e 's/.wav/.mp3/g'`
               case ${ID3TOOL} in
                  mp3info)
                    mp3info -t "$id3title" -a "${ID3ARTIST}" -l "${ID3ALBUM}" -c "Track $id3num" -y "${ID3YEAR}" ${ENEW} > /dev/null
                    mp3info -F2 ${ENEW}
                    ;;
                  id3ren)
                        id3ren -nocfg -tagonly -song "$id3title" -album "${ID3ALBUM}" -artist "${ID3ARTIST}" -year "${ID3YEAR}" -comment "Track $id3num" -nogenre ${ENEW}
                     ;;
                 esac
                 grep -vx "$i" ${TEMPDIR}/id3info.txt > ${TEMPDIR}/id3info.txt.new
                 mv ${TEMPDIR}/id3info.txt.new ${TEMPDIR}/id3info.txt
             fi
          e=`head -1 ${TEMPDIR}/encode`
         done
   SAVETO=$SAVETEMP
   rm -f ${TEMPDIR}/lock.encode 
}

checkoldrc
checkforsed
cleantemp

if [ -f ~/.ripenc/ripencrc ] ;
then
        . ${RCDIR}/ripencrc
        RCREAD=1
        testsaveto
fi

while [ "$MENU" != "15" ] ;
do
        clear
        echo "RipEnc version 0.7, Copyright (C) 1999  Michael J. Parmeley"
        echo "<mjparme@asde.com>, RipEnc comes with ABSOLUTELY NO WARRANTY"
        echo ; echo
        if [ -f ${TEMPDIR}/lock.encode ] ;
          then
           echo "There is currently an encoding process running in the background"
          else
           echo "There is currently NO encoding process running in the background"
        fi
        if [ -f ${TEMPDIR}/encode.log ] ;
          then
             SIZE=`ls -lag ${TEMPDIR}/encode.log | awk '{ print $5 }'`
             echo "Your encode.log file is "${SIZE}" bytes long."
          else
             echo "There is no encode.log file."
         fi
         echo ; echo "<Enter 'd' for details, 'v' to view the encode log, or 'del' to delete the encode log>"
         echo ; echo
        echo -e "1) Change working directory....................[\033[1m"${SAVETO}"\033[0m]"
        echo -e "2) Choose encoder..............................[\033[1m"${ENCODER}"\033[0m]"
        echo -e "3) Choose ripper...............................[\033[1m"${RIPPER}"\033[0m]"
        echo -e "4) Choose id3 tool.............................[\033[1m"${ID3TOOL}"\033[0m]"
        echo -e "5) Toggle between Manual and CDDB naming.......[\033[1m"${METHOD}"\033[0m]"
        echo -e "6) Setup XMCD_LIBDIR variable for CDA..........[\033[1m"${XMCDLIB}"\033[0m]"
        echo -e "7) Set preferred naming convention.............[\033[1m"${NCONVENT}"\033[0m]"
        echo -e "8) Rip whole CD?...............................[\033[1m"${WHOLE}"\033[0m]"
        echo -e "9) Set small hard drive option?................[\033[1m"${SMALL}"\033[0m]"
        echo -e "10) Please select your Cd-Rom device...........[\033[1m"${DEVICE}"\033[0m]"
        echo -e "11) Set the Bitrate for the encoded MP3's......[\033[1m"${BITRATE}"\033[0m]"
        echo -e "12) List the files in your working directory"
        echo -e "13) Start"
        echo -e "14) About"
        echo -e "15) Exit"
        echo -n "? " ; read MENU
        case $MENU in
                v) 
                  ABORT=1
                  if [ -f ${TEMPDIR}/encode.log ] ;
                    then
                      cat ${TEMPDIR}/encode.log
                      echo ; echo ; echo "Press <enter> to continue" ; read continue
                      ABORT=0
                    else
                     echo ; echo "There is no encode.log file to view"
                     echo ; echo "Press <enter> to continue" ; read continue
                     ABORT=0
                  fi
                 ;;
                d)
                  if [ ! -f ${TEMPDIR}/lock.encode ] ;
                    then
                     echo ; echo "There doesn't appear to be a encoding process running!"
                     echo ; echo "Please press enter to continue" ; read continue
                    else
                     echo ; echo "Encoder      PID   CPU%    CPU Time"
                     ps auxww | sed -ne '/bladeenc/p' -e '/8hz-mp3/p' -e '/l3enc/p' | awk '$11 !~ /sed/ { print $11"    " $2"   " $3"    " $10 }'
                     STATUS=`wc -l ${TEMPDIR}/encode | awk '{ print $1 }'`
                     STATUS=`expr ${STATUS} - 1`
                     CURRENT=`sed -ne '1p' ${TEMPDIR}/encode`
                     echo ; echo "Currently" ${CURRENT} "is being encoded"
                     case ${STATUS} in
                      0)
                        echo ; echo "No more songs are in the queue" ;;
                      1)
                        echo ; echo "This 1 song still needs to be encoded:" ;;
                      *)
                        echo ; echo "These" ${STATUS} "songs still need to be encoded:" ;;
                     esac 
                     sed -ne '2,$p' ${TEMPDIR}/encode
                     echo ; echo "Press enter to continue" ; read continue
                  fi
                  ;;
                del)
                   if [ -f ${TEMPDIR}/lock.encode ] ;
                     then
                      echo ; echo "Deleting the encode log while an encode process is running will keep any more info from being written to the log file until all files currently in and added to the queue while the current encode process is running are completed."
                      echo ; echo -n "Do you still want to do this [y/N]? "
                      read choice
                        if [ "${choice}" = "y" ] ;
                         then
                          rm -f ${TEMPDIR}/encode.log
                         fi
                      else
                          rm -f ${TEMPDIR}/encode.log
                   fi
                   ;;
                1)
                        OLDSAVETO=${SAVETO}
                        echo
                        echo -n "Enter your working directory: "
                        read SAVETO
                        TEMPSAVETO=${SAVETO}
                        testsaveto
                        ;;
                2)
                        echo "1) bladeenc"
                        echo "2) 8hz-mp3"
                        echo "3) l3enc"
                        echo "4) Do not automatically start encoding"
                        echo -n "? " ; read opt
                        if [ "$opt" = "1" ] ;
                        then
                                ENCODER=bladeenc
                        fi
                        if [ "$opt" = "2" ] ;
                        then
                                ENCODER=8hz-mp3
                        fi
                        if [ "$opt" = "3" ] ;
                        then
                                ENCODER=l3enc
                        fi
                        if [ "$opt" = "4" ] ;
                        then
                                ENCODER=none
                        fi
                        if [ "${ENCODER}" = "bladeenc" -o "${ENCODER}" = "8hz-mp3" ] && [ ${BITRATE} -gt 999 ]  ;
                          then
                            BITRATE=`expr ${BITRATE} / 1000`
                          fi
                        if [ "${ENCODER}" = "l3enc" ] && [ ${BITRATE} -le 999 ] ;
                          then
                           BITRATE=`expr ${BITRATE} \* 1000`
                        fi
                        ;;
                3)
                        echo "1) cdparanoia"
                        echo "2) cdda2wav"
                        echo "3) tosha"
                        echo "4) dagrab"
                        echo "5) none (assume wavs exist and/or wav files need to be encoded)"
                        echo -n "? " ; read ch
                        if [ "$ch" = "1" ] ;
                        then
                                RIPPER=cdparanoia
                        fi
                        if [ "$ch" = "2" ] ;
                        then
                                RIPPER=cdda2wav 
                        fi
                        if [ "$ch" = "3" ] ;
                        then
                                RIPPER=tosha
                        fi
                        if [ "$ch" = "4" ]  ;
                        then
                                RIPPER=dagrab
                        fi
                        if [ "$ch" = "5" ]  ;
                         then
                                RIPPER=none
                        fi
                        ;;
                4)
                        echo ; echo "Some versions of mp3info do not support the command line options.  If you have one of these versions please upgrade to the newest version!"
                        echo ; echo "1) mp3info"
                        echo "2) id3ren"
                        echo "3) none"
                        echo -n "? " ; read ch
                         if [ "$ch" = "1" ] ;
                         then
                           ID3TOOL=mp3info
                         fi
                         if [ "$ch" = "2" ] ;
                         then
                           ID3TOOL=id3ren
                         fi
                         if [ "$ch" = "3" ] ;
                          then
                           ID3TOOL=none
                         fi
                         ;; 

                5)
                        if [ "${METHOD}" = "cddb" ] ;
                        then
                          METHOD=manual
                        else
                          METHOD=cddb
                        fi
                        ;;
                6)
                        XMCDTEMP=${XMCDLIB}
                        echo -n "Please enter the path to your xmcd library directory: "
                        read XMCDLIB
                        if [ ! -d ${XMCDLIB} ] ;
                        then
                                echo "That directory does not seem to exist"
                                echo "Hit enter to continue" ; read continue
                                XMCDLIB=$XMCDTEMP
                        fi 
                        if [ "${XMCDLIB}" = "" ] ;
                        then
                                XMCDLIB=$XMCDTEMP
                        fi
                        ;;
                7)
                        echo ; echo -e "\033[1mNOTE: Option 5 and 6 can not be used with various artist CD's\033[0m" ; echo
                        echo "1) artist-name_of_song.mp3"
                        echo "2) track#-artist-name_of_song.mp3"
                        echo "3) Artist-Name_Of_Song.mp3 ( note the case changes )"
                        echo "4) track#-Artist-Name_Of_Song.mp3"
                        echo "5) artist--album/track#-name_of_song.mp3"
                        echo "6) artist/album/track#-name_of_song.mp3"
                        echo -n "? " ; read select
                        if [ "${select}" = "1" ]  ;
                        then
                                NCONVENT=artist-name_of_song.mp3
                        fi
                        if [ "${select}" = "2" ] ;
                        then
                                NCONVENT=track#-artist-name_of_song.mp3
                        fi
                        if [ "${select}" = "3" ]  ;
                        then
                                NCONVENT=Artist-Name_Of_Song.mp3
                        fi
                        if [ "${select}" = "4" ] ;
                        then
                                NCONVENT=track#-Artist-Name_Of_Song.mp3
                        fi
                        if [ "${select}" = "5" ] ;
                        then
                               NCONVENT=artist--album/track#-name_of_song.mp3
                        fi
                        if [ "${select}" = "6" ] ;
                        then
                              NCONVENT=artist/album/track#-name_of_song.mp3
                        fi
                        ;;  
                8)
                        if [ "${METHOD}" = "manual" ] ;
                        then
                                echo "You are using Manual naming. Changing this option has no effect."
                                echo "Hit enter to continue" ; read continue
                        else
                                if [ "${WHOLE}" = "no" ] ;
                                then
                                        WHOLE=yes
                                else
                                        WHOLE=no
                                fi
                        fi
                        ;;
                9)
                   if [ "${SMALL}" = "no" ] ;
                    then
                     echo "Setting this option to YES makes RipEnc rip one song and then encode that song"
                     echo "before ripping another one.  This is handy if you have a small hard drive and do"
                     echo "not have room for a whole CD on your hard drive."
                     echo ; echo "Press <enter> to continue" ; read continue
                    fi
                         if [ "${SMALL}" = "no" ] ;
                           then
                            SMALL=yes
                           else
                            SMALL=no
                         fi
                         ;;
                10)
                        TEMPDEVICE=${DEVICE}
                        echo
                        echo -n "Enter full path of device: "
                        read DEVICE
                        if [ ! -e ${DEVICE} ] ;
                        then
                                echo ${DEVICE} "does not exist...hit enter to continue"
                                read continue
                                DEVICE=$TEMPDEVICE
                        fi
                        if [ "${DEVICE}" = "" ] ;
                        then
                                DEVICE=$TEMPDEVICE
                        fi
                        ;;
                11)
                     TEMPBITRATE=${BITRATE}
                     echo
                     echo -n "Type your Bitrate (only enter two or three digits ie 64, 128, 256, etc): "
                     read BITRATE
                     if [ "${ENCODER}" = "l3enc" ] ;
                       then
                         ZERO=000
                         BITRATE=${BITRATE}$ZERO
                       fi
                     if [ "${BITRATE}" = "" ] ;
                      then
                       BITRATE=$TEMPBITRATE
                     fi
                     ;;
                12)
                        ls ${SAVETO}/
                        echo
                        echo "Hit enter to continue" ; read continue 
                        ;;
                13)
                        if [ "${METHOD}" = "cddb" ] ;
                        then
                                confirm=1       
                                getcddb
                        fi
                        if [ "${METHOD}" = "manual" ] ;
                        then
                                confirm=2
                                manual
                        fi
                        
                        cleantemp

                        ;;
                14)
                        echo "              RipEnc 0.7 By Michael J. Parmeley" >> ${TEMPDIR}/tmprip
                        echo >> ${TEMPDIR}/tmprip 
                        echo "                      mjparme@asde.com" >> ${TEMPDIR}/tmprip
                        echo >> ${TEMPDIR}/tmprip
                        echo "              http://www.asde.com/~mjparme/index.htm" >> ${TEMPDIR}/tmprip
                        echo >> ${TEMPDIR}/tmprip
                        echo "Thanks to the following people for some great ideas and/or code" >> ${TEMPDIR}/tmprip
                        echo "                        Bryan Mayland                " >> ${TEMPDIR}/tmprip
                        echo "                       Vijay Bharadwaj               " >> ${TEMPDIR}/tmprip
                        echo "                       Jason Willoughby              " >> ${TEMPDIR}/tmprip
                        echo "                         Oyvind Moll                 " >> ${TEMPDIR}/tmprip
                        echo "                         Justin Lee                  " >> ${TEMPDIR}/tmprip 
                        echo "                         Evan Jones                  " >> ${TEMPDIR}/tmprip
                        dialog --backtitle "About RipEnc 0.7" --msgbox "`cat ${TEMPDIR}/tmprip`" 18 67
                        rm ${TEMPDIR}/tmprip
                        ;;
                15)
                        saverc
                        cleantemp
                        ;;
        esac
done
