Concatenate option steps on -t/-T option
[abcde.git] / abcde
diff --git a/abcde b/abcde
index 2237ca2..c607b72 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -15,7 +15,7 @@
 #
 # $Id$
 
-VERSION='2.5.4-UNRELEASED'
+VERSION='2.5.5-UNRELEASED'
 
 usage ()
 {
@@ -51,11 +51,9 @@ echo "-m     Modify playlist to include CRLF endings, to comply with some player
 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 "-s <field>"
@@ -433,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}
@@ -493,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
@@ -515,6 +513,9 @@ do_replaygain()
                                vorbis|ogg)
                                        OUTPUT=$OGGOUTPUTCONTAINER
                                        ;;
+                               opus)
+                                       OUTPUT=$OPUSOUTPUTCONTAINER
+                                       ;;
                                flac)
                                        OUTPUT=$FLACOUTPUTCONTAINER
                                        ;;
@@ -824,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-text-frame=TPE2:"$TPE2"} \
+                                               ${ENCODING:+--encoding="$ENCODING"} \
+                                               ${TPE2:+--text-frame=TPE2:"$TPE2"} \
                                                "$ABCDETEMPDIR/track$1.$OUTPUT"
                                        ;;
                                # FIXME # Still not activated...
@@ -898,6 +904,10 @@ do_tag ()
                                        ;;
                        esac
                        ;;
+               opus)
+                       run_command tagtrack-$OUTPUT-$1 true
+                       ;;
+
                flac)
                        (
                        echo ARTIST="$TRACKARTIST"
@@ -1018,6 +1028,9 @@ do_encode ()
                        vorbis|ogg)
                                TEMPARG="PIPE_$OGGENCODERSYNTAX"
                                ;;
+                       opus)
+                               TEMPARG="PIPE_$OPUSENCODERSYNTAX"
+                               ;;
                        flac)
                                TEMPARG="PIPE_$FLACENCODERSYNTAX"
                                ;;
@@ -1025,7 +1038,7 @@ do_encode ()
                                TEMPARG="PIPE_$SPEEXENCODER"
                                ;;
                        mpc)
-                               TEMPARG="PIPE_$MPPENCODER"
+                               TEMPARG="PIPE_$MPCENCODER"
                                ;;
                        m4a)
                                TEMPARG="PIPE_$AACENCODERSYNTAX"
@@ -1060,6 +1073,9 @@ do_encode ()
                                vorbis|ogg)
                                        OUTPUT=$OGGOUTPUTCONTAINER
                                        ;;
+                               opus)
+                                       OUTPUT=$OPUSOUTPUTCONTAINER
+                                       ;;
                                flac)
                                        OUTPUT=$FLACOUTPUTCONTAINER
                                        ;;
@@ -1115,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*%)
@@ -1145,16 +1187,16 @@ do_encode ()
                                ;;
                        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)
                                # Tag the file at encode time, as it can't be done after encoding.
-                               if [ "$DOTAG" = "y" ]; then
+                               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
@@ -1397,6 +1439,9 @@ do_move ()
                                vorbis|ogg)
                                        OUTPUT=$OGGOUTPUTCONTAINER
                                        ;;
+                               opus)
+                                       OUTPUT=$OPUSOUTPUTCONTAINER
+                                       ;;
                                flac)
                                        OUTPUT=$FLACOUTPUTCONTAINER
                                        ;;
@@ -1478,6 +1523,9 @@ do_playlist ()
                        vorbis|ogg)
                                OUTPUT=$OGGOUTPUTCONTAINER
                                ;;
+                       opus)
+                               OUTPUT=$OPUSOUTPUTCONTAINER
+                               ;;
                        flac)
                                OUTPUT=$FLACOUTPUTCONTAINER
                                ;;
@@ -1705,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
@@ -2400,6 +2448,9 @@ do_cddbstat ()
                                                2??)    # Server responded, everything seems OK
                                                        rc=0
                                                        ;;
+                                               *)      # unknown error
+                                                       break
+                                                       ;;
                                        esac
                                        ;;
                                esac
