- trunk/FAQ
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index 44875bd..64efdf0 100755 (executable)
--- a/abcde
+++ b/abcde
 # Copyright for this work is to expire January 1, 2010, after which it
 # shall be public domain.
 
-VERSION="2.1pre2.2.0"
+VERSION="2.2.4"
 
 usage ()
 {
 echo "This is abcde v$VERSION."
 echo "Usage: abcde [options] [tracks]"
 echo "Options:"
-echo "-1    Encode the whole CD in a single file"
-echo "-a    Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
-echo "-A    Experimental actions (retag, transcode)"
-echo "-b    Batch mode: enable album normalization and nogap encoding"
-echo "-c    Specify a configuration file (overrides system and user config files)"
-echo "-C    Specify discid to resume from (only needed if you no longer have the cd)"
-echo "-d    Specify CDROM device to grab"
-echo "-D    Debugging mode (equivalent to sh -x abcde)"
-echo "-h    This help information"
+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 "-b     Batch mode: enable album normalization and nogap encoding"
+echo "-c <file>"
+echo "       Specify a configuration file (overrides system and user config files)"
+echo "-C <discid#>"
+echo "       Specify discid to resume from (only needed if you no longer have the cd)"
+echo "-d <device>"
+echo "       Specify CDROM device to grab"
+echo "-D     Debugging mode (equivalent to sh -x abcde)"
+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"
-echo "-k    Keep the wav tracks for later use"
-echo "-l    Use low disk space algorithm"
-echo "-L    Use local CDDB storage directory"
-echo "-n    No lookup. Don't query CDDB, just create and use template"
-echo "-N    Noninteractive. Never prompt for anything"
-echo "-m    Modify playlist to include CRLF endings, to comply with some players"
-echo "-o    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 "-r    [host1,host2...] Also encode on these remote hosts"
-echo "-R    Add replaygain values to the tag info (only for ogg,flac)"
-echo "-s    Start the track numbering at a given number [DEPRECATED: use -t]"
-echo "-S    Set the CD speed"
+echo "-j <#> Number of encoder processes to run at once (localhost)"
+echo "-k     Keep the wav tracks for later use"
+echo "-l     Use low disk space algorithm"
+echo "-L     Use local CDDB storage directory"
+echo "-n     No lookup. Don't query CDDB, just create and use template"
+echo "-N     Noninteractive. Never prompt for anything"
+echo "-m     Modify playlist to include CRLF endings, to comply with some players"
+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 "-r <host1[,host2]...>"
+echo "       Also encode on these remote hosts"
+echo "-R     Add replaygain values to the tag info (only for ogg,flac)"
+echo "-S <#> Set the CD speed"
 #echo "-t    File types to preprocess (wav)"
 #echo "-T    Set postprocessing options"
-echo "-t    Start the track numbering at a given number"
-echo "-T    Start the track numbering at a given number, modifying tag numbering"
-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"
-echo "-w    [comment] Add a comment to the CD tracks"
+echo "-t <#> Start the track numbering at a given number"
+echo "-T <#> Same as -t but modifies tag numbering"
+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"
+echo "-w <comment>"
+echo "       Add a comment to the CD tracks"
+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."
 }
@@ -412,7 +420,7 @@ do_encode ()
                for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
                do
                        OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
-                       echo "Encoding track $1 of $TRACKS: $TRACKNAME..." >&2
+                       run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
                        case "$OUTPUT" in
                        mp3)
                                case "$2" in
@@ -750,13 +758,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 ))
@@ -835,7 +843,7 @@ 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' ' ' )
+                                               TRACKS=$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 | 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
@@ -1258,6 +1266,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
@@ -1558,12 +1567,27 @@ 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"
@@ -1613,7 +1637,7 @@ do_cdread ()
                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"
+               echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
                return $RETURN
        else
                echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
@@ -1661,9 +1685,11 @@ pre_read ()
 :
 }
 
+###############################################################################
 # End of functions
 #
 # Start of execution
+###############################################################################
 
 # Builtin defaults
 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
@@ -1853,7 +1879,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" ;;
@@ -1894,24 +1920,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
@@ -1981,6 +2011,26 @@ else
        exit 1
 fi
 
+# USEPIPES is not compatible with:
+# - multiple outputs
+# - normalize
+# - anything else?
+if [ "$USEPIPES" = "y" ]; then
+       if [ $(echo $OUTPUTTYPE | tr , \  | wc -w ) -gt 1 ]; then
+               echo "abcde error: Unix pipes not compatible with multiple outputs"
+               exit 1
+       fi
+       if [ "$DONORMALIZE" = "y" ]; 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 [ "$DOENCODE" = "n" ]; then
+               vecho "Disabling Unix pipes since we are not encoding!"
+               USEPIPES=n
+       fi
+fi
+
 # Decide which CDROM reader we're gonna use
 case "$CDROMREADERSYNTAX" in
        cdparanoia|debug)
@@ -2195,42 +2245,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
@@ -2249,6 +2268,10 @@ if [ "$ONETRACK" = "y" ]; then
        for UTRACKNUM in $TRACKQUEUE; do :;done
        if checkstatus readtrack-$FIRSTTRACK; then :; else
                do_cdread_one $UTRACKNUM $FIRSTTRACK
+               # FIXME # Allow ranges of tracks to be encoded in one track
+               # FIXME # do_cdread onetrack $FIRSTTRACK $UTRACKNUM
+               # Until we have it we must use:
+               #do_cdread onetrack $FIRSTTRACK $UTRACKNUM
        fi
 else
        for UTRACKNUM in $TRACKQUEUE
@@ -2434,7 +2457,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
@@ -2518,3 +2541,6 @@ else
 fi
 )
 exit 0
+
+# b:is_bash
+# vim:tabstop=4