Readme entry
[clinton/abcde.git] / abcde
diff --git a/abcde b/abcde
index 1649671..99e1cf5 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
-# Copyright (c) 2003-2004 Jesus Climent <jesus.climent@hispalinux.es>
+# Copyright (c) 2003-2005 Jesus Climent <jesus.climent@hispalinux.es>
 # This code is hereby licensed for public consumption under either the
 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
 #
@@ -11,7 +11,7 @@
 # Copyright for this work is to expire January 1, 2010, after which it
 # shall be public domain.
 
-VERSION="2.3.0"
+VERSION="2.3.99"
 
 usage ()
 {
@@ -31,6 +31,7 @@ echo "-d <device>"
 echo "       Specify CDROM device to grab"
 echo "-D     Debugging mode (equivalent to sh -x abcde)"
 echo "-e     Erase encoded track information from status file"
+#echo "-E     Set the encoding information for the tags"
 echo "-h     This help information"
 #echo "-i    Tag files while encoding, when possible (local only) -NWY-"
 echo "-j <#> Number of encoder processes to run at once (localhost)"
@@ -48,6 +49,8 @@ echo "-P     Use UNIX pipes to read+encode without wav files"
 echo "-r <host1[,host2]...>"
 echo "       Also encode on these remote hosts"
 echo "-R     Add replaygain values to the tag info (only for vorbis,flac)"
+echo "-s <field>"
+echo "       Show dielfs from the CDDB info (year,genre)"
 echo "-S <#> Set the CD speed"
 #echo "-t    File types to preprocess (wav)"
 #echo "-T    Set postprocessing options"
@@ -159,6 +162,31 @@ checkerrors ()
        fi
 }
 
+# page [file]
+# Finds the right pager in the system to display a file
+page ()
+{
+       PAGEFILE="$1"
+       # Use the debian sensible-pager wrapper to pick the pager
+       # user has requested via their $PAGER environment variable
+       if [ -x "/usr/bin/sensible-pager" ]; then
+               /usr/bin/sensible-pager "$PAGEFILE"
+       elif [ -x "$PAGER" ]; then
+               # That failed, try to load the preferred editor, starting
+               # with their PAGER variable
+               $PAGER "$PAGEFILE"
+               # If that fails, check for less
+       elif [ -x /usr/bin/less ]; then
+               /usr/bin/less -f "$PAGEFILE"
+               # more should be on all UNIX systems
+       elif [ -x /bin/more ]; then
+               /bin/more "$PAGEFILE"
+       else
+               # No bananas, just cat the thing
+               cat "$PAGEFILE" >&2
+       fi
+}
+
 # run_command [blurb] [command...]
 # Runs a command, silently if necessary, and updates the status file
 run_command ()
@@ -300,7 +328,7 @@ splitvarious ()
                        TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
                        ;;
                esac
-       elif [ "$ONETRACK" = "y" ]; then
+       elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
                TRACKARTIST="Various"
        else
                TRACKARTIST="$DARTIST"
@@ -373,7 +401,7 @@ local id=""
                "gangsta")               id=59 ;;
                "top 40")                id=60 ;;
                "christian rap")         id=61 ;;
-               "pop/funk")              id=62 ;;
+               "pop/funk"|"pop / funk") id=62 ;;
                "jungle")                id=63 ;;
                "native american")       id=64 ;;
                "cabaret")               id=65 ;;
@@ -459,6 +487,7 @@ local id=""
                "anime")                 id=145 ;;
                "jpop")                  id=146 ;;
                "synthpop")              id=147 ;;
+               "rock/pop"|"rock / pop") id=148 ;;
                *)                       return 1 ;;
        esac
 echo ${id}
@@ -488,11 +517,24 @@ do_tag ()
                # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
                GENREID=$(do_getgenreid "${CDGENRE}")
 
-               # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
-               run_command tagtrack-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
-                       -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
-                       -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
-                       "$ABCDETEMPDIR/track$1.$OUTPUT"
+               case "$ID3SYNTAX" in
+                       id3);;
+                       eyed3)
+                               # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
+                               run_command tagtrack-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
+                                       -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
+                                       -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
+                                       "${ENCODING:+--set-encoding=$ENCODING}"
+                                       "$ABCDETEMPDIR/track$1.$OUTPUT"
+                               ;;
+                       *)
+                               # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
+                               run_command tagtrack-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
+                                       -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
+                                       -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
+                                       "$ABCDETEMPDIR/track$1.$OUTPUT"
+                               ;;
+               esac
                ;;
        vorbis|ogg)
                case "$OGGENCODERSYNTAX" in