@@ -2697,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
@@ -2900,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
@@ -2980,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)
@@ -3146,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
@@ -3196,17 +3255,18 @@ 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
@@ -3217,6 +3277,7 @@ CDPARANOIA=cdparanoia
 CDDA2WAV=icedax
 DAGRAB=dagrab
 CDDAFS=cp
+PIRD=pird
 CDDISCID=cd-discid
 CDDBTOOL=cddb-tool
 MUSICBRAINZ=abcde-musicbrainz-tool
@@ -3247,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=
@@ -3283,16 +3349,10 @@ ACTIONS=cddb,read,encode,tag,move,clean
 
 # 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
+DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
 
 # List of preferred cdromreaders - by default, run whichever we have in the path
-DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav"
-
-# 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:"
+DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav pird"
 
 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
 # Linux/OpenBSD. ftp is user for NetBSD.
@@ -3309,6 +3369,8 @@ elif [ X$(uname) = "XDarwin" ] ; then
        # 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
@@ -3326,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
@@ -3373,6 +3432,8 @@ 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
@@ -3383,30 +3444,28 @@ if [ "$CDROM" = "" ] ; then
                CDROM=/dev/acd0c
        elif [ -e /dev/disk1 ]; then
                CDROM=/dev/disk1
-       elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part.*(disk.)$'\n' ]]; then
-               CDROM=/dev/${BASH_REMATCH[1]}
        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. If
-# EXTRAVERBOSE=y, set it to 1 for backwards compatibility.
-if [ "$EXTRAVERBOSE" = "y" ]; then
-       EXTRAVERBOSE=1
-fi
-if [ "$EXTRAVERBOSE" = "n" ]; then
-       EXTRAVERBOSE=0
-fi
+# 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" ;;
@@ -3428,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" ;;
@@ -3447,7 +3505,7 @@ while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPq:r:s:S:t:T:UvVxX:w:W:z opt ; do
                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}"
@@ -3514,6 +3572,7 @@ if [ "$ONETRACK" = "y" ]; then
                flac) ;;
                cdparanoia) ;;
                cdda2wav | icedax) ;;
+               pird) ;;
                *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
                        exit 1 ;;
        esac
@@ -3708,6 +3767,10 @@ case "$CDROMREADERSYNTAX" in
                CDROMREADER="$DAGRAB"
                CDROMREADEROPTS="$DAGRABOPTS"
                ;;
+       pird)
+               CDROMREADER="$PIRD"
+               CDROMREADEROPTS="$PIRDOPTS"
+               ;;
        cddafs)
                CDROMREADER="$CDDAFS"
                CDROMREADEROPTS="$CDDAFSOPTS"
@@ -3727,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
@@ -3743,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 , \ )
@@ -3758,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
@@ -3774,7 +3844,7 @@ do
 #                      [ "$DOREPLAYGAIN" = "y" ] &&
                        ;;
                mpc)
-                       [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
+                       [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
                        [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN=y
                        ;;
                m4a)
@@ -3834,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}"
@@ -3858,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
@@ -3876,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 ...
@@ -3946,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 ;;
@@ -3959,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
@@ -3976,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" )" = "$" ] || \
@@ -4003,7 +4085,7 @@ fi
 
 # Make sure a buncha things exist
 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
-       $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
+       $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
        $AACENCODER $CDDBTOOL \
        ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
        ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
@@ -4108,6 +4190,7 @@ fi
 if [ X"$CDSPEEDVALUE" != "X" ]; then
        case "$CDROMREADERSYNTAX" in
                cdparanoia|debug) ;;
+               pird) ;;
                flac) ;;
                *) do_cdspeed ;;
        esac
@@ -4221,7 +4304,7 @@ 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.
@@ -4238,7 +4321,7 @@ if [ "$EJECTCD" = "y" ] && [ -x $(which $EJECT) ]; then
                $eject $EJECTOPTS $cd
        elif [ X"$(uname)" = X"Darwin" ] ; then
                diskutil eject ${CDROM#/dev/} 0
-       else
+    elif [ -x $(which $EJECT) ]; then
                $EJECT $EJECTOPTS "$CDROM"
        fi
        #fi