Added YEAR as a variable for creating playlists
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index fb409e2..af7282d 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -62,6 +62,7 @@ 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."
 echo ""
 echo "Tracks is a space-delimited list of tracks to grab."
 echo "Ranges specified with hyphens are allowed."
+#echo "Double hyphens are used to concatenate tracks"
 }
 
 # Funtions to replace the need of seq, which is too distribution dependant.
 }
 
 # Funtions to replace the need of seq, which is too distribution dependant.
@@ -504,12 +505,12 @@ do_tag ()
                                echo ARTIST="$TRACKARTIST"
                                echo ALBUM="$DALBUM"
                                echo TITLE="$TRACKNAME"
                                echo ARTIST="$TRACKARTIST"
                                echo ALBUM="$DALBUM"
                                echo TITLE="$TRACKNAME"
-                                       if [ -n "$CDYEAR" ]; then
+                               if [ -n "$CDYEAR" ]; then
                                        echo DATE="$CDYEAR"
                                        echo DATE="$CDYEAR"
-                                       fi
-                               if [ -n "$CDGENRE" ]; then
+                               fi
+                               if [ -n "$CDGENRE" ]; then
                                        echo GENRE="$CDGENRE"
                                        echo GENRE="$CDGENRE"
-                               fi      
+                               fi      
                                echo TRACKNUMBER=${TRACKNUM:-$1}
                                echo CDDB=$CDDBDISCID
                                if [ "$(eval echo ${COMMENT})" != "" ]; then
                                echo TRACKNUMBER=${TRACKNUM:-$1}
                                echo CDDB=$CDDBDISCID
                                if [ "$(eval echo ${COMMENT})" != "" ]; then
@@ -822,9 +823,18 @@ do_encode ()
 #      done
 #}
 
 #      done
 #}
 
+# do_single_gain
+# variables used:
+# FIXME #
+do_single_gain ()
+{
+:
+}
+
 # do_batch_gain
 # variables used:
 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
 # do_batch_gain
 # variables used:
 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
+# FIXME #
 do_batch_gain ()
 {
        # The commands here don't go through run_command because they're never supposed to be silenced
 do_batch_gain ()
 {
        # The commands here don't go through run_command because they're never supposed to be silenced
@@ -958,6 +968,7 @@ do_playlist ()
                ALBUMFILE=$(mungefilename "$DALBUM")
                ARTISTFILE=$(mungefilename "$DARTIST")
                GENRE=$(mungegenre "$GENRE")
                ALBUMFILE=$(mungefilename "$DALBUM")
                ARTISTFILE=$(mungefilename "$DARTIST")
                GENRE=$(mungegenre "$GENRE")
+               YEAR=${CDYEAR:-$CDYEAR}
                if [ "$VARIOUSARTISTS" = "y" ] ; then
                        PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
                else
                if [ "$VARIOUSARTISTS" = "y" ] ; then
                        PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
                else
@@ -1046,7 +1057,13 @@ do_discid ()
        #elif [ -z "$DISCID" ]; then
        if [ -z "$DISCID" ]; then
                vecho -n "Getting CD track info... "
        #elif [ -z "$DISCID" ]; then
        if [ -z "$DISCID" ]; then
                vecho -n "Getting CD track info... "
+               if [ "$OSFLAVOUR" = "OSX" ]; then
+                       disktool -u ${CDROM#/dev/}
+               fi
                TRACKINFO=$($CDDISCID $CDROM)
                TRACKINFO=$($CDDISCID $CDROM)
+               if [ "$OSFLAVOUR" = "OSX" ]; then
+                       disktool -m ${CDROM#/dev/}
+               fi
                # Make sure there's a CD in there by checking cd-discid's return code
                if [ "$?" = "1" ]; then
                        echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
                # Make sure there's a CD in there by checking cd-discid's return code
                if [ "$?" = "1" ]; then
                        echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
@@ -1203,9 +1220,10 @@ do_discid ()
                cat /dev/null > "$ABCDETEMPDIR/status"
        fi
        if [ X"$CUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
                cat /dev/null > "$ABCDETEMPDIR/status"
        fi
        if [ X"$CUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
-               if checkstatus cuefile ; then :; else
-                       $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/cue-$(echo $TRACKINFO | cut -f1 -d' ').txt
-                       echo cuefile >> "$ABCDETEMPDIR/status"
+               if checkstatus cuefile >/dev/null ; then :; else
+                       CUEFILE=cue-$(echo $TRACKINFO | cut -f3 -d' ').txt
+                       $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/$CUEFILE
+                       echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
                fi
        fi
        # If we got the CDPARANOIA status and it is not recorded, save it now
                fi
        fi
        # If we got the CDPARANOIA status and it is not recorded, save it now
@@ -1221,6 +1239,19 @@ do_discid ()
        echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
 }
 
        echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
 }
 
+# do_cleancue
+# Create a proper CUE file based on the CUE file we created before.
+do_cleancue()
+{
+       if checkstatus cuefile; then :; else
+               $CUEFILE_INPUT="$ABCDETEMPDIR/cue-$(echo $TRACKINFO | cut -f1 -d' ').txt"
+               ### FIXME ### checkstatus cddb
+               if [ "$DOCDDB" = "y" ]; then
+               MARKER  
+               fi
+       fi
+}
+
 # do_cddbparse
 # Parses a CDDB file and outputs the title and the track names.
 # Variables: CDDBFILE
 # do_cddbparse
 # Parses a CDDB file and outputs the title and the track names.
 # Variables: CDDBFILE
@@ -1267,7 +1298,7 @@ do_localcddb ()
                                echo "y" >&2
                        fi
                        if [ "$USELOCALRESP" = "y" ]; then
                                echo "y" >&2
                        fi
                        if [ "$USELOCALRESP" = "y" ]; then
-                       #echo "Using local copy of CDDB data"
+                               #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"
                                cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
                                echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
                                echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
@@ -1278,7 +1309,6 @@ do_localcddb ()
                                #echo "Not using local copy of CDDB data"
                                CDDBLOCALSUCCESS="n"
                        fi
                                #echo "Not using local copy of CDDB data"
                                CDDBLOCALSUCCESS="n"
                        fi
-                       CDDBLOCALSUCCESS="y"
                else
                        CDDBLOCALSUCCESS="n"
                fi
                else
                        CDDBLOCALSUCCESS="n"
                fi
@@ -1774,9 +1804,10 @@ do_cdread ()
                # We need the first and last track for cdda2wav
                FIRSTTRACK=$2
                LASTTRACK=$3
                # We need the first and last track for cdda2wav
                FIRSTTRACK=$2
                LASTTRACK=$3
+               UTRACKNUM=$FIRSTTRACK
                case "$CDROMREADERSYNTAX" in
                case "$CDROMREADERSYNTAX" in
-                       cdparanoia) UTRACKNUM="1-" ;;
-                       cdda2wav) UTRACKNUM="1+$LASTRACK" ;;
+                       cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
+                       cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
                        *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
                           exit 1 ;;
                esac
                        *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
                           exit 1 ;;
                esac
@@ -1802,14 +1833,19 @@ do_cdread ()
                esac
                REDIR=">&2"
        fi
                esac
                REDIR=">&2"
        fi
-       if [ -r "$CDDBDATA" ]; then
-               TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
-               echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
+       if [ "$1" = "onetrack" ]; then
+               echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK ..." >&2
        else
        else
-               echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
+               if [ -r "$CDDBDATA" ]; then
+                       TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
+                       echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
+               else
+                       echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
+               fi
        fi
        case "$CDROMREADERSYNTAX" in
        fi
        case "$CDROMREADERSYNTAX" in
-               cdparanoia) nice $READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
+               cdparanoia) 
+                       nice $READNICE $CDROMREADER -d $CDROM ${READTRACKNUMS:-$UTRACKNUM} $FILEARG $REDIR ;;
                cdda2wav)
                        if [ "$OSFLAVOUR" = "OSX" ] ; then
                                # Hei, we have to unmount the device before running anything like cdda2wav in OSX
                cdda2wav)
                        if [ "$OSFLAVOUR" = "OSX" ] ; then
                                # Hei, we have to unmount the device before running anything like cdda2wav in OSX
