Added YEAR as a variable for creating playlists
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index bd13e20..af7282d 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -11,7 +11,7 @@
 # Copyright for this work is to expire January 1, 2010, after which it
 # shall be public domain.
 
-VERSION="2.2.4"
+VERSION="2.3.0"
 
 usage ()
 {
@@ -30,6 +30,7 @@ echo "       Specify discid to resume from (only needed if you no longer have th
 echo "-d <device>"
 echo "       Specify CDROM device to grab"
 echo "-D     Debugging mode (equivalent to sh -x abcde)"
+echo "-e     Erase encoded track information from status file"
 echo "-h     This help information"
 #echo "-i    Tag files while encoding, when possible (local only) -NWY-"
 echo "-j <#> Number of encoder processes to run at once (localhost)"
@@ -61,6 +62,7 @@ echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
 echo ""
 echo "Tracks is a space-delimited list of tracks to grab."
 echo "Ranges specified with hyphens are allowed."
+#echo "Double hyphens are used to concatenate tracks"
 }
 
 # Funtions to replace the need of seq, which is too distribution dependant.
@@ -85,6 +87,31 @@ f_seq_line ()
        echo
 }
 
+# Functions to replace the need of awk {print $1} and {print $NF}
+get_first()
+{
+if [ X"$1" = "X" ]; then
+       for first in `cat`; do
+               break
+       done
+else
+       first=$1
+fi
+echo $first
+}
+
+get_last()
+{
+if [ X"$1" = "X" ]; then
+       for stdin in `cat`; do
+               last=$stdin
+       done
+else
+       for last in $@ ; do :; done
+fi
+echo $last
+}
+
 # checkstatus [blurb]
 # Returns "0" if the blurb was found, returns 1 if it wasn't
 # Puts the blurb content, if available, on stdout.
@@ -219,6 +246,7 @@ relpath ()
                        FR="$(echo "$FR" | cut -d/ -f2-)"
                        TO="../$TO"
                done
+               ;;
        esac
 
        echo $TO
@@ -241,43 +269,201 @@ splitvarious ()
        if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
                case "$VARIOUSARTISTSTYLE" in
                forward)
-                       DTITLEARTIST="$(echo $TRACKNAME | sed 's- / -~-g')"
-                       TRACKARTIST="$(echo $DTITLEARTIST | cut -f1 -d~)"
-                       TRACKNAME="$(echo $DTITLEARTIST | cut -f2 -d~)"
+                       DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
+                       TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
+                       TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
                        ;;
                forward-dash)
-                       DTITLEARTIST="$(echo $TRACKNAME | sed 's, - ,~,g')"
-                       TRACKARTIST="$(echo $DTITLEARTIST | cut -f1 -d~)"
-                       TRACKNAME="$(echo $DTITLEARTIST | cut -f2 -d~)"
+                       DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
+                       TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
+                       TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
                        ;;
                reverse)
-                       DTITLEARTIST="$(echo $TRACKNAME | sed 's- / -~-g')"
-                       TRACKARTIST="$(echo $DTITLEARTIST | cut -f2 -d~)"
-                       TRACKNAME="$(echo $DTITLEARTIST | cut -f1 -d~)"
+                       DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
+                       TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
+                       TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
                        ;;
                reverse-dash)
-                       DTITLEARTIST="$(echo $TRACKNAME | sed 's, - ,~,g')"
-                       TRACKARTIST="$(echo $DTITLEARTIST | cut -f2 -d~)"
-                       TRACKNAME="$(echo $DTITLEARTIST | cut -f1 -d~)"
+                       DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
+                       TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
+                       TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
                        ;;
                colon)
-                       DTITLEARTIST="$(echo $TRACKNAME | sed 's-: -~-g')"
-                       TRACKARTIST="$(echo $DTITLEARTIST | cut -f1 -d~)"
-                       TRACKNAME="$(echo $DTITLEARTIST | cut -f2 -d~)"
+                       DTITLEARTIST=$(echo "$TRACKNAME" | sed 's-: -~-g')
+                       TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
+                       TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
                        ;;
                trailing-paren)
-                       DTITLEARTIST="$(echo $TRACKNAME | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
-                       TRACKARTIST="$(echo $DTITLEARTIST | cut -f2 -d~)"
-                       TRACKNAME="$(echo $DTITLEARTIST | cut -f1 -d~)"
+                       DTITLEARTIST=$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')
+                       TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
+                       TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
                        ;;
                esac
        elif [ "$ONETRACK" = "y" ]; then
                TRACKARTIST="Various"
        else
