r47@yurie: data | 2005-02-16 03:38:54 +0200
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index d6d35fb..30dfc1c 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.0"
+VERSION="2.2.4"
 
 usage ()
 {
@@ -21,7 +21,7 @@ echo "Options:"
 echo "-1     Encode the whole CD in a single file"
 echo "-a <action1[,action2]...>"
 echo "       Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
-echo "-A     Experimental actions (retag, transcode)"
+#echo "-A     Experimental actions (retag, transcode)"
 echo "-b     Batch mode: enable album normalization and nogap encoding"
 echo "-c <file>"
 echo "       Specify a configuration file (overrides system and user config files)"
@@ -42,7 +42,7 @@ echo "-m     Modify playlist to include CRLF endings, to comply with some player
 echo "-o <type1[,type2]...>"
 echo "       Output file type(s) (ogg,mp3,flac,spx,mpc). Defaults to ogg"
 echo "-p     Pad track numbers with 0's (if less than 10 tracks)"
-#echo "-P    Use UNIX pipes to read+encode without wav files"
+echo "-P     Use UNIX pipes to read+encode without wav files"
 echo "-r <host1[,host2]...>"
 echo "       Also encode on these remote hosts"
 echo "-R     Add replaygain values to the tag info (only for ogg,flac)"
@@ -358,7 +358,7 @@ do_tag ()
                                *)   echo COMMENT="$COMMENTOUTPUT";;
                        esac    
                fi
-                ) | run_command tagtrack-$1 $METAFLAC --import-vc-from=- --no-utf8-convert "$ABCDETEMPDIR/track$1.$OUTPUT"
+                ) | run_command tagtrack-$1 $METAFLAC --import-tags-from=- --no-utf8-convert "$ABCDETEMPDIR/track$1.$OUTPUT"
                ;;
        spx)
                run_command tagtrack-$1 true
@@ -732,7 +732,6 @@ do_playlist ()
                FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
                mkdir -p "$FINALPLAYLISTDIR"
                if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
-                       #echo -n "Erase any existing playlist file? [y/n] (y): " >&2
                        echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
                        if [ "$INTERACTIVE" = "y" ]; then
                                while [ "$DONE" != "y" ]; do
@@ -758,13 +757,13 @@ do_playlist ()
                        do
                                # Shares some code with do_move since the filenames have to match
                                CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
-                               TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
+                               TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
                                splitvarious
                                TRACKFILE=$(mungefilename "$TRACKNAME")
                                ARTISTFILE=$(mungefilename "$TRACKARTIST")
                                # If we want to start the tracks with a given number, we need to modify the
                                # TRACKNUM value before evaluation
-                               if [ -n $STARTTRACKNUMBER ] ; then
+                               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 ))
@@ -843,7 +842,12 @@ do_discid ()
                                cdparanoia|debug)
                                        if [ "$WEHAVEACD" = "y" ]; then
                                                vecho "Querying the CD for audio tracks..."
-                                               TRACKS=$( $CDROMREADER -Q 2>&1 | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 |  awk '{print $1}' | tr -d "." | tr '\n' ' ' )
+                                               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' ' ' )
                                                CDPARANOIAAUDIOTRACKS="$TRACKS"
                                        else
                                                if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks ; then
@@ -858,6 +862,10 @@ do_discid ()
                else
                        TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
                fi
+               if echo "$TRACKS" | grep [[:digit:]] > /dev/null 2>&1 ;then :;else
+                       echo "The disc does not contain any tracks. Giving up..."
+                       exit 0
+               fi
                echo -n "Grabbing entire CD - tracks: "
                if [ ! "$PADTRACKS" = "y" ] ; then
                        TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
@@ -964,10 +972,11 @@ do_discid ()
        fi
        
        # If we got the CDPARANOIA status and it is not recorded, save it now
-       ## FIXME ## ! is non-portable
-       if [ -n "$CDPARANOIAAUDIOTRACKS" ] && ! checkstatus cdparanoia-audio-tracks; then
-               if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
-                       echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
+       if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
+               if checkstatus cdparanoia-audio-tracks; then :; else
+                       if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
+                               echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
+                       fi
                fi
        fi
        
@@ -1266,6 +1275,7 @@ do_cddbedit ()
                                        # I'll take CDDB read #3 for $400, Alex
                                        echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
                                        read CDDBCHOICE
+                                       [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
                                        # Make sure we get a valid choice
                                        CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
                                        while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
@@ -1566,23 +1576,54 @@ do_cdread_one ()
 }
 
 # do_cdread [tracknumber]