@@ -1825,7 +1861,7 @@ do_cdread ()
                                        CDDA2WAVCDROM="$CDROMID"
                                fi
                        fi
                                        CDDA2WAVCDROM="$CDROMID"
                                fi
                        fi
-                       nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
+                       nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} $FILEARG $REDIR
                        ;;
                ## FIXME ## We have an exception for dagrab, since it uses -f
                ## FIXME ## Shall we just use -f $FILEARG ??
                        ;;
                ## FIXME ## We have an exception for dagrab, since it uses -f
                ## FIXME ## Shall we just use -f $FILEARG ??
@@ -1911,6 +1947,9 @@ pre_read ()
 :
 }
 
 :
 }
 
+# do_movecue
+# Standalone function to move the CUE file to the final location
+
 ###############################################################################
 # End of functions
 #
 ###############################################################################
 # End of functions
 #
@@ -2049,6 +2088,7 @@ elif [ X$(uname) = "XDarwin" ] ; then
        OSFLAVOUR=OSX
        # We should have disktool in OSX, but let's be sure...
        NEEDDISKTOOL=y
        OSFLAVOUR=OSX
        # We should have disktool in OSX, but let's be sure...
        NEEDDISKTOOL=y
+       CDROMREADERSYNTAX=cddafs
 elif [ X$(uname) = "XOpenBSD" ] ; then
        HTTPGET=wget
        MD5SUM=md5
 elif [ X$(uname) = "XOpenBSD" ] ; then
        HTTPGET=wget
        MD5SUM=md5
@@ -2240,6 +2280,7 @@ if [ X"$CDROM" != "X" ] ; then
                                echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
                                echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
                                exit 1
                                echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
                                echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
                                exit 1
+                       fi
                fi
        elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
                echo "abcde error: CDROM device cannot be found." >&2
                fi
        elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
                echo "abcde error: CDROM device cannot be found." >&2
@@ -2816,6 +2857,8 @@ do
                        fi
                fi
        fi
                        fi
                fi
        fi
+       if [ "$DOTAG" = "y" ]; then
+               if checkstatus encodetrack-$UTRACKNUM; then
                        if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
                fi
        fi
                        if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
                fi
        fi
@@ -2826,6 +2869,12 @@ do
        fi
        ) &
 done
        fi
        ) &
 done
+
+# Lets move the cue file
+if checkstatus cuefile >/dev/null ; then 
+       do_movecue
+fi
+
 # Go through it again and make sure there's no distmp3 stragglers, otherwise
 # we'll delete the files they're working on
 ## FIXME ## Check also for files which are encoded using PIPEs.
 # Go through it again and make sure there's no distmp3 stragglers, otherwise
 # we'll delete the files they're working on
 ## FIXME ## Check also for files which are encoded using PIPEs.