-               TRACKARTIST=$DARTIST
+               TRACKARTIST="$DARTIST"
        fi
 }
 
+do_getgenreid () {
+local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
+local id=""
+       case ${genre} in
+               "blues")                 id=0 ;;
+               "classic rock")          id=1 ;;
+               "country")               id=2 ;;
+               "dance")                 id=3 ;;
+               "disco")                 id=4 ;;
+               "funk")                  id=5 ;;
+               "grunge")                id=6 ;;
+               "hip-hop")               id=7 ;;
+               "jazz")                  id=8 ;;
+               "metal")                 id=9 ;;
+               "new age")               id=10 ;;
+               "oldies")                id=11 ;;
+               "other")                 id=12 ;;
+               "pop")                   id=13 ;;
+               "r&b")                   id=14 ;;
+               "rap")                   id=15 ;;
+               "reggae")                id=16 ;;
+               "rock")                  id=17 ;;
+               "techno")                id=18 ;;
+               "industrial")            id=19 ;;
+               "alternative")           id=20 ;;
+               "ska")                   id=21 ;;
+               "death metal")           id=22 ;;
+               "pranks")                id=23 ;;
+               "soundtrack")            id=24 ;;
+               "euro-techno")           id=25 ;;
+               "ambient")               id=26 ;;
+               "trip-hop")              id=27 ;;
+               "vocal")                 id=28 ;;
+               "jazz+funk")             id=29 ;;
+               "fusion")                id=30 ;;
+               "trance")                id=31 ;;
+               "classical")             id=32 ;;
+               "instrumental")          id=33 ;;
+               "acid")                  id=34 ;;
+               "house")                 id=35 ;;
+               "game")                  id=36 ;;
+               "sound clip")            id=37 ;;
+               "gospel")                id=38 ;;
+               "noise")                 id=39 ;;
+               "alt. rock")             id=40 ;;
+               "bass")                  id=41 ;;
+               "soul")                  id=42 ;;
+               "punk")                  id=43 ;;
+               "space")                 id=44 ;;
+               "meditative")            id=45 ;;
+               "instrum. pop")          id=46 ;;
+               "instrum. rock")         id=47 ;;
+               "ethnic")                id=48 ;;
+               "gothic")                id=49 ;;
+               "darkwave")              id=50 ;;
+               "techno-indust.")        id=51 ;;
+               "electronic")            id=52 ;;
+               "pop-folk")              id=53 ;;
+               "eurodance")             id=54 ;;
+               "dream")                 id=55 ;;
+               "southern rock")         id=56 ;;
+               "comedy")                id=57 ;;
+               "cult")                  id=58 ;;
+               "gangsta")               id=59 ;;
+               "top 40")                id=60 ;;
+               "christian rap")         id=61 ;;
+               "pop/funk")              id=62 ;;
+               "jungle")                id=63 ;;
+               "native american")       id=64 ;;
+               "cabaret")               id=65 ;;
+               "new wave")              id=66 ;;
+               "psychadelic")           id=67 ;;
+               "rave")                  id=68 ;;
+               "showtunes")             id=69 ;;
+               "trailer")               id=70 ;;
+               "lo-fi")                 id=71 ;;
+               "tribal")                id=72 ;;
+               "acid punk")             id=73 ;;
+               "acid jazz")             id=74 ;;
+               "polka")                 id=75 ;;
+               "retro")                 id=76 ;;
+               "musical")               id=77 ;;
+               "rock & roll")           id=78 ;;
+               "hard rock")             id=79 ;;
+               "folk")                  id=80 ;;
+               "folk/rock")             id=81 ;;
+               "national folk")         id=82 ;;
+               "swing")                 id=83 ;;
+               "fusion")                id=84 ;;
+               "bebob")                 id=85 ;;
+               "latin")                 id=86 ;;
+               "revival")               id=87 ;;
+               "celtic")                id=88 ;;
+               "bluegrass")             id=89 ;;
+               "avantgarde")            id=90 ;;
+               "gothic rock")           id=91 ;;
+               "progress. rock")        id=92 ;;
+               "psychadel. rock")       id=93 ;;
+               "symphonic rock")        id=94 ;;
+               "slow rock")             id=95 ;;
+               "big band")              id=96 ;;
+               "chorus")                id=97 ;;
+               "easy listening")        id=98 ;;
+               "acoustic")              id=99 ;;
+               "humour")                id=100 ;;
+               "speech")                id=101 ;;
+               "chanson")               id=102 ;;
+               "opera")                 id=103 ;;
+               "chamber music")         id=104 ;;
+               "sonata")                id=105 ;;
+               "symphony")              id=106 ;;
+               "booty bass")            id=107 ;;
+               "primus")                id=108 ;;
+               "porn groove")           id=109 ;;
+               "satire")                id=110 ;;
+               "slow jam")              id=111 ;;
+               "club")                  id=112 ;;
+               "tango")                 id=113 ;;
+               "samba")                 id=114 ;;
+               "folklore")              id=115 ;;
+               "ballad")                id=116 ;;
+               "power ballad")          id=117 ;;
+               "rhythmic soul")         id=118 ;;
+               "freestyle")             id=119 ;;
+               "duet")                  id=120 ;;
+               "punk rock")             id=121 ;;
+               "drum solo")             id=122 ;;
+               "a capella")             id=123 ;;
+               "euro-house")            id=124 ;;
+               "dance hall")            id=125 ;;
+               "goa")                   id=126 ;;
+               "drum & bass")           id=127 ;;
+               "club-house")            id=128 ;;
+               "hardcore")              id=129 ;;
+               "terror")                id=130 ;;
+               "indie")                 id=131 ;;
+               "britpop")               id=132 ;;
+               "negerpunk")             id=133 ;;
+               "polsk punk")            id=134 ;;
+               "beat")                  id=135 ;;
+               "christian gangsta rap") id=136 ;;
+               "heavy metal")           id=137 ;;
+               "black metal")           id=138 ;;
+               "crossover")             id=139 ;;
+               "contemporary christian")id=140 ;;
+               "christian rock")        id=141 ;;
+               "merengue")              id=142 ;;
+               "salsa")                 id=143 ;;
+               "thrash metal")          id=144 ;;
+               "anime")                 id=145 ;;
+               "jpop")                  id=146 ;;
+               "synthpop")              id=147 ;;
+               *)                       return 1 ;;
+       esac
+echo ${id}
+return 0
+}
+
 # do_tag [tracknumber]
 # id3 tags a filename
 # variables used:
@@ -292,16 +478,20 @@ do_tag ()
        if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
                # Get the trackpadding from the current track
                CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
-               TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
+               TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
        fi
        for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
        do
        case "$OUTPUT" in
        mp3)
                # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
+               GENREID=$(do_getgenreid "${CDGENRE}")
+
+               # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
                run_command tagtrack-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
                        -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
-                       -g "$CDGENRE" -T "$1/$TRACKS" "$ABCDETEMPDIR/track$1.$OUTPUT"
+                       -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
+                       "$ABCDETEMPDIR/track$1.$OUTPUT"
                ;;
        ogg)
                case "$OGGENCODERSYNTAX" in
@@ -312,16 +502,16 @@ do_tag ()
                                fi
                                (
                                # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
-                               echo ARTIST=$TRACKARTIST
+                               echo ARTIST="$TRACKARTIST"
                                echo ALBUM="$DALBUM"
-                               echo TITLE=$TRACKNAME
-                                       if [ -n "$CDYEAR" ]; then
+                               echo TITLE="$TRACKNAME"
+                               if [ -n "$CDYEAR" ]; then
                                        echo DATE="$CDYEAR"
-                                       fi
-                               if [ -n "$CDGENRE" ]; then
+                               fi
+                               if [ -n "$CDGENRE" ]; then
                                        echo GENRE="$CDGENRE"
-                               fi      
-                               echo TRACKNUMBER=$1
+                               fi      
+                               echo TRACKNUMBER=${TRACKNUM:-$1}
                                echo CDDB=$CDDBDISCID
                                if [ "$(eval echo ${COMMENT})" != "" ]; then
                                        case "$COMMENTOUTPUT" in
@@ -329,7 +519,7 @@ do_tag ()
                                                *)   echo COMMENT="$COMMENTOUTPUT";;
                                        esac    
                                fi
-                               ) | run_command tagtrack-$1 $VORBISCOMMENT -w \
+                               ) | run_command tagtrack-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
                                        "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
                                # Doublecheck that the commented file was created successfully before wiping the original
                                if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" ]; then
@@ -341,16 +531,17 @@ do_tag ()
                esac
                ;;
        flac)
