Allow cue extraction from a flac file.
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index 6ee7d3b..5b9847a 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -1364,13 +1364,11 @@ do_discid ()
                        disktool -u ${CDROM#/dev/}
                fi
                if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
-                       if [ "$TRACKINFO" = "" ]; then
+                       if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM > /dev/null 2>&1 ; then
                                TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM | $CUE2DISCID)
                        else
-                               if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM > /dev/null 2>&1 ; then :; else
-                                       log error "the input flac file does not contain a cuesheet."
-                                       exit 1
-                               fi
+                               log error "the input flac file does not contain a cuesheet."
+                               exit 1
                        fi
                else
                        case "$CDDBMETHOD" in
@@ -1554,13 +1552,22 @@ do_discid ()
                if checkstatus cuefile > /dev/null 2>&1 ; then :; else
                        CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
                        vecho "Creating cue file..."
-                       if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
-                               echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
-                       else
-                               log warning "reading the CUE sheet with mkcue is still considered experimental"
-                               log warning "and there was a problem with the CD reading. abcde will continue,"
-                               log warning "but consider reporting the problem to the abcde author"
-                       fi
+                       case $CDROMREADERSYNTAX in
+                               flac)
+                                       if $METAFLAC --export-cuesheet-to=- $CDROM > "$ABCDETEMPDIR/$CUEFILE"; then :; else
+                                               log warning "the input flac file does not contain a cuesheet."
+                                       fi
+                                       ;;
+                               *)
+                                       if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
+                                               echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
+                                       else
+                                               log warning "reading the CUE sheet with mkcue is still considered experimental"
+                                               log warning "and there was a problem with the CD reading. abcde will continue,"
+                                               log warning "but consider reporting the problem to the abcde author"
+                                       fi
+                                       ;;
+                       esac
                fi
        fi
        # If we got the CDPARANOIA status and it is not recorded, save it now
@@ -1654,8 +1661,6 @@ do_localcddb ()
                                if   (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
                                        CDDBLOCALFILE="${CDDBLOCALRESULTS}"
                                        CDDBLOCALMATCH=single
-                                       echo "${CDDBLOCALRESULTS}" : $(echo "${CDDBLOCALRESULTS}" | wc -l )
-                                       echo CDDBLOCALMATCH=single
                                elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
                                        CDDBLOCALMATCH=multiple
                                fi
@@ -1672,13 +1677,13 @@ do_localcddb ()
                # If the user has selected to check a local CDDB repo, we proceed with it
                case $CDDBLOCALMATCH in
                        multiple)
-                               echo "Processing multiple matching CDDB entries..." >> "$ABCDETEMPDIR/cddblocalchoices"
+                               echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
                                X=0
                                echo "$CDDBLOCALRESULTS" | while read RESULT ; do
                                        X=$(expr $X + 1)
                                        # List out disc title/author and contents
                                        CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
-                                       cat "$RESULT" >> "${CDDBLOCALREAD}"
+                                       cat "$RESULT" > "${CDDBLOCALREAD}"
                                        {       
                                                echo -n "#$X: "
                                                do_cddbparse "${CDDBLOCALREAD}" 
@@ -1717,7 +1722,7 @@ do_localcddb ()
                                # List out disc title/author and contents
                                do_cddbparse "${CDDBLOCALFILE}"
                                if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
-                                       echo -n "Embedded cuesheet entry found, use ut? [y/n] (y): " >&2
+                                       echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
                                else
                                        echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
                                fi
@@ -2274,12 +2279,12 @@ do_cdread ()
                # the user said
                # We need the first and last track for cdda2wav
                FIRSTTRACK=$2
-               LASTTRACK=$3
+               LASTTRACK=$(expr $3 + 0)
                UTRACKNUM=$FIRSTTRACK
                case "$CDROMREADERSYNTAX" in
                        flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
                        cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
-                       cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
+                       cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
                        *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
                                exit 1 ;;
                esac
@@ -3277,8 +3282,8 @@ for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
        ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
        ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
        ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
-       ${NEEDMPPGAIN+$MPPGAIN} \
-       ${NEEDCUEREADER+$CUEREADER}
+       ${NEEDMPPGAIN+$MPPGAIN} ${NEEDCUEREADER+$CUEREADER} \
+       ${NEEDCUE2DISCID+$CUE2DISCID}
 do
        checkexec "$X"
 done
@@ -3289,15 +3294,15 @@ if [ -x $(which $DIFF) ]; then :; else
        DIFF=""
 fi
 
-# Now that we have metaflac, check if we need cue2discid
-case $CDROMREADERSYNTAX in
-       flac)
-               TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | egrep "[a-f0-9]{8}")
-               if [ "$TRACKINFO" = "" ]; then 
-                       checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
-               fi
-               ;;
-esac
+## Now that we have metaflac, check if we need cue2discid
+#case $CDROMREADERSYNTAX in
+#      flac)
+#              TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | egrep "[a-f0-9]{8}")
+#              if [ "$TRACKINFO" = "" ]; then 
+#                      checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
+#              fi
+#              ;;
+#esac
 
 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
@@ -3332,6 +3337,8 @@ case "$CDDBMETHOD" in
 esac
 
 if [ "$DOCDDB" = "y" ]; then
+       # start with a sane default:
+       CDDBLOCALSTATUS=notfound
        if [ $CDDBUSELOCAL = "y" ]; then
                do_localcddb
        fi