@@ -624,7 +666,7 @@ do_encode ()
                                TEMPARG="PIPE_$MPPENCODER"
                                ;;
                esac
-               IN=${!TEMPARG}
+               IN="$( eval echo "\$$TEMPARG" )"
        else
                IN="$ABCDETEMPDIR/track$1.wav"
                case "$OUTPUT" in
@@ -967,13 +1009,15 @@ do_move ()
                OUTPUTFILEDIR=$(dirname "$OUTPUTDIR/$OUTPUTFILE")
                # mkdir -p shouldn't return an error if the directory already exists
                mkdir -p "$OUTPUTFILEDIR"
-               vecho "Moving $ABCDETEMPDIR/track$1.$OUTPUT to $OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
+               # Silence the Moving output since it overlaps with encoding processes...
+               #run_command '' vecho "Moving track$1.$OUTPUT to $OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
                run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
                # Lets move the cue file
                if CUEFILE=$(checkstatus cuefile) >/dev/null ; then 
                        if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
                                if checkstatus movecue-$OUTPUT; then :; else
-                                       vecho "Copying cue file to its destination directory..."
+                                       # Silence the Copying output since it overlaps with encoding processes...
+                                       #run_command '' vecho "Copying cue file to its destination directory..."
                                        if checkstatus onetrack >/dev/null ; then
                                                case $OUTPUT in
                                                        # NOTE: Creating a cue file with the 3-char-extension files is to comply with
@@ -1137,7 +1181,7 @@ do_discid ()
                                cdparanoia|debug)
                                        if [ "$WEHAVEACD" = "y" ]; then
                                                vecho "Querying the CD for audio tracks..."
-                                               CDPARANOIAOUTPUT="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
+                                               CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
                                                RET=$?
                                                if [ ! "$RET" = "0" ];then
                                                        echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
@@ -1267,8 +1311,13 @@ do_discid ()
                if checkstatus cuefile > /dev/null 2>&1 ; then :; else
                        CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
                        vecho "Creating cue file..."
-                       $MKCUE $MKCUEOPTS > "$ABCDETEMPDIR/$CUEFILE"
-                       echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
+                       if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
+                               echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
+                       else
+                               echo "abcde: reading the CUE sheet with mkcue is still considered experimental"
+                               echo "abcde: and there was a problem with the CD reading. abcde will continue,"
+                               echo "abcde: but consider reporting the problem to the abcde author"
+                       fi
                fi
        fi
        # If we got the CDPARANOIA status and it is not recorded, save it now
@@ -1326,6 +1375,18 @@ do_cddbparse ()
                vecho "ONETRACK mode selected: displaying only the title of the CD..."
        fi
        echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
+       if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
+               PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
+               if [ ! X"$PARSEDYEAR" = "X" ]; then
+                       echo "Year: $PARSEDYEAR"
+               fi
+       fi
+       if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
+               PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
+               if [ ! X"$PARSEDGENRE" = "X" ]; then
+                       echo "Genre: $PARSEDGENRE"
+               fi
+       fi
        if [ ! "$ONETRACK" = "y" ]; then
                for TRACK in $(f_seq_row 1 $TRACKS)
                do
@@ -1579,40 +1640,52 @@ do_cddbedit ()
                                else
                                        # The user has a choice to make, display the info in a pager if necessary
                                        if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
-                                               # Use the debian sensible-pager wrapper to pick the pager
-                                               # user has requested via their $PAGER environment variable
-                                               if [ -x "/usr/bin/sensible-pager" ]; then
-                                                       /usr/bin/sensible-pager "$ABCDETEMPDIR/cddbchoices"
-                                               elif [ -x "$PAGER" ]; then
-                                                       # That failed, try to load the preferred editor, starting
-                                                       # with their PAGER variable
-                                                       $PAGER "$ABCDETEMPDIR/cddbchoices"
-                                                       # If that fails, check for less
-                                               elif [ -x /usr/bin/less ]; then
-                                                       /usr/bin/less -f "$ABCDETEMPDIR/cddbchoices"
-                                                       # more should be on all UNIX systems
-                                               elif [ -x /bin/more ]; then
-                                                       /bin/more "$ABCDETEMPDIR/cddbchoices"
-                                               else
-                                                       # No bananas, just cat the thing
-                                                       cat "$ABCDETEMPDIR/cddbchoices" >&2
-                                               fi
+                                               page "$ABCDETEMPDIR/cddbchoices"
                                        else
                                                # It's all going to fit in one page, cat it
                                                cat "$ABCDETEMPDIR/cddbchoices" >&2
                                        fi
                                        