-                (
+## FIXME ##            [ "$FLACONOGG" = "y" ] && OUTPUT=ogg
+               (
                echo ARTIST="$TRACKARTIST"
                echo ALBUM="$DALBUM"
                echo TITLE="$TRACKNAME"
-                       if [ -n "$CDYEAR" ]; then
+               if [ -n "$CDYEAR" ]; then
                        echo DATE="$CDYEAR"
-                       fi
-                       if [ -n "$CDGENRE" ]; then
+               fi
+               if [ -n "$CDGENRE" ]; then
                        echo GENRE="$CDGENRE"
-                fi     
+               fi      
                echo TRACKNUMBER=${TRACKNUM:-$1}
                echo CDDB=$CDDBDISCID
                if [ "$(eval echo ${COMMENT})" != "" ]; then
@@ -359,7 +550,7 @@ do_tag ()
                                *)   echo COMMENT="$COMMENTOUTPUT";;
                        esac    
                fi
-                ) | run_command tagtrack-$1 $METAFLAC --import-tags-from=- --no-utf8-convert "$ABCDETEMPDIR/track$1.$OUTPUT"
+               ) | run_command tagtrack-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$OUTPUT"
                ;;
        spx)
                run_command tagtrack-$1 true
@@ -415,26 +606,69 @@ do_batch_encode ()
 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
 do_encode ()
 {
-       IN="$ABCDETEMPDIR/track$1.wav"
-       # We need IN to proceed.
-       if [ -s "$IN" ] ; then
+       if [ "$USEPIPES" = "y" ]; then
+               case "$OUTPUT" in
+                       mp3)
+                               TEMPARG="PIPE_$MP3ENCODERSYNTAX"
+                               ;;
+                       ogg)
+                               TEMPARG="PIPE_$OGGENCODERSYNTAX"
+                               ;;
+                       flac)
+                               TEMPARG="PIPE_$FLACENCODERSYNTAX"
+                               ;;
+                       spx)
+                               TEMPARG="PIPE_$SPEEXENCODER"
+                               ;;
+                       mpc)
+                               TEMPARG="PIPE_$MPPENCODER"
+                               ;;
+               esac
+               IN=${!TEMPARG}
+       else
+               IN="$ABCDETEMPDIR/track$1.wav"
+               case "$OUTPUT" in
+                       mp3)
+                               case "$MP3ENCODERSYNTAX" in
+                                       # FIXME # check if mp3enc needs -if for pipes
+                                       mp3enc)
+                                               FILEARG="-if $IN"
+                                               ;;
+                                       *)
+                                               FILEARG=$IN
+                                               ;;
+                               esac
+                               ;;
+                       *)
+                               FILEARG=$IN
+                               ;;
+               esac
+       fi
+       # We need IN to proceed, if we are not using pipes.
+       if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
                for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
                do
                        OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
-                       run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
+                       if [ X"$USEPIPES" = "Xy" ]; then
+                               RUN_COMMAND=""
+                       else
+                               run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
+                               RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
+                       fi
                        case "$OUTPUT" in
                        mp3)
                                case "$2" in
                                %local*%)
                                        case "$MP3ENCODERSYNTAX" in
-                                       lame|gogo) run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
-                                       bladeenc) run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
-                                       l3enc|xingmp3enc) run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
-                                       mp3enc) run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
+                                       lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
+                                       bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
+                                       l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
+                                       # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
+                                       mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
                                        esac
                                        ;;
                                *)
-                                       run_command encodetrack-$OUTPUT-$1 nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
+                                       $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
                                        ;;
                                esac
                                ;;
@@ -442,12 +676,12 @@ do_encode ()
                                case "$2" in
                                %local*%)
                                        case "$OGGENCODERSYNTAX" in
-                                       vorbize) run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
-                                       oggenc) run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
+                                       vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
+                                       oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
                                        esac
                                        ;;
                                *)
-                                       run_command encodetrack-$OUTPUT-$1 nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
+                                       $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
                                        ;;
                                esac
                                ;;
@@ -455,14 +689,14 @@ do_encode ()
                                case "$2" in
                                %local*%)
                                        case "$FLACENCODERSYNTAX" in
-                                       flac) run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $FLACENCODER  $FLACENCODEROPTS -o "$OUT" "$IN" ;; 
+                                       flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER  $FLACENCODEROPTS -o "$OUT" "$IN" ;; 
                                        esac
                                        ;;
        
                                *)
                                        echo -n "DISTMP3:"
                                        echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
-                                       run_command encodetrack-$OUTPUT-$1 nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
+                                       $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
                                        ;;
                                esac
                                ;;
@@ -476,9 +710,9 @@ do_encode ()
                                fi
                                # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
                                if [ ! "$DOTAG" = "y" ]; then
-                                       run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
+                                       $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
                                else
-                                       run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
+                                       $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
                                fi
                                ;;
                        mpc)    
