Added info about unicode in the man file.
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index 21dff41..ac99e88 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -57,6 +57,7 @@ echo "       Show dielfs from the CDDB info (year,genre)"
 echo "-S <#> Set the CD speed"
 echo "-t <#> Start the track numbering at a given number"
 echo "-T <#> Same as -t but modifies tag numbering"
+echo "-u     Use UNICODE tags and comments"
 echo "-v     Show version number and exit"
 echo "-V     Be a bit more verbose about what is happening behind the scenes"
 echo "-x     Eject CD after all tracks are read"
@@ -377,6 +378,7 @@ do_replaygain()
                                        ;;
                        esac
                        OUTPUTFILES=""
+                       REPLAYINDEX=0
                        for UTRACKNUM in $TRACKQUEUE
                        do
                                CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
@@ -387,21 +389,22 @@ do_replaygain()
                                ALBUMFILE="$(mungefilename "$DALBUM")"
                                do_gettracknum
                                if [ "$VARIOUSARTISTS" = "y" ]; then
-                                       OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
+                                       OUTPUTFILE="$(eval echo $VAOUTPUTFORMAT)"
                                else
-                                       OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
+                                       OUTPUTFILE="$(eval echo $OUTPUTFORMAT)"
                                fi
-                               OUTPUTFILES="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT $OUTPUTFILES"
+                               OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
+                               (( REPLAYINDEX = $REPLAYINDEX + 1 ))
                        done
                        case "$OUTPUT" in
                                flac)
-                                       run_command replaygain-flac $METAFLAC --add-replay-gain $OUTPUTFILES
+                                       run_command replaygain-flac $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
                                        ;;
                                vorbis|ogg)
-                                       run_command replaygain-vorbis $VORBISGAIN --album $OUTPUTFILES
+                                       run_command replaygain-vorbis $VORBISGAIN --album "${OUTPUTFILES[@]}"
                                        ;;
                                mp3)
-                                       run_command replaygain-mp3 $MP3GAIN -a $OUTPUTFILES
+                                       run_command replaygain-mp3 $MP3GAIN -a "${OUTPUTFILES[@]}"
                                        ;;
                                *);;
                        esac
@@ -854,6 +857,8 @@ do_encode ()
                        esac
                        if [ X"$USEPIPES" = "Xy" ]; then
                                RUN_COMMAND=""
+                               # We need a way to store the creation of the files when using PIPES
+                               RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
                        else
                                run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
                                RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
@@ -928,9 +933,9 @@ do_encode ()
                                ;;
                        wav)
                                # In case of wav output we need nothing. Just keep the wavs.
-                               run_command encodetrack-$OUTPUT-$1 true
                                ;;
                        esac
+                       $RUN_COMMAND_PIPES
                done
                # Only remove .wav if the encoding succeeded
                if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
@@ -2273,8 +2278,12 @@ fi
 decho ()
 {
 if [ x"$DEBUG" != "x" ]; then
-       DEBUGECHO=$(echo "$@" | tr -d '[]')
-       echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
+       if echo $1 | grep -q "^\[" ; then
+               DEBUGECHO=$(echo "$@" | tr -d '[]')
+               echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
+       else
+               echo "[DEBUG] $1"
+       fi
 fi
 }
 
@@ -2443,6 +2452,7 @@ MKCUEOPTS=
 MKTOCOPTS=""
 VORBISCOMMENTOPTS="-R"
 METAFLACOPTS="--no-utf8-convert"
+DIFFOPTS=
 
 # Default to one process if -j isn't specified
 MAXPROCS=1
@@ -2532,7 +2542,7 @@ fi
 
 # Parse command line options
 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
-while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:vVxw:W:z opt ; do
+while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:uvVxw:W:z opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
@@ -2565,11 +2575,9 @@ while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:vVxw:W:z opt ; do
                R) DOREPLAYGAIN=y ;;
                s) SHOWCDDBFIELDS="$OPTARG" ;;
                S) CDSPEEDVALUE="$OPTARG" ;;
-#              t) PREPROCESSFORMATS="$OPTARG"
-#                 PREPROCESS=y ;;
-#              T) POSTPROCESSFORMATS="$OPTARG" ;;
                t) STARTTRACKNUMBER="$OPTARG" ;;
                T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
+               u) CDDBPROTO=6 ;;
                v) 
                   echo "This is abcde v$VERSION."
                   echo "Usage: abcde [options] [tracks]"
@@ -2603,6 +2611,9 @@ if echo $CDROM | grep -i -q '.flac$'; then
        fi
 fi
 
+# If the user provided a DISCID, disable eject
+if [ -n "$DISCID" ]; then EJECTCD=n ; fi
+
 # Decide if we can continue.
 if [ "$ONETRACK" = "y" ]; then 
        # FIXME # remove check as soon as we find out about the other readers
@@ -3015,9 +3026,12 @@ if [ X"$CDSPEEDVALUE" != "X" ]; then
        esac
 fi
 
+###USEPIPESSUPPORT###
+
 # Rippers with USEPIPE support
 # FIXME # Include here all the rippers we can figure out support pipes
 PIPERIPPER_cdparanoia="-"
+PIPERIPPER_debug="-"
 PIPERIPPER_flac="-c "
 
 # Encoders with USEPIPE support
@@ -3043,13 +3057,17 @@ if [ "$USEPIPES" = "y" ]; then
                mpc)
                        PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
        esac
-       if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] ; then
+       decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
+       if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
+          [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
                log error "no support for pipes with given ripper"
                log error "read the USEPIPES file from the source tarball to get help."
                log error "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
                exit 1;
        fi
-       if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] ; then
+       decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
+       if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
+          [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
                log error "no support for pipes with given encoder"
                log error "read the USEPIPES file from the source tarball to help"
                log error "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
@@ -3195,6 +3213,11 @@ else
                if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
                    :
                else
+                       # If we are not reading, set the encode output to loud already, so
+                       # that we can see the output of the first track.
+                       if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
+                               echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
+                       fi
                        echo NEXTTRACK # Get the encoder machine churning again
                        if [ "$DOREAD" = "y" ]; then
                                if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
@@ -3448,6 +3471,11 @@ wait
 if [ "$DOREPLAYGAIN" = "y" ]; then
        do_replaygain
 fi
+
+# FIXME #
+# Check if all the encoded formats have been actually moved to the final destination
+# ...
+
 # Check to see if run_command logged any errors
 if [ -f "$ABCDETEMPDIR/errors" ]; then
        log error "The following commands failed to run:"