+                                       CDDBCHOICENUM=""
+                                       # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
+                                       CDCHOICENUM=-1
                                        # I'll take CDDB read #3 for $400, Alex
-                                       echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
-                                       read CDDBCHOICE
-                                       [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
-                                       # Make sure we get a valid choice
-                                       CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
-                                       while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
-                                               echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
-                                               echo -n "Selection [0-$CDDBCHOICES]: " >&2
+                                       while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
+                                               echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
                                                read CDDBCHOICE
-                                               CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
+                                               [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
+                                               if echo $CDDBCHOICE | egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
+                                                       if [ ! X"$DIFF" = "X" ]; then
+                                                               PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1)
+                                                               PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2)
+                                                               if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
+                                                                  [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
+                                                                  [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then 
+                                                                       echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
+                                                               else
+
+                                                                       # We parse the 2 choices to diff, store them in temporary files and diff them.
+                                                                       for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
+                                                                               do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
+                                                                       done
+                                                                       echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
+                                                                       $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
+                                                                       if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
+                                                                               page "$ABCDETEMPDIR/cddbread.diff"
+                                                                       else
+                                                                               cat "$ABCDETEMPDIR/cddbread.diff" >&2
+                                                                       fi
+                                                               fi
+                                                       else
+                                                               echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
+                                                       fi
+                                               else
+                                                       if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
+                                                               # Make sure we get a valid choice
+                                                               CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
+                                                               echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
+                                                       fi
+                                               fi
                                        done
                                        if [ "$CDCHOICENUM" = "0" ]; then
                                                vecho "Creating empty CDDB template..."
@@ -1708,8 +1781,12 @@ do_cddbedit ()
                # If that fails, check for a vi
                elif which vi >/dev/null 2>&1; then
                        vi "$CDDBDATA"
+               elif [ -x /usr/bin/vim ]; then
+                       /usr/bin/vim "$CDDBDATA"
                elif [ -x /usr/bin/vi ]; then
                        /usr/bin/vi "$CDDBDATA"
+               elif [ -x /bin/vi ]; then
+                       /bin/vi "$CDDBDATA"
                # nano should be on all (modern, i.e., sarge) debian systems
                elif which nano >/dev/null 2>&1 ; then
                        nano "$CDDBDATA"
@@ -1815,7 +1892,7 @@ do_cddbedit ()
        echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
 
        if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
-               if [ $CDDBDATAMD5SUM != "" ]  && [ $CDDBDATAMD5SUM != $($MD5SUM "$CDDBDATA" | cut -d " " -f 1) ]; then
+               if [ "$CDDBDATAMD5SUM" != "" ]  && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
                        # This works but does not have the necessary error checking
                        # yet. If you are familiar with the CDDB spec
                        # (see http://www.freedb.org/src/latest/DBFORMAT) 
@@ -1880,7 +1957,7 @@ do_cdread ()
        CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
        if [ "$USEPIPES" = "y" ]; then
                TEMPARG="PIPE_$CDROMREADERSYNTAX"
-               FILEARG="${!TEMPARG}"
+               FILEARG="$( eval echo "\$$TEMPARG" )"
                REDIR=""
                PIPE_MESSAGE="and encoding "
        else
@@ -1908,7 +1985,7 @@ do_cdread ()
        fi
        case "$CDROMREADERSYNTAX" in
                cdparanoia) 
-                       nice $READNICE $CDROMREADER -d $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
+                       nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
                cdda2wav)
                        if [ "$OSFLAVOUR" = "OSX" ] ; then
                                # Hei, we have to unmount the device before running anything like cdda2wav in OSX
@@ -1941,7 +2018,7 @@ do_cdread ()
                        else
                                false
                        fi ;;
-               debug) nice $READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
+               debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
                        ;;
        esac
        RETURN=$?
@@ -2013,6 +2090,13 @@ pre_read ()
 :
 }
 
+# post_read
+# Empty post_read function, to be defined in the configuration file.
+post_read ()
+{
+:
+}
+
 ###############################################################################
 # End of functions
 #
@@ -2024,6 +2108,13 @@ CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
 CDDBSUBMIT=freedb-submit@freedb.org
 CDDBPROTO=5
 HELLOINFO="$(whoami)@$(hostname)"