@@ -488,7 +722,7 @@ do_encode ()
                                # errors, so I have not tried it myself.
                                ## FIXME ## Needs some cleanup to determine if an empty tag sent
                                ## FIXME ## to the encoder ends up empty.
-                               run_command encodetrack-$OUTPUT-$1 nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
+                               $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
                                ;;
                        esac
                done
@@ -589,9 +823,18 @@ do_encode ()
 #      done
 #}
 
+# do_single_gain
+# variables used:
+# FIXME #
+do_single_gain ()
+{
+:
+}
+
 # do_batch_gain
 # variables used:
 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
+# FIXME #
 do_batch_gain ()
 {
        # The commands here don't go through run_command because they're never supposed to be silenced
@@ -691,7 +934,7 @@ do_move ()
                if [ -n "$STARTTRACKNUMBER" ] ; then
                        # Get the trackpadding from the current track
                        CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
-                       TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
+                       TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
                else
                        TRACKNUM=${UTRACKNUM}
                fi
@@ -725,6 +968,7 @@ do_playlist ()
                ALBUMFILE=$(mungefilename "$DALBUM")
                ARTISTFILE=$(mungefilename "$DARTIST")
                GENRE=$(mungegenre "$GENRE")
+               YEAR=${CDYEAR:-$CDYEAR}
                if [ "$VARIOUSARTISTS" = "y" ] ; then
                        PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
                else
@@ -767,7 +1011,7 @@ do_playlist ()
                                if [ -n "$STARTTRACKNUMBER" ] ; then
                                        # Get the trackpadding from the current track
                                        CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
-                                       TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
+                                       TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
                                else
                                        TRACKNUM=${UTRACKNUM}
                                fi
@@ -813,7 +1057,13 @@ do_discid ()
        #elif [ -z "$DISCID" ]; then
        if [ -z "$DISCID" ]; then
                vecho -n "Getting CD track info... "
+               if [ "$OSFLAVOUR" = "OSX" ]; then
+                       disktool -u ${CDROM#/dev/}
+               fi
                TRACKINFO=$($CDDISCID $CDROM)
+               if [ "$OSFLAVOUR" = "OSX" ]; then
+                       disktool -m ${CDROM#/dev/}
+               fi
                # Make sure there's a CD in there by checking cd-discid's return code
                if [ "$?" = "1" ]; then
                        echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
@@ -843,12 +1093,12 @@ do_discid ()
                                cdparanoia|debug)
                                        if [ "$WEHAVEACD" = "y" ]; then
                                                vecho "Querying the CD for audio tracks..."
-                                               CDPARANOIAOUTPUT=$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )
+                                               CDPARANOIAOUTPUT="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
                                                RET=$?
                                                if [ ! "$RET" = "0" ];then
                                                        echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
                                                fi
-                                               TRACKS=$( echo $CDPARANOIAOUTPUT | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 |  awk '{print $1}' | tr -d "." | tr '\n' ' ' )
+                                               TRACKS="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ' )"
                                                CDPARANOIAAUDIOTRACKS="$TRACKS"
                                        else
                                                if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks ; then
@@ -863,7 +1113,7 @@ do_discid ()
                else
                        TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
                fi
-               if echo "$TRACKS" | grep [[:digit:]] > /dev/null 2>&1 ;then :;else
+               if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
                        echo "The disc does not contain any tracks. Giving up..."
                        exit 0
                fi
@@ -898,8 +1148,6 @@ do_discid ()
                echo Grabbing tracks: "$TRACKQUEUE"
        fi
 
-#      for LASTTRACK in $TRACKQUEUE; do :; done
-
        QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
 
        # We have the discid, create a temp directory after it to store all the temp
@@ -972,9 +1220,10 @@ do_discid ()
                cat /dev/null > "$ABCDETEMPDIR/status"
        fi
        if [ X"$CUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
-               if checkstatus cuefile ; then :; else
-                       $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/cue-$(echo $TRACKINFO | cut -f1 -d' ').txt
-                       echo cuefile >> "$ABCDETEMPDIR/status"
+               if checkstatus cuefile >/dev/null ; then :; else
+                       CUEFILE=cue-$(echo $TRACKINFO | cut -f3 -d' ').txt
+                       $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/$CUEFILE
+                       echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
                fi
        fi
        # If we got the CDPARANOIA status and it is not recorded, save it now
@@ -990,6 +1239,19 @@ do_discid ()
        echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
 }
 
+# do_cleancue
+# Create a proper CUE file based on the CUE file we created before.
+do_cleancue()
+{
+       if checkstatus cuefile; then :; else
+               $CUEFILE_INPUT="$ABCDETEMPDIR/cue-$(echo $TRACKINFO | cut -f1 -d' ').txt"
+               ### FIXME ### checkstatus cddb
+               if [ "$DOCDDB" = "y" ]; then
+               MARKER  
+               fi
+       fi
+}
+
 # do_cddbparse
 # Parses a CDDB file and outputs the title and the track names.
 # Variables: CDDBFILE
@@ -1036,7 +1298,7 @@ do_localcddb ()
                                echo "y" >&2
                        fi
                        if [ "$USELOCALRESP" = "y" ]; then
-                       #echo "Using local copy of CDDB data"
+                               #echo "Using local copy of CDDB data"
                                cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
                                echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
                                echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
@@ -1047,7 +1309,6 @@ do_localcddb ()
                                #echo "Not using local copy of CDDB data"
                                CDDBLOCALSUCCESS="n"
                        fi
-                       CDDBLOCALSUCCESS="y"
                else
                        CDDBLOCALSUCCESS="n"
                fi
@@ -1382,12 +1643,18 @@ do_cddbedit ()
                                eval $(echo "$EDITOR") "$CDDBDATA"
                        fi
                # If that fails, check for a vi
+               elif which vi >/dev/null 2>&1; then
+                       vi "$CDDBDATA"
                elif [ -x /usr/bin/vi ]; then
                        /usr/bin/vi "$CDDBDATA"
                # nano should be on all (modern, i.e., sarge) debian systems
+               elif which nano >/dev/null 2>&1 ; then
+                       nano "$CDDBDATA"
                elif [ -x /usr/bin/nano ]; then
                        /usr/bin/nano "$CDDBDATA"
                # mg should be on all OpenBSD systems
+               elif which mg >/dev/null 2>&1 ; then
+                       mg "$CDDBDATA"
                elif [ -x /usr/bin/mg ]; then
                        /usr/bin/mg "$CDDBDATA"
                # bomb out
@@ -1402,7 +1669,7 @@ do_cddbedit ()
 
        # Some heuristics first. Look at Disc Title, and if it starts with
        # "Various", then we'll assume Various Artists
-       if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2 -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
+       if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
                echo "Looks like a Multi-Artist CD" >&2
                VARIOUSARTISTS=y
        else
@@ -1537,9 +1804,10 @@ do_cdread ()
                # We need the first and last track for cdda2wav
                FIRSTTRACK=$2
                LASTTRACK=$3
+               UTRACKNUM=$FIRSTTRACK
                case "$CDROMREADERSYNTAX" in
-                       cdparanoia) UTRACKNUM="1-" ;;
-                       cdda2wav) UTRACKNUM="1+$LASTRACK" ;;
+                       cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
+                       cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
                        *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
                           exit 1 ;;
                esac
