Concatenate option steps on -t/-T option
[abcde.git] / abcde
diff --git a/abcde b/abcde
index 258b728..c607b72 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -1,6 +1,8 @@
 #!/bin/bash
 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
+# Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
+# Copyright (c) 2012      Steve McIntyre <93sam@@debian.org>
 # This code is hereby licensed for public consumption under either the
 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
 #
@@ -13,7 +15,7 @@
 #
 # $Id$
 
-VERSION='2.5.1-UNRELEASED'
+VERSION='2.5.5-UNRELEASED'
 
 usage ()
 {
@@ -43,20 +45,17 @@ 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 "       WARNING: Deprecated. Use \"cue\" action"
 #echo "-M     Create a CUE file"
+echo "-n     No lookup. Don't query CDDB, just create and use template"
+echo "-N     Noninteractive. Never prompt for anything"
 echo "-o <type1[,type2]...>"
-echo "       Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
+echo "       Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus). Defaults to vorbis"
 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 "-q <level>"
-echo "       Set quality level (high,medium,low)"
 echo "-r <host1[,host2]...>"
 echo "       Also encode on these remote hosts"
-echo "-R     Use local CDDB in recursive mode"
 echo "-s <field>"
 echo "       Show fields from the CDDB info (year,genre)"
 echo "-S <#> Set the CD speed"
@@ -96,7 +95,7 @@ log ()
        esac
 }
 
-# Funtions to replace the need of seq, which is too distribution dependant.
+# Functions to replace the need of seq, which is too distribution dependent.
 f_seq_row ()
 {
        i=$1
@@ -118,7 +117,7 @@ f_seq_line ()
                done
                echo
        else
-               log error "syntax error while processing track numbers"
+               log error "syntax error while processing track numbers ($i)"
                exit 1
        fi
 }
@@ -246,6 +245,7 @@ page ()
 # Runs a command, silently if necessary, and updates the status file
 run_command ()
 {
+       vvecho "$@"
        BLURB="$1"
        shift
        # See if this is supposed to be silent
@@ -431,8 +431,8 @@ getcddbinfo()
 gettracknum()
 {
        if [ -n "$STARTTRACKNUMBER" ] ; then
-               # Get the trackpadding from the current track
-               CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
+               # Get the trackpadding from the current track, also trim whitespace for MacOSX
+               CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
                TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
        else
                TRACKNUM=${UTRACKNUM}
@@ -491,7 +491,7 @@ makeids ()
 
        case "$CDDBMETHOD" in
                cddb)
-                       printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
+                       printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
                        ;;
                musicbrainz)
                        # FIXME: don't assume the first track is 1
@@ -513,6 +513,9 @@ do_replaygain()
                                vorbis|ogg)
                                        OUTPUT=$OGGOUTPUTCONTAINER
                                        ;;
+                               opus)
+                                       OUTPUT=$OPUSOUTPUTCONTAINER
+                                       ;;
                                flac)
                                        OUTPUT=$FLACOUTPUTCONTAINER
                                        ;;
@@ -822,13 +825,18 @@ do_tag ()
                                eyed3)
                                        # FIXME # track numbers in mp3 come with 1/10, so we cannot
                                        # happily substitute them with $TRACKNUM
+                                       # FIXME as well! # Older versions of eyeD3 (< 0.7.0) expect
+                                       # --set-encoding and --set-text-frame so perhaps some version 
+                                       # sniffing would be useful. Might also be better to simply cut 
+                                       # ties with the older eyeD3... Andrew.
+                                       # eyeD3 --comment syntax is also different in < and >= 0.7.0
                                        run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
-                                               --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
-                                               -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
+                                               --comment="$COMMENTOUTPUT" -A "$DALBUM" \
+                                               -a "$TRACKARTIST" -t "$TRACKNAME" ${CDYEAR:+-Y "$CDYEAR"} \
                                                -G "$GENREID" -n "${TRACKNUM:-$1}" \
-                                               "${TRACKNUM:+-N $TRACKS}" \
-                                               "${ENCODING:+--set-encoding=$ENCODING}" \
-                                               "${TPE2:+--set-user-text-frame=TPE2:$TPE2}" \
+                                               ${TRACKNUM:+-N "$TRACKS"} \
+                                               ${ENCODING:+--encoding="$ENCODING"} \
+                                               ${TPE2:+--text-frame=TPE2:"$TPE2"} \
                                                "$ABCDETEMPDIR/track$1.$OUTPUT"
                                        ;;
                                # FIXME # Still not activated...