+# do_cdread onetrack [firsttrack] [lasttrack]
 # 
 do_cdread ()
 {
        # The commands here don't go through run_command because they're never supposed to be silenced
        # return codes need to be doublechecked anyway, however
-       UTRACKNUM=$1
+       if [ "$1" = "onetrack" ]; then
+               # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
+               # FIXME # Until then, we grab the whole CD in one track, no matter what
+               # the user said
+               # We need the first and last track for cdda2wav
+               FIRSTTRACK=$2
+               LASTTRACK=$3
+               case "$CDROMREADERSYNTAX" in
+                       cdparanoia) UTRACKNUM="1-" ;;
+                       cdda2wav) UTRACKNUM="1+$LASTRACK" ;;
+                       *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
+                          exit 1 ;;
+               esac
+       else
+               UTRACKNUM=$1
+       fi
        CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
        WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
-       OUTDATA="$ABCDETEMPDIR/track$UTRACKNUM.$OUTPUTTYPE"
        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=""
+       else
+               case "$CDROMREADERSYNTAX" in
+               ## FIXME ## Find the case for dagrab, to avoid exceptions
+                       dagrab)
+                               FILEARG="-f $WAVDATA"
+                               ;;
+                       *)
+                               FILEARG=$WAVDATA
+                               ;;
+               esac
+               REDIR=">&2"
+       fi
        case "$CDROMREADERSYNTAX" in
-               cdparanoia) nice $READNICE $CDROMREADER -d $CDROM $UTRACKNUM "$WAVDATA" >&2 ;;
+               cdparanoia) nice $READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
                cdda2wav)
                        if [ "$OSFLAVOUR" = "OSX" ] ; then
                                # Hei, we have to unmount the device before running anything like cdda2wav in OSX
@@ -1598,9 +1639,12 @@ do_cdread ()
                                        CDDA2WAVCDROM="$CDROMID"
                                fi
                        fi
-                       nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM "$WAVDATA" >&2 
+                       nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
+                       ;;
+               ## FIXME ## We have an exception for dagrab, since it uses -f
+               ## FIXME ## Shall we just use -f $FILEARG ??
+               dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM $FILEARG $REDIR
                        ;;
-               dagrab) nice $READNICE $CDROMREADER -d $CDROM -f $WAVDATA -v $UTRACKNUM >&2 ;;
                cddafs)
                        # Find the track's mounted path
                        REALTRACKNUM=$(expr $UTRACKNUM + 0)
@@ -1608,23 +1652,34 @@ do_cdread ()
                        FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
                        # If the file exists, copy it
                        if [ -e "$FILEPATH" ] ; then
-                               nice $READNICE $CDROMREADER "$FILEPATH" "$WAVDATA" >&2
+                               nice $READNICE $CDROMREADER "$FILEPATH" $FILEARG $REDIR
                        else
                                false
                        fi ;;
-               debug) nice $READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] "$WAVDATA" >&2 ;;
+               debug) nice $READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] $FILEARG $REDIR
+                       ;;
        esac
        RETURN=$?
-       if [ "$RETURN" != "0" -o ! -s "$WAVDATA" ]; then
+       # If we get some error or we get some missing wav 
+       # (as long as we dont use pipes)
+       if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
                # Thank goodness errors is only machine-parseable up to the
                # first colon, otherwise this woulda sucked
                if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
                        RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
                fi
-                echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
+               if [ "$USEPIPES" = "y" ]; then
+                       echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
+               else
+                       echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
+               fi
                return $RETURN
        else
-               echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
+               if [ "$USEPIPES" = "y" ]; then
+                       echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
+               else
+                       echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
+               fi
        fi
 }
 
@@ -1669,9 +1724,11 @@ pre_read ()
 :
 }
 
+###############################################################################
 # End of functions
 #
 # Start of execution
+###############################################################################
 
 # Builtin defaults
 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
@@ -1861,7 +1918,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:klLnNo:pr:Rs:S:t:T:vVxw: opt ; do
+while getopts 1a:A:bc:C:d:Dhj:klLnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
@@ -1902,24 +1959,28 @@ while getopts 1a:A:bc:C:d:Dhj:klLnNo:pr:Rs:S:t:T:vVxw: opt ; do
                V) EXTRAVERBOSE="y" ;;
                x) EJECTCD="y" ;;
                w) COMMENT="$OPTARG" ;;
+               W) STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}" ;;
                ?) usage; exit ;;
        esac
 done
 
 shift $(($OPTIND - 1))
 