+CDDBCOPYLOCAL="n"
+CDDBLOCALDIR="$HOME/.cddb"
+CDDBUSELOCAL="n"
+
+# List of fields we parse and show during the CDDB parsing...
+SHOWCDDBFIELDS="year,genre"
+
 INTERACTIVE=y
 CDROMREADERSYNTAX=cdparanoia
 ENCODERSYNTAX=default
@@ -2034,6 +2125,7 @@ FLACENCODERSYNTAX=default
 SPEEXENCODERSYNTAX=default
 MPPENCODERSYNTAX=default
 NORMALIZERSYNTAX=default
+CUEREADERSYNTAX=default
 
 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
@@ -2055,13 +2147,13 @@ VARIOUSARTISTS=n
 VARIOUSARTISTSTYLE=forward
 KEEPWAVS=n
 PADTRACKS=n
-CDDBCOPYLOCAL="n"
-CDDBLOCALDIR="$HOME/.cddb"
-CDDBUSELOCAL="n"
 
 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
 # i.e. CDROMID="1,0,0"
 CDROMID=""
+# If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
+# If we are using the ide-scsi emulation layer, we need to define a "g"
+CDPARANOIACDROMBUS="d"
 
 # program paths - defaults to checking your $PATH
 # mp3
@@ -2083,6 +2175,7 @@ MPPENC=mppenc
 
 ID3=id3
 ID3V2=id3v2
+EYED3=eyeD3
 CDPARANOIA=cdparanoia
 CDDA2WAV=cdda2wav
 DAGRAB=dagrab
@@ -2098,6 +2191,8 @@ NORMALIZE=normalize-audio
 CDSPEED=eject
 VORBISGAIN=vorbisgain
 MKCUE=mkcue
+MKTOC=cdrdao
+DIFF=diff
 
 # Options for programs called from abcde
 # mp3
@@ -2130,6 +2225,7 @@ NORMALIZEOPTS=
 CDSPEEDOPTS="-x"
 CDSPEEDVALUE=
 MKCUEOPTS=
+MKTOCOPTS=""
 VORBISCOMMENTOPTS="-R"
 METAFLACOPTS="--no-utf8-convert"
 
@@ -2147,6 +2243,7 @@ DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
 # Let's use these checkings to determine the OS flavour, which will be used later
 if [ X$(uname) = "XFreeBSD" ] ; then
        HTTPGET=fetch
+       MD5SUM=md5
        NEEDCDROMID=y
        OSFLAVOUR=FBSD
 elif [ X$(uname) = "XDarwin" ] ; then
@@ -2158,6 +2255,9 @@ elif [ X$(uname) = "XDarwin" ] ; then
 elif [ X$(uname) = "XOpenBSD" ] ; then
        HTTPGET=wget
        MD5SUM=md5
+elif [ X$(uname) = "XNetBSD" ] ; then
+       HTTPGET=ftp
+       MD5SUM=md5
 else
        HTTPGET=wget
 fi
@@ -2193,6 +2293,7 @@ if [ "$HTTPGETOPTS" = "" ] ; then
                wget) HTTPGETOPTS="-q -O -";;
                curl) HTTPGETOPTS="-f -s";;
                fetch)HTTPGETOPTS="-q -o -";;
+               ftp)  HTTPGETOPTS="-q -o -";;
                *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
        esac
 fi
@@ -2215,12 +2316,12 @@ if [ "$CDROM" = "" ] ; then
 fi
 
 # Parse command line options
-#while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
-while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
+#while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
+while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
-               A) EXPACTIONS="$OPTARG";;
+               A) EXPACTIONS="$OPTARG" ;;
                b) BATCH=y ;;
                c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
                C) DISCID="${OPTARG#abcde.}" ;;
@@ -2229,6 +2330,7 @@ while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
                e) ERASEENCODEDSTATUS=y ;;
                h) usage; exit ;;
                e) ERASEENCODEDSTATUS=y ;;
+               E) ENCODING="$OPTARG" ;;
 #              f) FORCECDDBUSELOCAL=y ;;
                i) INLINETAG=y ;;
                j) MAXPROCS="$OPTARG" ;;
@@ -2244,7 +2346,7 @@ while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
                P) USEPIPES=y ;;
                r) REMOTEHOSTS="$OPTARG" ;;
                R) REPLAYGAIN=y ;;
