last changes before 2.2
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index 44875bd..22bb6fd 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.0"
 
 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 "-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...] 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 "-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,7 +758,7 @@ 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")
@@ -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
@@ -1661,9 +1670,11 @@ pre_read ()
 :
 }
 
+###############################################################################
 # End of functions
 #
 # Start of execution
+###############################################################################
 
 # Builtin defaults
 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
@@ -1853,7 +1864,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:pr:Rs:S:t:T:vVxw:W: opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
@@ -1894,6 +1905,7 @@ 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
@@ -2434,7 +2446,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