@@ -896,6 +904,10 @@ do_tag ()
                                        ;;
                        esac
                        ;;
+               opus)
+                       run_command tagtrack-$OUTPUT-$1 true
+                       ;;
+
                flac)
                        (
                        echo ARTIST="$TRACKARTIST"
@@ -937,7 +949,7 @@ do_tag ()
                        fi
 
                        #It has to be command file opts for AtomicParsley
-                       run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $ATOMICPARSLEY $ABCDETEMPDIR/track$1.m4a --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --tracknum ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --compilation $VARIOUSBOOL --comment "$COMMENTOUTPUT" --output $ATOMICTEMPFILE
+                       run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $ATOMICPARSLEY "$ABCDETEMPDIR/track$1.m4a" --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --tracknum ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --compilation $VARIOUSBOOL --comment "$COMMENTOUTPUT" --output $ATOMICTEMPFILE
                        if [ -f $ATOMICTEMPFILE ]; then
                                mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
                        fi
@@ -1016,6 +1028,9 @@ do_encode ()
                        vorbis|ogg)
                                TEMPARG="PIPE_$OGGENCODERSYNTAX"
                                ;;
+                       opus)
+                               TEMPARG="PIPE_$OPUSENCODERSYNTAX"
+                               ;;
                        flac)
                                TEMPARG="PIPE_$FLACENCODERSYNTAX"
                                ;;
@@ -1023,10 +1038,10 @@ do_encode ()
                                TEMPARG="PIPE_$SPEEXENCODER"
                                ;;
                        mpc)
-                               TEMPARG="PIPE_$MPPENCODER"
+                               TEMPARG="PIPE_$MPCENCODER"
                                ;;
                        m4a)
-                               TEMPARG="PIPE_$MPPENCODER"
+                               TEMPARG="PIPE_$AACENCODERSYNTAX"
                                ;;
                esac
                IN="$( eval echo "\$$TEMPARG" )"
@@ -1058,6 +1073,9 @@ do_encode ()
                                vorbis|ogg)
                                        OUTPUT=$OGGOUTPUTCONTAINER
                                        ;;
+                               opus)
+                                       OUTPUT=$OPUSOUTPUTCONTAINER
+                                       ;;
                                flac)
                                        OUTPUT=$FLACOUTPUTCONTAINER
                                        ;;
@@ -1113,6 +1131,32 @@ do_encode ()
                                        ;;
                                esac
                                ;;
+                       opus)
+                               case "$2" in
+                               %local*%)
+                                       case "$OPUSENCODERSYNTAX" in
+                                       opusenc) 
+
+                                           if [ "$(eval echo ${COMMENT})" != "" ]; then
+                                               case "$COMMENT" in
+                                                   *=*) ;;
+                                                    *)   COMMENT="COMMENT=$COMMENT" ;;
+                                               esac    
+                                           fi
+                                           # Tag the file at encode time, as it can't be done after encoding.
+                                           if [ "$DOTAG" = "y" ]; then
+                                              $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
+                                           else
+                                             $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"  
+                                           fi
+                                             ;;
+                                       esac
+                                       ;;
+                               *)
+                                       $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
+                                       ;;
+                               esac
+                               ;;
                        flac)
                                case "$2" in
                                %local*%)
@@ -1133,27 +1177,26 @@ do_encode ()
                                                *=*) ;;
                                                *)   COMMENT="COMMENT=$COMMENT" ;;
                                        esac    
-                                       COMMENT="--comment \"$COMMENT\""
                                fi
-                               # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
-                               if [ "$DOTAG" = "y" ]; then
-                                       $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" --comment "$COMMENT" "$IN" "$OUT"
+                               # Tag the file at encode time, as it can't be done after encoding.
+                               if [ "$DOTAG" = "y" ]; then
+                                       $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
                                else
                                        $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
                                fi
                                ;;
                        mpc)    
                                # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
-                               # tagging.
-                               # I tried compiling the mppenc from corecodecs.org and got some
-                               # errors, so I have not tried it myself.
-                               ## FIXME ## Needs some cleanup to determine if an empty tag sent
-                               ## FIXME ## to the encoder ends up empty.
-                               $RUN_COMMAND nice $EFFECTIVE_NICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
+                               # tagging. Uses mpcenc for Musepack SV8 encoding, changed from
+                               # Musepack SV7 which used mppenc....
+                               $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
                                ;;
                        m4a)