-               s) STARTTRACKNUMBER="$OPTARG" ;;
+               s) SHOWCDDBFIELDS="$OPTARG" ;;
                S) CDSPEEDVALUE="$OPTARG" ;;
 #              t) PREPROCESSFORMATS="$OPTARG"
 #                 PREPROCESS=y ;;
@@ -2338,25 +2440,15 @@ do
        esac
 done
 
-# Sanity checks:
+for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
+       case $SHOWCDDBFIELD in
+               y*|Y*) SHOWCDDBYEAR="y";;
+               g*|G*) SHOWCDDBGENRE="y";;
+               *) ;;
+       esac
+done
 
-# Check the encoding format, if nothing has been configured in the system, from the ones available in the system
-if [ X"$OUTPUTTYPE" = "X" ]; then
-       for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
-               DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
-               DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
-               if which $DEFAULT_OUTPUT_BINARY > /dev/null 2>&1 ; then
-                       OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
-                       vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
-                       break
-               fi
-       done
-       if [ X"$OUTPUTTYPE" = "X" ]; then
-               echo "abcde error: no encoder found in the PATH" >&2
-               echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
-               exit 1
-       fi
-fi
+# Sanity checks:
 
 # At this point a CDROM has to be defined, so we check it exists.
 if [ X"$CDROM" != "X" ] ; then 
@@ -2404,6 +2496,24 @@ if [ X"$USEPIPES" = "Xy" ]; then
        fi
 fi
 
+# Check the encoding format from the ones available in the system, if nothing has been configured in the system.
+if [ X"$OUTPUTTYPE" = "X" ]; then
+       for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
+               DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
+               DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
+               if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
+                       OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
+                       vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
+                       break
+               fi
+       done
+       if [ X"$OUTPUTTYPE" = "X" ]; then
+               echo "abcde error: no encoder found in the PATH" >&2
+               echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
+               exit 1
+       fi
+fi
+
 # Decide which CDROM reader we're gonna use
 case "$CDROMREADERSYNTAX" in
        cdparanoia|debug)
@@ -2557,6 +2667,14 @@ else
        TAGGEROPTS="$ID3V2OPTS"
 fi
 
+# Options for mkcue
+case "$CUEREADERSYNTAX" in
+       default|mkcue)
+               CUEREADEROPTS="${CDROM}"
+               CUEREADER="$MKCUE"
+               ;;
+esac
+
 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
        echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
@@ -2592,8 +2710,8 @@ fi
 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
        NEEDHTTPGET=y
 fi
-if [ "$CUEFILE" = "y" ]; then
-       NEEDMKCUE=y
+if [ "$MAKECUEFILE" = "y" ]; then
+       NEEDCUEREADER=y
 fi
 
 if [ X"$CDSPEEDVALUE" != "X" ]; then
@@ -2629,13 +2747,13 @@ if [ "$USEPIPES" = "y" ]; then
                mpc)
                        PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
        esac
-       if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
+       if [ ! -n "$( eval echo "\$$PIPERIPPERSVARCHECK" )" ] ; then
                echo "abcde error: no support for pipes with given ripper" >&2
                echo "read the USEPIPES file from the source tarball to help" >&2
                echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
                exit 1;
        fi
-       if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
+       if [ ! -n "$( eval echo "\$$PIPEENCODERSVARCHECK" )" ] ; then
                echo "abcde error: no support for pipes with given encoder" >&2
                echo "read the USEPIPES file from the source tarball to help" >&2
                echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
@@ -2650,7 +2768,7 @@ for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
        ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
        ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
        ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
-       ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
+       ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER}
 do
        # Cut off the command-line options we just added in
        X=$(echo $X | cut -d' ' -f2)
@@ -2667,9 +2785,15 @@ CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
 HTTPGET="$HTTPGET $HTTPGETOPTS"
 
+# And last but not least, check if we can diff between files
+if [ -x $(which $DIFF) ]; then :; else
+       vecho "[WAR] Disabling diff since we cannot find it in the \$PATH..."
+       DIFF=""
+fi
+
 # Here it used to say:
 # One thousand lines in, we can start doing stuff with things
-# Well, right now we are at line 2157 ;)
+# Well, right now we are at line 2736 ;)
 
 # Export needed things so they can be read in this subshell
 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
@@ -2796,6 +2920,9 @@ if [ "$BATCH" = "y" ] || [ "$ONETRACK" = "y" ]; then
        echo NEXTTRACK
 fi
 
+# Execute the user-defined post_read funtion 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