* If we don't find any CDDB or Musicbrainz information for the CD, try
authorSteve McIntyre <steve@einval.com>
Fri, 20 Apr 2012 01:07:51 +0000 (01:07 +0000)
committerSteve McIntyre <steve@einval.com>
Fri, 20 Apr 2012 01:07:51 +0000 (01:07 +0000)
    to extract CD-Text information to populate the cddbinfo template.
    (Closes issue 41).

abcde
changelog

diff --git a/abcde b/abcde
index 34e0546..33f7128 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -2229,6 +2229,58 @@ do_localcddb ()
        fi
 }
 
+# do_cdtext
+# Try to read CD-Text from the drive using icedax / cdda2wav
+do_cdtext ()
+{
+       if new_checkexec icedax; then
+               CDTEXT_READER=icedax
+       elif new_checkexec cdda2wav; then
+               CDTEXT_READER=cdda2wav
+    else
+               # Didn't find either, bail
+               return 0
+       fi
+
+       if [ "$CDROMID" = "" ]; then
+               CDDA2WAVCDROM="$CDROM"
+       else
+               CDDA2WAVCDROM="$CDROMID"
+       fi
+
+       # Do we have CD-Text on the disc (and can the drive read it?)
+       ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > $ABCDETEMPDIR/cd-text 2>&1
+       grep -q '^CD-Text: detected' $ABCDETEMPDIR/cd-text
+       ERRORCODE=$?
+       if [ $ERRORCODE -ne 0 ]; then
+               # No CD-Text found, bail
+               return 0
+       fi
+
+       rm -f "$ABCDETEMPDIR/cddbchoices"
+       CDDBCHOICES=1
+       # Make an empty template
+       $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
+       echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
+       echo "done." >> "$ABCDETEMPDIR/cddbchoices"
+       echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
+       echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
+       ATITLE=$(grep -e '^Album title:' ${ABCDETEMPDIR}/cd-text | cut -c14- )
+       echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
+       # List out disc title/author and contents
+       echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
+       for TRACK in $(f_seq_row 1 $TRACKS)
+       do
+               TRACKM1=$(($TRACK - 1))
+               TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | cut -c11- | tr -d \\r\\n)"
+               echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
+               sed -i "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" $ABCDETEMPDIR/cddbread.1
+       done
+       sed -i "s~^DTITLE=.*~DTITLE=${ATITLE}~" $ABCDETEMPDIR/cddbread.1
+       echo >> "$ABCDETEMPDIR/cddbchoices"
+       echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
+}
+
 # do_musicbrainz
 # Work with the musicbrainz WS API, then transform the results here so
 # they look (very) like the results from CDDB. Maybe not the best way
@@ -4022,6 +4074,13 @@ if [ "$DOCDDB" = "y" ]; then
                                        ;;
                        esac
                fi
+               CHOICE=$(checkstatus cddb-choice)
+               if [ $CHOICE = 0 ] ; then
+                       # We don't have any information at all; try to fall back
+                       # to CD-Text for basic information
+                       vecho "No CDDB information found, trying cdtext from the CD"
+                       do_cdtext
+               fi
        fi
        do_cddbedit
 
index db13477..1d73e32 100644 (file)
--- a/changelog
+++ b/changelog
@@ -25,6 +25,9 @@ abcde 2.5.1 UNRELEASED
     far) and a new vvecho() function for callers to use.
   * With EXTRAVERBOSE==2 or more, make run_command() print out each
     command as it's run. (Closes issue 39).
+  * If we don't find any CDDB or Musicbrainz information for the CD, try
+    to extract CD-Text information to populate the cddbinfo template.
+    (Closes issue 41).
 
   [ Colin Tuckley ]
   * replace deprecated egrep with grep -E (Closes issue 24).