-                               # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
-                               if [ ! "$DOTAG" = "y" ]; then
+                               # Tag the file at encode time, as it can't be done after encoding.
+                               if [ "$AACENC" = "neroAacEnc" ] ; then
+                                       DOTAG=y
+                                       $RUN_COMMAND nice $ENCNICE $AACENC $AACENCOPTS -if "$IN" -of "$OUT"
+                                                                       elif [ ! "$DOTAG" = "y" ]; then
                                        $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
                                        
                                else
@@ -1396,6 +1439,9 @@ do_move ()
                                vorbis|ogg)
                                        OUTPUT=$OGGOUTPUTCONTAINER
                                        ;;
+                               opus)
+                                       OUTPUT=$OPUSOUTPUTCONTAINER
+                                       ;;
                                flac)
                                        OUTPUT=$FLACOUTPUTCONTAINER
                                        ;;
@@ -1477,6 +1523,9 @@ do_playlist ()
                        vorbis|ogg)
                                OUTPUT=$OGGOUTPUTCONTAINER
                                ;;
+                       opus)
+                               OUTPUT=$OPUSOUTPUTCONTAINER
+                               ;;
                        flac)
                                OUTPUT=$FLACOUTPUTCONTAINER
                                ;;
@@ -1556,7 +1605,7 @@ do_playlist ()
                ## this will convert the playlist to have CRLF line-endings, if specified
                ## (some hardware players insist on CRLF endings)
                if [ "$DOSPLAYLIST" = "y" ]; then
-                       awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
+                       awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
 #                      mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
                        cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
                fi
