Concatenate option steps on -t/-T option
[abcde.git] / abcde
diff --git a/abcde b/abcde
index 6b07ddd..c607b72 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -54,8 +54,6 @@ echo "-o <type1[,type2]...>"
 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>"
@@ -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
@@ -831,9 +829,10 @@ do_tag ()
                                        # --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:+--encoding="$ENCODING"} \
@@ -1146,7 +1145,7 @@ do_encode ()
                                            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" --comment album="$DALBUM" --title "$TRACKNAME" --comment track="$1" --comment genre="$CDGENRE" --comment year="$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
+                                              $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
@@ -2749,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
@@ -2952,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
@@ -3032,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)
@@ -3271,6 +3277,7 @@ CDPARANOIA=cdparanoia
 CDDA2WAV=icedax
 DAGRAB=dagrab
 CDDAFS=cp
+PIRD=pird
 CDDISCID=cd-discid
 CDDBTOOL=cddb-tool
 MUSICBRAINZ=abcde-musicbrainz-tool
@@ -3345,13 +3352,7 @@ ACTIONS=cddb,read,encode,tag,move,clean
 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.
@@ -3447,24 +3448,24 @@ if [ "$CDROM" = "" ] ; then
 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" ;;
@@ -3486,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" ;;
@@ -3505,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}"
@@ -3572,6 +3572,7 @@ if [ "$ONETRACK" = "y" ]; then
                flac) ;;
                cdparanoia) ;;
                cdda2wav | icedax) ;;
+               pird) ;;
                *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
                        exit 1 ;;
        esac
@@ -3766,6 +3767,10 @@ case "$CDROMREADERSYNTAX" in
                CDROMREADER="$DAGRAB"
                CDROMREADEROPTS="$DAGRABOPTS"
                ;;
+       pird)
+               CDROMREADER="$PIRD"
+               CDROMREADEROPTS="$PIRDOPTS"
+               ;;
        cddafs)
                CDROMREADER="$CDDAFS"
                CDROMREADEROPTS="$CDDAFSOPTS"
@@ -3785,8 +3790,9 @@ 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- )" ;;
@@ -3802,7 +3808,8 @@ 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 mpcenc for mpcs and faac for m4as
@@ -4016,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 ;;
@@ -4029,6 +4037,7 @@ 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
@@ -4181,6 +4190,7 @@ fi
 if [ X"$CDSPEEDVALUE" != "X" ]; then
        case "$CDROMREADERSYNTAX" in
                cdparanoia|debug) ;;
+               pird) ;;
                flac) ;;
                *) do_cdspeed ;;
        esac