@@ -1547,18 +1815,13 @@ do_cdread ()
                UTRACKNUM=$1
        fi
        CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
-       WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
-       if [ -r "$CDDBDATA" ]; then
-               TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
-               echo "Grabbing track $UTRACKNUM: $TRACKNAME..." >&2
-       else
-               echo "Grabbing track $UTRACKNUM..." >&2
-       fi
        if [ "$USEPIPES" = "y" ]; then
                TEMPARG="PIPE_$CDROMREADERSYNTAX"
                FILEARG=${!TEMPARG}
                REDIR=""
+               PIPE_MESSAGE="and encoding "
        else
+               WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
                case "$CDROMREADERSYNTAX" in
                ## FIXME ## Find the case for dagrab, to avoid exceptions
                        dagrab)
@@ -1570,8 +1833,19 @@ do_cdread ()
                esac
                REDIR=">&2"
        fi
+       if [ "$1" = "onetrack" ]; then
+               echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK ..." >&2
+       else
+               if [ -r "$CDDBDATA" ]; then
+                       TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
+                       echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
+               else
+                       echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
+               fi
+       fi
        case "$CDROMREADERSYNTAX" in
-               cdparanoia) nice $READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
+               cdparanoia) 
+                       nice $READNICE $CDROMREADER -d $CDROM ${READTRACKNUMS:-$UTRACKNUM} $FILEARG $REDIR ;;
                cdda2wav)
                        if [ "$OSFLAVOUR" = "OSX" ] ; then
                                # Hei, we have to unmount the device before running anything like cdda2wav in OSX