@@ -1704,7 +1753,7 @@ abcde.mkcue () {
        shift 2
 
        echo REM DISCID $DISCID
-       echo FILE \""$CUEWAVEFILE"\" WAVE
+       echo FILE \""$CUEWAVFILE"\" WAVE
 
        if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
                OFFSET=$1
@@ -1742,7 +1791,7 @@ do_discid ()
                vecho -n "Getting CD track info... "
                # In OSX, unmount the disc before a query
                if [ "$OSFLAVOUR" = "OSX" ]; then
-                       disktool -u ${CDROM#/dev/}
+                       diskutil unmount ${CDROM#/dev/}
                fi
                case "$CDROMREADERSYNTAX" in
                        flac)
@@ -1814,7 +1863,7 @@ do_discid ()
                fi
                # In OSX, remount the disc again
                if [ "$OSFLAVOUR" = "OSX" ]; then
-                       disktool -m ${CDROM#/dev/}
+                       diskutil mount ${CDROM#/dev/}
                fi
                WEHAVEACD=y
                DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
@@ -1929,7 +1978,7 @@ do_discid ()
                if [ ! -f "$ABCDETEMPDIR/discid" ]; then
                        # Wipe and start fresh
                        echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
-                       echo -n "this directory to continue. Continue? [y/n] (n)" >&2
+                       echo -n "this directory to continue. Continue [y/N]? " >&2
                        if [ "$INTERACTIVE" = "y" ]; then
                                read ANSWER
                        else
@@ -2194,9 +2243,9 @@ do_localcddb ()
                                # List out disc title/author and contents
                                do_cddbparse "${CDDBLOCALFILE}"
                                #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
-                               #       echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
+                               #       echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
                                #else
-                                       echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
+                                       echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
                                #fi
                                if [ "$INTERACTIVE" = "y" ]; then
                                        read USELOCALRESP
@@ -2229,6 +2278,69 @@ 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 [ "$OSFLAVOUR" = "OSX" ] ; then
+               # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
+               diskutil unmount ${CDROM#/dev/}
+               # Also, in OSX the cdrom device for cdda2wav/icedax changes...
+               CDDA2WAVCDROM="IODVDServices"
+       elif [ "$OSFLAVOUR" = "FBSD" ] ; then
+               CDDA2WAVCDROM="$CDROMID"
+       else
+               if [ "$CDROMID" = "" ]; then
+                       CDDA2WAVCDROM="$CDROM"
+               else
+                       CDDA2WAVCDROM="$CDROMID"
+               fi
+       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" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
+               echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
+               sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
+        mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
+       done
+       sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
+    mv -f "$ABCDETEMPDIR/cddbread.new" "$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
@@ -2243,27 +2355,11 @@ do_musicbrainz ()
                rm -f "$ABCDETEMPDIR/cddbchoices"
                CDDBCHOICES=1 # Overridden by multiple matches
                MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
-               ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir $ABCDETEMPDIR
+               ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
 
                # The helper script will write disc matches out to
                # cddbread.*. Count how many we have
-               NUM_RESPONSES=$(echo ${ABCDETEMPDIR}/cddbread.* | wc -w)
-               if [ "$NUM_RESPONSES" -eq 1 ] ; then
-                       # One exact match
-                       echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
-                       echo "done." >> "$ABCDETEMPDIR/cddbchoices"
-                       echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
-                       echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
-                       ATITLE=$(grep -e '^DTITLE=' ${ABCDETEMPDIR}/cddbread.1 | cut -c8- )
-                       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
-                               echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
-                       done
-                       echo >> "$ABCDETEMPDIR/cddbchoices"
-               elif [ "$NUM_RESPONSES" -eq 0 ] ; then
+               if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
                        # No matches. Use the normal cddb template for the user to
                        # fill in
                        echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
@@ -2280,23 +2376,42 @@ do_musicbrainz ()
                        echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
                        echo 503 > "$ABCDETEMPDIR/cddbquery"
                else
-                       echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
-                       echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
-                       for file in $ABCDETEMPDIR/cddbread.*
-                       do
-                               X=$(echo $file | sed 's/^.*cddbread\.//g')
-                               echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
-                               ATITLE=$(grep -e '^DTITLE=' ${ABCDETEMPDIR}/cddbread.$X | cut -c8- )
-                               echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
+                       # We have some matches
+                       NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
+                       if [ "$NUM_RESPONSES" -eq 1 ] ; then
+                               # One exact match
+                               echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
+                               echo "done." >> "$ABCDETEMPDIR/cddbchoices"
+                               echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
+                               echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
+                               ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
+                               echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
                                # List out disc title/author and contents
-                               echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
+                               echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
                                for TRACK in $(f_seq_row 1 $TRACKS)
                                do
-                                       echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
+                                       echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
                                done
                                echo >> "$ABCDETEMPDIR/cddbchoices"
-                       done
-                       echo "." >> "$ABCDETEMPDIR/cddbquery"
+                       else
+                               echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
+                               echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
+                               for file in "$ABCDETEMPDIR"/cddbread.*
+                               do
+                                       X=$(echo $file | sed 's/^.*cddbread\.//g')
+                                       echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
+                                       ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
+                                       echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
+                                       # List out disc title/author and contents
+                                       echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
+                                       for TRACK in $(f_seq_row 1 $TRACKS)
+                                       do
+                                               echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
+                                       done
+                                       echo >> "$ABCDETEMPDIR/cddbchoices"
+                               done
+                               echo "." >> "$ABCDETEMPDIR/cddbquery"
+                       fi
                fi
                echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
        fi
@@ -2333,6 +2448,9 @@ do_cddbstat ()
                                                2??)    # Server responded, everything seems OK
                                                        rc=0
                                                        ;;
+                                               *)      # unknown error
+                                                       break
+                                                       ;;
                                        esac
                                        ;;
                                esac
@@ -2630,18 +2748,18 @@ do_cddbedit ()
                exit 1
        fi
        CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
-       echo -n "Edit selected CDDB data? [y/n] (" >&2
+       echo -n "Edit selected CDDB data? " >&2
        if [ "$INTERACTIVE" = "y" ]; then
                if [ "$UNKNOWNDISK" = "y" ]; then
-                       echo -n "y): " >&2
+                       echo -n "[Y/n] (y): " >&2
                        read EDITCDDB
                        [ "$EDITCDDB" != "n" ] && EDITCDDB=y
                else
-                       echo -n "n): " >&2
+                       echo -n "[y/N] (n): " >&2
                        read EDITCDDB
                fi
        else
-               echo "n): n" >&2
+               echo "[y/N] (n): n" >&2
                EDITCDDB=n
        fi
        if [ "$EDITCDDB" = "y" ]; then
@@ -2692,7 +2810,7 @@ do_cddbedit ()
                echo "Looks like a Multi-Artist CD" >&2
                VARIOUSARTISTS=y
        else
-               echo -n "Is the CD multi-artist? [y/n] (n): " >&2
+               echo -n "Is the CD multi-artist [y/N]? " >&2
                if [ "$INTERACTIVE" = "y" ]; then
                        read VARIOUSARTISTS
                else
@@ -2783,7 +2901,7 @@ do_cddbedit ()
 
                        # submit the modified file, if they want
                        if [ "$NOSUBMIT" != "y" ]; then
-                               echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
+                               echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
                                read YESNO
                                while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
                                        [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
@@ -2833,6 +2951,7 @@ do_cdread ()
                                # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
                                READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
                        cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
+                       pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
                        *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
                                exit 1 ;;
                esac
@@ -2888,7 +3007,7 @@ do_cdread ()
                cdda2wav | icedax)
                        if [ "$OSFLAVOUR" = "OSX" ] ; then
                                # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
-                               disktool -u ${CDROM#/dev/} 0
+                               diskutil unmount ${CDROM#/dev/}
                                # Also, in OSX the cdrom device for cdda2wav/icedax changes...
                                CDDA2WAVCDROM="IODVDServices"
                        elif [ "$OSFLAVOUR" = "FBSD" ] ; then
@@ -2913,6 +3032,12 @@ do_cdread ()
                        else
                                nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG"
                        fi ;;
+               pird)
+                       if [ "$REDIR" = "y" ]; then
+                               nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
+                       else
+                               nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
+                       fi ;;
                cddafs)
                        # Find the track's mounted path
                        REALTRACKNUM=$(expr $UTRACKNUM + 0)
@@ -2975,10 +3100,23 @@ do_cdspeed ()
 
 # vecho [message]
 #
-# vecho outputs a message if EXTRAVERBOSE is selected
+# vecho outputs a message if EXTRAVERBOSE is 1 or more
 vecho ()
 {
-if [ x"$EXTRAVERBOSE" != "x" ]; then
+if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
+       case $1 in
+               warning) shift ; log warning "$@" ;;
+               *) echo "$@" ;;
+       esac
+fi
+}
+
+# vvecho [message]
+#
+# vvecho outputs a message if EXTRAVERBOSE is 2 or more
+vvecho ()
+{
+if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
        case $1 in
                warning) shift ; log warning "$@" ;;
                *) echo "$@" ;;