-# Decide if we can continue. TO_REMOVE as soon as we find out about dagrab
-if [ "$ONETRACK" = "y" ] ; then 
+# Decide if we can continue.
+if [ "$ONETRACK" = "y" ]; then 
+       # FIXME # remove check as soon as we find out about the other readers
        case "$CDROMREADERSYNTAX" in
-               dagrab|debug) echo "abcde error: ONETRACK reading is not suported with "$CDROMREADERSYNTAX" yet"
-                             exit 1 ;;
+               dagrab|cddafs|debug) echo "abcde error: ONETRACK reading is not suported with "$CDROMREADERSYNTAX" yet"
+                                        exit 1 ;;
        esac
        if [ "$BATCH" = "y" ]; then
                echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
+               BATCH=n
        fi
        # It does not matter how many tracks we want. In ONETRACK mode we grab them all
+       # FIXME # allow ranges of tracks to be selected for onetrack ripping
        if [ $# -gt 0 ]; then
-               vecho "ONETRACK mode selected: grabbing all tracks..."
+               vecho "abcde warning: ONETRACK mode selected, grabbing all tracks..."
        fi
 else
        while [ $# -gt 0 ]; do
@@ -1989,6 +2050,32 @@ else
        exit 1
 fi
 
+# USEPIPES pre-tests, before we get into more serious stuff
+# Not compatible with:
+# - multiple outputs
+# - normalize
+# - lowdisk algorithm
+# - anything else?
+if [ X"$USEPIPES" = "Xy" ]; then
+       if [ $(echo $OUTPUTTYPE | tr , \  | wc -w ) -gt 1 ]; then
+               echo "abcde error: Unix pipes not compatible with multiple outputs"
+               exit 1
+       fi
+       if [ X"$DONORMALIZE" = "Xy" ]; then
+               echo "abcde error: Unix pipes not compatible with normalizer"
+               # FIXME # Do we need to exit or shall we just disable the mode?
+               exit 1
+       fi
+       if [ X"$DOENCODE" = "Xn" ]; then
+               vecho "Disabling Unix pipes since we are not encoding!"
+               USEPIPES=n
+       fi
+       if [ X"$LOWDISK" = "Xy" ]; then
+               vecho "abcde error: Unix pipes not compatible with lowdisk algorithm"
+               exit 1
+       fi
+fi
+
 # Decide which CDROM reader we're gonna use
 case "$CDROMREADERSYNTAX" in
        cdparanoia|debug)
@@ -2132,6 +2219,45 @@ if [ X"$CDSPEEDVALUE" != "X" ]; then
        esac
 fi
 
+# Rippers with USEPIPE support
+# FIXME # Include here all the rippers we can figure out support pipes
+PIPE_cdparanoia="-"
+
+# Encoders with USEPIPE support
+# FIXME # Include here all the encoders we can figure out support pipes
+PIPE_lame="-"
+PIPE_oggenc="-"
+
+# Figure out if we can use pipes with the ripper/encoder combination
+# exit otherwise
+if [ "$USEPIPES" = "y" ]; then
+       PIPERIPPERSVARCHECK="PIPE_${CDROMREADER}"
+       case "$OUTPUT" in
+               mp3)
+                       PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
+               ogg)
+                       PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
+               flac)
+                       PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYTNAX" ;;
+               spx)
+                       PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
+               mpc)
+                       PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
+       esac
+       if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
+               echo "abcde error: no support for pipes with given ripper" >&2
+               echo "read the USEPIPES file from the source tarball to help" >&2
+               echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
+               exit 1;
+       fi
+       if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
+               echo "abcde error: no support for pipes with given encoder" >&2
+               echo "read the USEPIPES file from the source tarball to help" >&2
+               echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
+               exit 1;
+       fi
+fi
+
 
 # Make sure a buncha things exist
 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
@@ -2140,7 +2266,7 @@ for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
        ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
        ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
        ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
-       ${NEEDVORBISGAIN+$VORBISGAIN}
+       ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
 do
        # Cut off the command-line options we just added in
        X=$(echo $X | cut -d' ' -f2)
@@ -2203,42 +2329,11 @@ if [ X"$CDSPEEDVALUE" != "X" ]; then
        esac
 fi
 
