Doc rework
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index a447509..c874b1f 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -26,7 +26,7 @@ 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 "-f    Force the use of a local CDDB entry. Otherwise use an empty template"
+echo "-f    Force the use of a local CDDB entry. Use an empty template if not found"
 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"
@@ -40,13 +40,16 @@ 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 "-r    [host1,host2...] Also encode on these remote hosts"
 echo "-R    Add replaygain values to the tag info (ogg,flac)"
-echo "-s    Start the track numbering at a given number"
+echo "-s    Start the track numbering at a given number [DEPRECATED: use -t]"
 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 "Tracks is a space-delimited list of tracks to grab."
 echo "Ranges specified with hyphens are allowed."
 }
@@ -275,6 +278,13 @@ do_tag ()
 {
        COMMENTOUTPUT="$(eval echo ${COMMENT})"
        run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
+       # If we want to start the tracks with a given number, we need to modify the
+       # TRACKNUM value before evaluation
+       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 ))
+       fi
        for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
        do
        case "$OUTPUT" in
@@ -332,7 +342,7 @@ do_tag ()
                        if [ -n "$CDGENRE" ]; then
                        echo GENRE="$CDGENRE"
                 fi     
-               echo TRACKNUMBER=$1
+               echo TRACKNUMBER=${TRACKNUM:-$1}
                echo CDDB=$CDDBDISCID
                if [ "$(eval echo ${COMMENT})" != "" ]; then
                        case "$COMMENTOUTPUT" in
@@ -1017,36 +1027,41 @@ do_localcddb ()
                USELOCALRESP="y"
                
                # If the user has selected to check a local CDDB repo, we proceed with it
-               if [ "$CDDBUSELOCAL" = "y" ]; then
-                       if [ -r "${CDDBLOCALFILE}" ]; then
-                               # List out disc title/author and contents
-                               do_cddbparse "${CDDBLOCALFILE}"
-                               echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
-                               if [ "$INTERACTIVE" = "y" ]; then
+               if [ -r "${CDDBLOCALFILE}" ]; then
+                       # List out disc title/author and contents
+                       do_cddbparse "${CDDBLOCALFILE}"
+                       echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
+                       if [ "$INTERACTIVE" = "y" ]; then
+                               read USELOCALRESP
+                               while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
+                                       echo -n 'Invalid selection. Please answer "y" or "n": '
                                        read USELOCALRESP
-                                       while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
-                                               echo -n 'Invalid selection. Please answer "y" or "n": '
-                                               read USELOCALRESP
-                                       done
-                                       [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
-                               else
-                                       echo "y" >&2
-                               fi
-                               if [ "$USELOCALRESP" = "y" ]; then
-                               #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"
-                                       do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
-                                       echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
-                                       CDDBLOCALSUCCESS="y"
-                               else
-                                       #echo "Not using local copy of CDDB data"
-                                       CDDBLOCALSUCCESS="n"
-                               fi
+                               done
+                               [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
                        else
+                               echo "y" >&2
+                       fi
+                       if [ "$USELOCALRESP" = "y" ]; then
+                       #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"
+                               do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
+                               echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
+                               CDDBLOCALSUCCESS="y"
+                       else
+                               #echo "Not using local copy of CDDB data"
                                CDDBLOCALSUCCESS="n"
                        fi
+               elif [ "$FORCECDDBUSELOCAL" = "y" ]; then
+                       $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
+                       echo 998 > "$ABCDETEMPDIR/cddbquery" # Assuming 998 isn't used by CDDB
+                       echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
+                       do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
+                       echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
+                       CDDBLOCALSUCCESS="y"
+               else
+                       CDDBLOCALSUCCESS="n"
                fi
        fi
 }
@@ -1308,6 +1323,10 @@ do_cddbedit ()
                                if [ "$USELOCALRESP" = "y" ]; then :; else
                                        if [ -n "$CHOICE" ] ; then
                                                case $CDDBCHOICES in
+                                                       0) 
+                                                       UNKNOWNDISK=y
+                                                       echo "Selected template."
+                                                       ;;
                                                        1) cat "$ABCDETEMPDIR/cddbchoices" ;;
                                                        *)
                                                        echo "Selected: #$CHOICE"
@@ -1612,7 +1631,7 @@ do_cdread ()
                cddafs)
                        # Find the track's mounted path
                        REALTRACKNUM=$(expr $UTRACKNUM + 0)
-                       FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \([^(]*\) (.*/\1/')
+                       FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
                        FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
                        # If the file exists, copy it
                        if [ -e "$FILEPATH" ] ; then
@@ -1867,7 +1886,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:vVx opt ; do
+while getopts 1a:A:bc:C:d:Dfhj:klLnNo:pr:Rs:S:t:T:vVxw: opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
@@ -1893,9 +1912,11 @@ while getopts 1a:A:bc:C:d:Dhj:klLnNo:pr:Rs:S:vVx opt ; do
                R) REPLAYGAIN=y ;;
                s) STARTTRACKNUMBER="$OPTARG" ;;
                S) CDSPEEDVALUE="$OPTARG" ;;
-               t) PREPROCESSFORMATS="$OPTARG"
-                  PREPROCESS=y ;;
-               T) POSTPROCESSFORMATS="$OPTARG" ;;
+#              t) PREPROCESSFORMATS="$OPTARG"
+#                 PREPROCESS=y ;;
+#              T) POSTPROCESSFORMATS="$OPTARG" ;;
+               t) STARTTRACKNUMBER="$OPTARG" ;;
+               T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
                v) 
                   echo "This is abcde v$VERSION."
                   echo "Usage: abcde [options] [tracks]"
@@ -1904,6 +1925,7 @@ while getopts 1a:A:bc:C:d:Dhj:klLnNo:pr:Rs:S:vVx opt ; do
                   ;;
                V) EXTRAVERBOSE="y" ;;
                x) EJECTCD="y" ;;
+               w) COMMENT="$OPTARG" ;;
                ?) usage; exit ;;
        esac
 done
@@ -2127,7 +2149,7 @@ HTTPGET="$HTTPGET $HTTPGETOPTS"
 
 # Here it used to say:
 # One thousand lines in, we can start doing stuff with things
-# Well, right now we are at line 2116 ;)
+# Well, right now we are at line 2139 ;)
 
 # List of valid actions: cddb,read,normalize,encode,tag,playlist,move,clean
 # List of experimental actions: retag,transcode