@@ -3066,9 +3204,10 @@ ENCODERSYNTAX=default
 
 MP3ENCODERSYNTAX=default
 OGGENCODERSYNTAX=default
+OPUSENCODERSYNTAX=default
 FLACENCODERSYNTAX=default
 SPEEXENCODERSYNTAX=default
-MPPENCODERSYNTAX=default
+MPCENCODERSYNTAX=default
 AACENCODERSYNTAX=default
 NORMALIZERSYNTAX=default
 CUEREADERSYNTAX=default
@@ -3116,26 +3255,29 @@ MP3ENC=mp3enc
 # ogg
 VORBIZE=vorbize
 OGGENC=oggenc
+#opus
+OPUSENC=opusenc
 # flac
 FLAC=flac
 # speex
 SPEEXENC=speexenc
 # mpp (Musepack)
-MPPENC=mppenc
+MPCENC=mpcenc
 # m4a
 AACENC=faac
 
 ID3=id3
-ID3V2=id3v2
 EYED3=eyeD3
 VORBISCOMMENT=vorbiscomment
 METAFLAC=metaflac
 AACTAG=faac
+ATOMICPARSLEY=AtomicParsley
 
 CDPARANOIA=cdparanoia
 CDDA2WAV=icedax
 DAGRAB=dagrab
 CDDAFS=cp
+PIRD=pird
 CDDISCID=cd-discid
 CDDBTOOL=cddb-tool
 MUSICBRAINZ=abcde-musicbrainz-tool
@@ -3166,18 +3308,23 @@ MP3GAINOPTS="-a -k"
 VORBIZEOPTS=
 OGGENCOPTS=
 VORBISGAINOPTS="--album"
+#opus
+OPUSENCOPTS=
 # flac
 FLACOPTS=
 FLACGAINOPTS="--add-replay-gain"
 # speex
 SPEEXENCOPTS=
 # mpc
-MPPENCOPTS=
+MPCENCOPTS=
 # m4a
 AACENCOPTS=
 
 ID3OPTS=
-ID3V2OPTS=
+# FIXME # Older versions of eyeD3 (< 0.7.0) expect --set-encoding=utf16-LE
+# so perhaps some version sniffing would be useful. Or perhaps it might be
+# better to simply cut ties with the older eyeD3... Andrew.
+EYED3OPTS="--encoding utf16"
 CDPARANOIAOPTS=
 CDDA2WAVOPTS=
 DAGRABOPTS=