@@ -1587,7 +1861,7 @@ do_cdread ()
                                        CDDA2WAVCDROM="$CDROMID"
                                fi
                        fi
-                       nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
+                       nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} $FILEARG $REDIR
                        ;;
                ## FIXME ## We have an exception for dagrab, since it uses -f
                ## FIXME ## Shall we just use -f $FILEARG ??
@@ -1656,7 +1930,8 @@ fi
 # Custom filename munging:
 mungefilename ()
 {
-       echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
+       #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
+       echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
 }
 
 # Custom genre munging:
@@ -1672,6 +1947,9 @@ pre_read ()
 :
 }
 
+# do_movecue
+# Standalone function to move the CUE file to the final location
+
 ###############################################################################
 # End of functions
 #
@@ -1790,6 +2068,8 @@ NORMALIZEOPTS=
 CDSPEEDOPTS="-x"
 CDSPEEDVALUE=
 MKCUEOPTS=
+VORBISCOMMENTOPTS="-R"
+METAFLACOPTS="--no-utf8-convert"
 
 # Default to one process if -j isn't specified
 MAXPROCS=1
@@ -1808,6 +2088,7 @@ elif [ X$(uname) = "XDarwin" ] ; then
        OSFLAVOUR=OSX
        # We should have disktool in OSX, but let's be sure...
        NEEDDISKTOOL=y
+       CDROMREADERSYNTAX=cddafs
 elif [ X$(uname) = "XOpenBSD" ] ; then
        HTTPGET=wget
        MD5SUM=md5
@@ -1869,7 +2150,7 @@ fi
 
 # Parse command line options
 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
-while getopts 1a:A:bc:C:d:Dhj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
+while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
@@ -1879,7 +2160,9 @@ while getopts 1a:A:bc:C:d:Dhj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
                C) DISCID="${OPTARG#abcde.}" ;;
                d) CDROM="$OPTARG" ;;
                D) set -x ;;
+               e) ERASEENCODEDSTATUS=y ;;
                h) usage; exit ;;
+               e) ERASEENCODEDSTATUS=y ;;
 #              f) FORCECDDBUSELOCAL=y ;;
                i) INLINETAG=y ;;
                j) MAXPROCS="$OPTARG" ;;
@@ -1911,7 +2194,13 @@ while getopts 1a:A:bc:C:d:Dhj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
                V) EXTRAVERBOSE="y" ;;
                x) EJECTCD="y" ;;
                w) COMMENT="$OPTARG" ;;
-               W) STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}" ;;
+               W) if echo $OPTARG | grep -q "[[:digit:]]" ; then 
+                    STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
+                  else
+                    echo "abcde error: argument of -W must be integer"
+                        exit 1
+                  fi
+                  ;;
                ?) usage; exit ;;
        esac
 done
@@ -1922,7 +2211,7 @@ shift $(($OPTIND - 1))
 if [ "$ONETRACK" = "y" ]; then 
        # FIXME # remove check as soon as we find out about the other readers
        case "$CDROMREADERSYNTAX" in
-               dagrab|cddafs|debug) echo "abcde error: ONETRACK reading is not suported with "$CDROMREADERSYNTAX" yet"
+               dagrab|cddafs|debug) echo "abcde error: ONETRACK reading is not suported with $CDROMREADERSYNTAX yet"
                                         exit 1 ;;
        esac
        if [ "$BATCH" = "y" ]; then
@@ -1984,7 +2273,7 @@ done
 # Sanity checks:
 
 # At this point a CDROM has to be defined, so we check it exists.
-if [ "$CDROM" != "" ] ; then 
+if [ X"$CDROM" != "X" ] ; then 
        if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
                if [ "$OSFLAVOUR" = "FBSD" ]; then
                        if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
@@ -1993,11 +2282,12 @@ if [ "$CDROM" != "" ] ; then
                                exit 1
                        fi
                fi
-       elif [ ! -e $CDROM ] ; then
+       elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
                echo "abcde error: CDROM device cannot be found." >&2
                exit 1
        fi
-else
+# avoid processing if we are not going to hit the CDROM.
+elif [ X"$DOREAD" = "Xy" ]; then
        echo "abcde error: CDROM has not been defined or cannot be found" >&2
        exit 1
 fi
@@ -2143,7 +2433,11 @@ esac
 case "$FLACENCODERSYNTAX" in
        flac)
                FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