-if [ "$STRIPDATATRACKS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
-       case "$CDROMREADERSYNTAX" in
-               cdparanoia|debug) 
-                       # cdparanoia can query the CD, so let's process the TRACKQUEUE list with the results.
-                       if checkstatus cdparanoia-audio-tracks; then
-                               CDTRACKQUEUE=$( cat $ABCDETEMPDIR/cdparanoia-audio-tracks )
-                       else
-                               ## FIXME ##
-                               vecho "Querying the CD to obtain a list of valid audio tracks..."
-                               $CDROMREADER -Q > $ABCDETEMPDIR/cdparanoia-query 2>&1
-                               # Obtain a list of valid audio tracks from the results of the query
-                               CDTRACKQUEUE=$( cat $ABCDETEMPDIR/cdparanoia-query | egrep '^[[:space:]]+[[:digit:]]' | awk '{print $1}' | tr -d "." | tr '\n' ' ' )
-                       fi
-                       # Obtain the track padding value from the before-processing list and pad the CD list
-                       TRACKNUMPADDING=$( echo $TRACKQUEUE | awk '{print $1}' | tr -d " \n" | wc -c )
-                       for TRACK in $CDTRACKQUEUE ; do
-                               TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
-                               PADNEWTRACKQUEUE=$(echo $PADNEWTRACKQUEUE $TRACKNUM)
-                       done
-                       CDTRACKQUEUE=$PADNEWTRACKQUEUE
-                       # Now, compare if the values in the list are valid tracks in the CD
-                       for TRACK in $TRACKQUEUE; do
-                               if echo $CDTRACKQUEUE | grep $TRACK >/dev/null ; then
-                                       NEWTRACKQUEUE="$NEWTRACKQUEUE $TRACK"
-                               fi
-                       done
-                       TRACKQUEUE="$NEWTRACKQUEUE"
-               ;;
-       esac
-fi
-
 # Create playlist if needed (backgroundable) and start reading in tracks
 
 (
 
-if [ "$ONETRACK" = "y" ]; then :; else
+if [ ! "$ONETRACK" = "y" ]; then
        if [ "$DOPLAYLIST" = "y" ]; then
                echo Creating playlist... >&2
                do_playlist
@@ -2256,14 +2351,21 @@ if [ "$ONETRACK" = "y" ]; then
        TRACKS="$FIRSTTRACK"
        for UTRACKNUM in $TRACKQUEUE; do :;done
        if checkstatus readtrack-$FIRSTTRACK; then :; else
-               do_cdread_one $UTRACKNUM $FIRSTTRACK
+               #do_cdread_one $UTRACKNUM $FIRSTTRACK
+               do_cdread onetrack $FIRSTTRACK $UTRACKNUM
        fi
 else
        for UTRACKNUM in $TRACKQUEUE
        do
                if [ "$DOREAD" = "y" ]; then
-                       if checkstatus readtrack-$UTRACKNUM; then :; else
-                               do_cdread $UTRACKNUM
+                       if [ "$USEPIPES" = "y" ]; then
+                               if checkstatus readencodetrack-$UTRACKNUM; then :; else
+                                       do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0%
+                               fi
+                       else
+                               if checkstatus readtrack-$UTRACKNUM; then :; else
+                                       do_cdread $UTRACKNUM
+                               fi
                                if [ "$?" != "0" ]; then
                                        # CD read failed - don't give the goahead to
                                        # the encoder
@@ -2393,7 +2495,7 @@ do
        read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
        if [ "$GOAHEAD" = "NO" ]; then break; fi
        # find out where this track is to be encoded
-       if [ "$DOENCODE" = "y" ]; then
+       if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
                # Make sure we have a place to encode this, if not, exit stage right
                if [ -z "$ENCODELOCATIONS" ]; then
                        continue
@@ -2442,7 +2544,7 @@ do
 #                      TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
                        TRACKNUM=$UTRACKNUM
                        CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
-                       TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
+                       TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
                        splitvarious
                fi
        fi
@@ -2455,7 +2557,7 @@ do
                        if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
                fi
        fi
-       if [ "$DOENCODE" = "y" ]; then
+       if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
                if checkstatus readtrack-$UTRACKNUM; then
                        #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
                        if [ "$DONORMALIZE" = "y" ]; then
@@ -2481,7 +2583,8 @@ do
 done
 # Go through it again and make sure there's no distmp3 stragglers, otherwise
 # we'll delete the files they're working on
-if [ "$DOENCODE" = "y" ]; then
+## FIXME ## Check also for files which are encoded using PIPEs.
+if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
        PROCEED=
        until [ $PROCEED ]
        do
@@ -2526,3 +2629,6 @@ else
 fi
 )
 exit 0
+
+# b:is_bash
+# vim:tabstop=4