@@ -3200,20 +3347,14 @@ MAXPROCS=1
 # List of actions to perform - by default, run to completion
 ACTIONS=cddb,read,encode,tag,move,clean
 
-# This option is basicaly for Debian package dependencies:
-# List of prefered outputs - by default, run with whatever we have in the path
-DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac
-
-# List of prefered cdromreaders - by default, run whichever we have in the path
-DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav"
+# This option is basically for Debian package dependencies:
+# List of preferred outputs - by default, run with whatever we have in the path
+DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
 
-# List of quality levels associated with the encoders:
-DEFAULT_QUALITY_XLO="oggenc:-q -1,lame:-q 9,speex:--quality 1,m4a:"
-DEFAULT_QUALITY_LO="oggenc:-q 1,lame:-q 7,speex:--quality 5,m4a:"
-DEFAULT_QUALITY_HI="oggenc:-q 7,lame:--preset standard,speex:--quality 9,m4a:"
-DEFAULT_QUALITY_XHI="oggenc:-q 10,lame:--preset extreme,speex:--quality 10,m4a:"
+# List of preferred cdromreaders - by default, run whichever we have in the path
+DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav pird"
 
-# Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
+# Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
 # Linux/OpenBSD. ftp is user for NetBSD.
 # Let's use these checkings to determine the OS flavour, which will be used
 # later
@@ -3225,9 +3366,11 @@ if [ X$(uname) = "XFreeBSD" ] ; then
 elif [ X$(uname) = "XDarwin" ] ; then
        HTTPGET=curl
        OSFLAVOUR=OSX
-       # We should have disktool in OSX, but let's be sure...
-       NEEDDISKTOOL=y
+       # We should have diskutil in OSX, but let's be sure...
+       NEEDDISKUTIL=y
        CDROMREADERSYNTAX=cddafs
+       # We won't find the eject program in OSX, and doing checkexec will fail further below...
+       unset EJECT
 elif [ X$(uname) = "XOpenBSD" ] ; then
        HTTPGET=wget
        MD5SUM=md5
@@ -3245,10 +3388,7 @@ else
 fi
 
 # If CDDBAVAIL is set to n, no CDDB read is done
-# If USEID3 is set to n, no ID3 tagging is done
 CDDBAVAIL=y
-USEID3=y
-USEID3V2=y
 
 # There we go..
 # But before we get into business, let us chop off any GREP environmental
@@ -3292,8 +3432,12 @@ fi
 if [ "$CDROM" = "" ] ; then
        if [ -e /dev/cdroms/cdrom0 ]; then
                CDROM=/dev/cdroms/cdrom0
+       elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part.*(disk.)$'\n' ]]; then
+               CDROM=/dev/${BASH_REMATCH[1]}
        elif [ -e /dev/cdrom ]; then
                CDROM=/dev/cdrom
+       elif [ -e /dev/sr0 ]; then
+               CDROM=/dev/sr0
        elif [ -e /dev/cd0c ]; then
                CDROM=/dev/cd0c
        elif [ -e /dev/acd0c ]; then
@@ -3303,15 +3447,25 @@ if [ "$CDROM" = "" ] ; then
        fi
 fi
 
+# We used to use EXTRAVERBOSE=y to turn on more debug output. Now
+# that's changed to a number to allow for more control. Deal with
+# EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
+case "$EXTRAVERBOSE"x in
+       "*y*"x|"*Y*"x)
+               EXTRAVERBOSE=1
+               ;;
+       "*n*"x|"*N*")
+               EXTRAVERBOSE=0
+               ;;
+esac
+
 # Parse command line options
-#while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPq:r:Rs:S:t:T:vVxw:W: opt ; do
-while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPq:r:s:S:t:T:UvVxX:w:W:z opt ; do
+while getopts 1a:bc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
                A) EXPACTIONS="$OPTARG" ;;
                b) BATCHNORM=y ;;
-               B) NOBATCHREPLAYGAIN=y ;;
                c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
                C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
                d) CDROM="$OPTARG" ;;
@@ -3333,7 +3487,6 @@ while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPq:r:s:S:t:T:UvVxX:w:W:z opt ; do
                o) OUTPUTTYPE="$OPTARG" ;;
                p) PADTRACKS=y ;;
                P) USEPIPES=y ;;