-               FLACENCODER="$FLAC"
+               FLACENCODER="$FLAC"     
+               ## FIXME ## FLAC streams can be encapsulated on a Ogg transport layer
+               if echo "$FLACENCODEROPTS" | egrep -q -- "(^| )--ogg($| )" ;then
+                       FLACONOGG=y
+               fi
                ;;
 esac
 case "$SPEEXENCODERSYNTAX" in
@@ -2182,11 +2476,21 @@ if [ "$DISTMP3NICE" ]; then
 fi
 
 # Don't check for stuff if it's not needed
-if [ "$REMOTEHOSTS" ]; then NEEDDISTMP3=y; fi
-[ "$DONORMALIZE" = "y" ] && NEEDNORMALIZER=y
-[ "$EJECTCD" = "y" ] && NEEDEJECT=y
-[ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ] && NEEDHTTPGET=y
-[ "$CUEFILE" = "y" ] && NEEDMKCUE=y
+if [ "$REMOTEHOSTS" ]; then 
+       NEEDDISTMP3=y
+fi
+if [ "$DONORMALIZE" = "y" ]; then
+       NEEDNORMALIZER=y
+fi
+if [ "$EJECTCD" = "y" ]; then
+       NEEDEJECT=y
+fi
+if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
+       NEEDHTTPGET=y
+fi
+if [ "$CUEFILE" = "y" ]; then
+       NEEDMKCUE=y
+fi
 
 if [ X"$CDSPEEDVALUE" != "X" ]; then
        case "$CDROMREADERSYNTAX" in
@@ -2202,6 +2506,7 @@ PIPE_cdparanoia="-"
 # Encoders with USEPIPE support
 # FIXME # Include here all the encoders we can figure out support pipes
 PIPE_lame="-"
+PIPE_bladeenc="-"
 PIPE_oggenc="-"
 
 # Figure out if we can use pipes with the ripper/encoder combination
@@ -2216,7 +2521,7 @@ if [ "$USEPIPES" = "y" ]; then
                flac)
                        PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYTNAX" ;;
                spx)
-                       IPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
+                       PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
                mpc)
                        PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
        esac
@@ -2305,6 +2610,16 @@ if [ X"$CDSPEEDVALUE" != "X" ]; then
        esac
 fi
 
+# Define the first and last track, since we might need them later in several places
+FIRSTTRACK=$( get_first $TRACKQUEUE )
+LASTTRACK=$( get_last $TRACKQUEUE )
+
+if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
+       mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
+       grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
+               | grep -v ^encode-output > "$ABCDETEMPDIR/status"
+fi
+
 # Create playlist if needed (backgroundable) and start reading in tracks
 
 (
@@ -2323,11 +2638,9 @@ if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
 fi
 
 if [ "$ONETRACK" = "y" ]; then 
-       FIRSTTRACK=$( echo $TRACKQUEUE | awk '{print $1}' )
        TRACKS="$FIRSTTRACK"
-       for UTRACKNUM in $TRACKQUEUE; do :;done
        if checkstatus readtrack-$FIRSTTRACK; then :; else
-               do_cdread onetrack $FIRSTTRACK $UTRACKNUM
+               do_cdread onetrack $FIRSTTRACK $LASTTRACK
        fi
 else
        for UTRACKNUM in $TRACKQUEUE
@@ -2335,7 +2648,8 @@ else
                if [ "$DOREAD" = "y" ]; then
                        if [ "$USEPIPES" = "y" ]; then
                                if checkstatus readencodetrack-$UTRACKNUM; then :; else
-                                       do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0%
+                                       # Read, pipe, shut up!
+                                       do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
                                fi
                        else
                                if checkstatus readtrack-$UTRACKNUM; then :; else
@@ -2448,8 +2762,7 @@ fi
 
 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
 if [ "$ONETRACK" = "y" ] ; then
-       FIRSTTRACK=$( echo $TRACKQUEUE | awk '{print $1}')
-       TRACKQUEUE=$FIRSTTRACK
+       TRACKQUEUE="$FIRSTTRACK"
        TRACKS="$FIRSTTRACK"
 fi
 
@@ -2518,8 +2831,8 @@ do
                else
 #                      TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
                        TRACKNUM=$UTRACKNUM
-                       CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
-                       TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
+                       CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
+                       TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
                        splitvarious
                fi
        fi
@@ -2556,6 +2869,12 @@ do
        fi
        ) &
 done
+
+# Lets move the cue file
+if checkstatus cuefile >/dev/null ; then 
+       do_movecue
+fi
+
 # Go through it again and make sure there's no distmp3 stragglers, otherwise
 # we'll delete the files they're working on
 ## FIXME ## Check also for files which are encoded using PIPEs.