-               q) QUALITYLEVEL="$OPTARG" ;;
                r) REMOTEHOSTS="$OPTARG" ;;
                R) CDDBLOCALRECURSIVE=y ;;
                s) SHOWCDDBFIELDS="$OPTARG" ;;
@@ -3347,12 +3500,12 @@ while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPq:r:s:S:t:T:UvVxX:w:W:z opt ; do
                   echo "abcde -h for extra help"
                   exit
                   ;;
-               V) EXTRAVERBOSE="y" ;;
+               V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
                x) EJECTCD="y" ;;
                X) CUE2DISCID="$OPTARG" ;;
                w) COMMENT="$OPTARG" ;;
                W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
-                        STARTTRACKNUMBER="${OPTARG}01"
+                        STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
                         STARTTRACKNUMBERTAG="y"
                         COMMENT="CD${OPTARG}"
                         DISCNUMBER="${OPTARG}"
@@ -3419,6 +3572,7 @@ if [ "$ONETRACK" = "y" ]; then
                flac) ;;
                cdparanoia) ;;
                cdda2wav | icedax) ;;
+               pird) ;;
                *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
                        exit 1 ;;
        esac
@@ -3440,7 +3594,8 @@ else
                # Range parsing code courtesy of Vincent Ho
                # Cleaned up to use shell built-ins by Charles Steinkuehler
                if [ "${1#*[^0-9-]}" != "$1" ]; then
-                       log error "syntax error while processing track numbers"
+                       log error "syntax error while processing track numbers ($1)"
+                       exit 1
                else
                        RSTART=${1%%-*}
                        REND=${1##*-}
@@ -3510,7 +3665,7 @@ if [ X"$CDROM" != "X" ] ; then
                if [ "$OSFLAVOUR" = "FBSD" ]; then
                        if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
                                log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
-                               log error "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
+                               log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
                                exit 1
                        fi
                fi
@@ -3612,6 +3767,10 @@ case "$CDROMREADERSYNTAX" in
                CDROMREADER="$DAGRAB"
                CDROMREADEROPTS="$DAGRABOPTS"
                ;;
+       pird)
+               CDROMREADER="$PIRD"
+               CDROMREADEROPTS="$PIRDOPTS"
+               ;;
        cddafs)
                CDROMREADER="$CDDAFS"
                CDROMREADEROPTS="$CDDAFSOPTS"
@@ -3631,14 +3790,16 @@ case "$NORMALIZERSYNTAX" in
 esac
 
 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
-if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
-       for OUTPUT in "$(echo "$OUTPUTTYPE" | tr \  \|| tr , \ | tr \| \ )"; do
+case "$OUTPUTTYPE" in *:*)
+       for OUTPUT in $(echo "$OUTPUTTYPE" | tr \  \|| tr , \ ); do
+               OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
                case "$OUTPUT" in
                        vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
+                       opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
                        mp3:*)  MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
                        flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
                        spx:*)  SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
-                       mpc:*)  MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
+                       mpc:*)  MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
                        m4a:*)  AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
                esac
        done
@@ -3647,10 +3808,11 @@ if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
                TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
        done
        OUTPUTTYPE="$TEMPOUTPUTTYPE"
-fi
+       ;;
+esac
 
 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
-# for flacs and speexenc for speex and mppenc for mpps and faac for m4as
+# for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as
 
 # Getting ready for multiple output changes
 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
@@ -3662,6 +3824,10 @@ do
                        [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
                        OGGOUTPUTCONTAINER=ogg
                        ;;
+               opus)
+                       [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
+                       OPUSOUTPUTCONTAINER=opus
+                       ;;
                mp3)
                        [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
                        [ "$DOTAG" = "y" ] && NEEDTAGGER=y
@@ -3678,7 +3844,7 @@ do
 #                      [ "$DOREPLAYGAIN" = "y" ] &&
                        ;;
                mpc)
-                       [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
+                       [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
                        [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN=y
                        ;;
                m4a)
@@ -3738,6 +3904,12 @@ case "$OGGENCODERSYNTAX" in
                OGGENCODER="$OGGENC"
                ;;
 esac
+case "$OPUSENCODERSYNTAX" in
+       opusenc)
+               OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
+               OPUSENCODER="$OPUSENC"
+               ;;
+esac
 case "$FLACENCODERSYNTAX" in
        flac)
                FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
@@ -3762,10 +3934,10 @@ case "$SPEEXENCODERSYNTAX" in
                SPEEXENCODER="$SPEEXENC"
                ;;
 esac
-case "$MPPENCODERSYNTAX" in
-       mppenc)
-               MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
-               MPPENCODER="$MPPENC"
+case "$MPCENCODERSYNTAX" in
+       mpcenc)
+               MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
+               MPCENCODER="$MPCENC"
                ;;
 esac
 case "$AACENCODERSYNTAX" in
@@ -3780,8 +3952,9 @@ if [ "$ID3TAGV" = "1" ]; then
        TAGGER="$ID3"
        TAGGEROPTS="$ID3OPTS"
 else
-       TAGGER="$ID3V2"
-       TAGGEROPTS="$ID3V2OPTS"
+       TAGGER="$EYED3"
+       TAGGEROPTS="$EYED3OPTS"
+       ID3SYNTAX=eyed3
 fi
 
 # NOGAP is specific to lame. Other encoders fail ...
@@ -3850,6 +4023,7 @@ fi
 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
        case "$CDROMREADERSYNTAX" in
                cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
+               pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
                ### FIXME ### translate "cue2discid" from python to bash
                flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
                *) NEEDCDSPEED=y ;;
@@ -3863,12 +4037,14 @@ fi
 PIPERIPPER_cdparanoia="-"
 PIPERIPPER_debug="-"
 PIPERIPPER_flac="-c "
+PIPERIPPER_pird="-"
 
 # Encoders with USEPIPE support
 # FIXME # Include here all the encoders we can figure out support pipes
 PIPE_lame="-"
 PIPE_bladeenc="-"
 PIPE_oggenc="-"
+PIPE_opusenc="-"
 PIPE_flac="-"
 
 # Figure out if we can use pipes with the ripper/encoder combination
@@ -3880,12 +4056,14 @@ if [ "$USEPIPES" = "y" ]; then
                        PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
                vorbis|ogg)
                        PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
+               opus)
+                       PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
                flac)
                        PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
                spx)
                        PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
                mpc)
-                       PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
+                       PIPEENCODERSVARCHECK="PIPE_$MPCENCODER" ;;
        esac
        decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
        if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
@@ -3907,13 +4085,13 @@ fi
 
 # Make sure a buncha things exist
 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
-       $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
-       $AACENCODER \
+       $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
+       $AACENCODER $CDDBTOOL \
        ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
        ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
        ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
        ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
-       ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
+       ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
        ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
        ${NEEDMPPGAIN+$MPPGAIN} ${NEEDCUEREADER+$CUEREADER} \
        ${NEEDCUE2DISCID+$CUE2DISCID}
@@ -3965,7 +4143,7 @@ if [ "$DOREAD" = "y" ]; then
        #  - set the CD speed value with eject -x
        vecho -n "Executing customizable pre-read function... "
 
-       pre_read # Execute the user-defined pre-read funtion. Close the CD with it.
+       pre_read # Execute the user-defined pre-read function. Close the CD with it.
 
        vecho "done."
 fi
@@ -3994,6 +4172,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
 
@@ -4005,6 +4190,7 @@ fi
 if [ X"$CDSPEEDVALUE" != "X" ]; then
        case "$CDROMREADERSYNTAX" in
                cdparanoia|debug) ;;
+               pird) ;;
                flac) ;;
                *) do_cdspeed ;;
        esac
@@ -4113,12 +4299,12 @@ if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
        echo NEXTTRACK
 fi
 
-# Execute the user-defined post_read funtion before ejecting CD
+# Execute the user-defined post_read function before ejecting CD
 post_read
 
 # We are now finished with the cdrom - it can be safely ejected. Note that
 # abcde will not have completed yet.
-if [ "$EJECTCD" = "y" ] && [ -x $(which $EJECT) ]; then
+if [ "$EJECTCD" = "y" ]; then
        # We check if the disk we are processing is actually the disk inside the
        # CD tray. If not, we do not eject the CD, since it might be so that the
        # user ejected it manually.
@@ -4134,8 +4320,8 @@ if [ "$EJECTCD" = "y" ] && [ -x $(which $EJECT) ]; then
                cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
                $eject $EJECTOPTS $cd
        elif [ X"$(uname)" = X"Darwin" ] ; then
-               disktool -e ${CDROM#/dev/} 0
-       else
+               diskutil eject ${CDROM#/dev/} 0
+    elif [ -x $(which $EJECT) ]; then
                $EJECT $EJECTOPTS "$CDROM"
        fi
        #fi