echo "-P Use UNIX pipes to read+encode without wav files"
echo "-r <host1[,host2]...>"
echo " Also encode on these remote hosts"
+echo "-R Use local CDDB in recursive mode"
#echo "-R Add replaygain values to the tag info (only for vorbis,flac,mp3)"
echo "-s <field>"
echo " Show dielfs from the CDDB info (year,genre)"
echo $TO
}
+checkexec ()
+{
+ if [ ! "$@" = "" ]; then
+ # Cut off the command-line options we just added in
+ X=$(echo $@ | cut -d' ' -f2)
+ if [ "$(which $X)" = "" ]; then
+ log error "$X is not in your path." >&2
+ exit 1
+ elif [ ! -x $(which $X) ]; then
+ log error "$X is not executable." >&2
+ exit 1
+ fi
+ fi
+}
+
# do_getcddbinfo
# Finds an specific field from cddbinfo
do_getcddbinfo()
*) echo COMMENT="$COMMENTOUTPUT";;
esac
fi
- ) | run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
+ ) | run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
;;
spx)
run_command tagtrack-$OUTPUT-$1 true
disktool -u ${CDROM#/dev/}
fi
if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
- TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM | $CUE2DISCID)
+ if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM > /dev/null 2>&1 ; then
+ TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM | $CUE2DISCID)
+ else
+ log error "the input flac file does not contain a cuesheet."
+ exit 1
+ fi
else
case "$CDDBMETHOD" in
cddb) TRACKINFO=$($CDDISCID $CDROM) ;;
if checkstatus cuefile > /dev/null 2>&1 ; then :; else
CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
vecho "Creating cue file..."
- if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
- echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
- else
- log warning "reading the CUE sheet with mkcue is still considered experimental"
- log warning "and there was a problem with the CD reading. abcde will continue,"
- log warning "but consider reporting the problem to the abcde author"
- fi
+ case $CDROMREADERSYNTAX in
+ flac)
+ if $METAFLAC --export-cuesheet-to=- $CDROM > "$ABCDETEMPDIR/$CUEFILE"; then :; else
+ log warning "the input flac file does not contain a cuesheet."
+ fi
+ ;;
+ *)
+ if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
+ echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
+ else
+ log warning "reading the CUE sheet with mkcue is still considered experimental"
+ log warning "and there was a problem with the CD reading. abcde will continue,"
+ log warning "but consider reporting the problem to the abcde author"
+ fi
+ ;;
+ esac
fi
fi
# If we got the CDPARANOIA status and it is not recorded, save it now
{
if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
- CDDBLOCALSUCCESS="n"
+ CDDBLOCALSTATUS="notfound"
CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
- CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
USELOCALRESP="y"
-
- # If the user has selected to check a local CDDB repo, we proceed with it
- if [ -r "${CDDBLOCALFILE}" ]; then
- # List out disc title/author and contents
- do_cddbparse "${CDDBLOCALFILE}"
- echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
- if [ "$INTERACTIVE" = "y" ]; then
- read USELOCALRESP
- while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
- echo -n 'Invalid selection. Please answer "y" or "n": '
- read USELOCALRESP
- done
- [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
- else
- echo "y" >&2
- fi
- if [ "$USELOCALRESP" = "y" ]; then
- #echo "Using local copy of CDDB data"
- echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
- cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
- echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
- echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
- do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
- echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
- CDDBLOCALSUCCESS="y"
+
+ if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
+ CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
+ if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
+ if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
+ CDDBLOCALFILE="${CDDBLOCALRESULTS}"
+ CDDBLOCALMATCH=single
+ elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
+ CDDBLOCALMATCH=multiple
+ fi
else
- #echo "Not using local copy of CDDB data"
- CDDBLOCALSUCCESS="n"
+ CDDBLOCALMATCH=none
fi
+ elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
+ CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
+ CDDBLOCALMATCH=single
else
- CDDBLOCALSUCCESS="n"
+ CDDBLOCALMATCH=none
fi
+
+ # If the user has selected to check a local CDDB repo, we proceed with it
+ case $CDDBLOCALMATCH in
+ multiple)
+ echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
+ X=0
+ echo "$CDDBLOCALRESULTS" | while read RESULT ; do
+ X=$(expr $X + 1)
+ # List out disc title/author and contents
+ CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
+ cat "$RESULT" > "${CDDBLOCALREAD}"
+ {
+ echo -n "#$X: "
+ do_cddbparse "${CDDBLOCALREAD}"
+ echo ""
+ } >> "$ABCDETEMPDIR/cddblocalchoices"
+ done
+ CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
+ cat "$ABCDETEMPDIR/cddblocalchoices"
+ CDDBLOCALCHOICENUM=-1
+ if [ "$INTERACTIVE" = "y" ]; then
+ while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
+ echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
+ read CDDBLOCALCHOICENUM
+ [ x"$CDDBLOCALCHOICENUM" = "x" ] && CDDBLOCALCHOICENUM="1"
+ done
+ else
+ ### FIXME ###
+ echo "Selected ..."
+ CDDBLOCALRESP=y
+ fi
+ if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
+ #echo "Using local copy of CDDB data"
+ echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
+ cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
+ echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
+ echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
+ do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
+ echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
+ CDDBLOCALSTATUS="found"
+ else
+ #echo "Not using local copy of CDDB data"
+ CDDBLOCALSTATUS="notfound"
+ fi
+ ;;
+ single)
+ # 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
+ else
+ echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
+ fi
+ if [ "$INTERACTIVE" = "y" ]; then
+ read USELOCALRESP
+ while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
+ echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
+ read USELOCALRESP
+ done
+ [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
+ else
+ echo "y" >&2
+ fi
+ if [ "$USELOCALRESP" = "y" ]; then
+ #echo "Using local copy of CDDB data"
+ echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
+ cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
+ echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
+ echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
+ do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
+ echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
+ CDDBLOCALSTATUS="single"
+ else
+ #echo "Not using local copy of CDDB data"
+ CDDBLOCALSTATUS="notfound"
+ fi
+ ;;
+ none)
+ CDDBLOCALSTATUS="notfound"
+ ;;
+ esac
fi
}
if [ "$CDDBAVAIL" = "n" ]; then
ERRORCODE=no_query
echo 503 > "$ABCDETEMPDIR/cddbquery"
- # The default CDDBLOCALSUCCESS is "n"
+ # The default CDDBLOCALSTATUS is "notfound"
# This part will be triggered if the user CDDB repo does not
# contain the entry, or if we are not trying to use the repo.
else
if [ "$INTERACTIVE" = "y" ]; then
# We should show the CDDB results both when we are not using the local CDDB repo
# or when we are using it but we could not find a proper match
- if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
+ if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
# Display the $ABCDETEMPDIR/cddbchoices file created above
# Pick a pager so that if the tracks overflow the screen the user can still view everything
if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
CHOICE=$(checkstatus cddb-choice)
if [ -n "$CHOICE" ] ; then
case $CDDBCHOICES in
- -1) log error "CDDB query failed!"
- exit 1
+ -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep -q "^$" ; then
+ log error "CDDB query failed!"
+ exit 1
+ else
+ cat "$ABCDETEMPDIR/cddbchoices"
+ fi
;;
1) cat "$ABCDETEMPDIR/cddbchoices" ;;
*)
# Show the choice if we are not using the locally stored one
# or when the local search failed to find a match.
PREVIOUSCHOICE=$(checkstatus cddb-choice)
- if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
+ if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
#if [ "$PREVIOUSCHOICE" ]; then
cat "$ABCDETEMPDIR/cddbchoices"
#fi
fi
fi
fi
- # Make sure the cache directory exists
- mkdir -p $CDDBLOCALDIR
+ ### FIXME ###
+ # User CDDBLOCALPOLICY to find out if we store the file or not...
# Cache edited CDDB entry in the user's cddb dir
- if [ "$CDDBCOPYLOCAL" = "y" ] || [ "$COPYCDDBLOCAL" = "Y" ]; then
+ if [ "$CDDBCOPYLOCAL" = "y" ]; then
+ # Make sure the cache directory exists
+ mkdir -p $CDDBLOCALDIR
cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
fi
# the user said
# We need the first and last track for cdda2wav
FIRSTTRACK=$2
- LASTTRACK=$3
+ LASTTRACK=$(expr $3 + 0)
UTRACKNUM=$FIRSTTRACK
case "$CDROMREADERSYNTAX" in
flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
- cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
+ cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
*) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
exit 1 ;;
esac
### FIXME ### use an exception for flac, since it uses -o
### FIXME ### Shall we just use -o $FILEARG ??
flac)
- nice $READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
+ # Avoid problems wit math expressions by unpadding the given UTRACKNUM
+ STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
+ nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
cdparanoia)
- echo "nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;" > /tmp/log
nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
cdda2wav)
if [ "$OSFLAVOUR" = "OSX" ] ; then
echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
else
echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
- if [ "$1" = "onetrack" ]; then
- echo onetrack >> "$ABCDETEMPDIR/status"
- fi
+ fi
+ if [ "$1" = "onetrack" ]; then
+ echo onetrack >> "$ABCDETEMPDIR/status"
fi
fi
}
{
if [ x"$EXTRAVERBOSE" != "x" ]; then
case $1 in
- warning) log warning "$@" ;;
+ warning) shift ; log warning "$@" ;;
*) echo "$@" ;;
esac
fi
CDDBPROTO=5
HELLOINFO="$(whoami)@$(hostname)"
CDDBCOPYLOCAL="n"
+CDDBLOCALPOLICY="always"
+CDDBLOCALRECURSIVE="y"
CDDBLOCALDIR="$HOME/.cddb"
CDDBUSELOCAL="n"
# If the user specified a flac file, then switch to special flac mode
if echo $CDROM | grep -i -q '.flac$'; then
- vecho "abcde: switching to flac CDROMREADERSYNTAX..."
+ vecho warning "abcde: switching to flac CDROMREADERSYNTAX..."
CDROMREADERSYNTAX=flac
- if [ "$EJECTCD" = "y" ];then
- vecho "abcde: CDROM flac mode, deactivating EJECTCD..."
- EJECTCD=n
- fi
+ # Added a need on CUE2DISCID until we manage to convert the python script to bash.
+ NEEDCUE2DISCID=y
+ NEEDMETAFLAC=y
+ EJECTCD=n
fi
# If the user provided a DISCID, disable eject
-if [ -n "$DISCID" ]; then EJECTCD=n ; fi
+if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
# Check the available cd rippers in the system, from the ones we know.
if [ "$CDROMREADERSYNTAX" = "" ]; then
;;
esac
+# which information retrieval tool are we using?
+case "$CDDBTOOL" in
+ cddb) ;;
+ musicbrainz) ;;
+esac
+
# Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
log error "FLAC on an Ogg container is not yet supported"
NEEDCUEREADER=y
fi
-if [ X"$CDSPEEDVALUE" != "X" ]; then
+if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y"]; then
case "$CDROMREADERSYNTAX" in
cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
### FIXME ### translate "cue2discid" from python to bash
- flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ;;
+ flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
*) NEEDCDSPEED=y ;;
esac
fi
${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
- ${NEEDMPPGAIN+$MPPGAIN} \
- ${NEEDCUEREADER+$CUEREADER} ${NEEDCUE2DISCID+$CUE2DISCID}
+ ${NEEDMPPGAIN+$MPPGAIN} ${NEEDCUEREADER+$CUEREADER} \
+ ${NEEDCUE2DISCID+$CUE2DISCID}
do
- # Cut off the command-line options we just added in
- X=$(echo $X | cut -d' ' -f2)
- if [ "$(which $X)" = "" ]; then
- log error "$X is not in your path." >&2
- exit 1
- elif [ ! -x $(which $X) ]; then
- log error "$X is not executable." >&2
- exit 1
- fi
+ checkexec "$X"
done
-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 warning "Disabling diff since we cannot find it in the \$PATH..."
DIFF=""
fi
+## Now that we have metaflac, check if we need cue2discid
+#case $CDROMREADERSYNTAX in
+# flac)
+# TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | egrep "[a-f0-9]{8}")
+# if [ "$TRACKINFO" = "" ]; then
+# checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
+# fi
+# ;;
+#esac
+
+CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
+CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
+HTTPGET="$HTTPGET $HTTPGETOPTS"
+
# Here it used to say:
# One thousand lines in, we can start doing stuff with things
-# Well, right now we are at line 2736 ;)
+# Well, right now we are at line 3306 ;)
# Export needed things so they can be read in this subshell
export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
-# User-definable function to set some things. Use it for
-# - closing the CD tray with eject -t
-# - set the CD speed value with eject -x
-vecho -n "Executing customizable pre-read function... "
+if [ "$DOREAD" = "y" ]; then
+ # User-definable function to set some things. Use it for
+ # - closing the CD tray with eject -t
+ # - 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 funtion. Close the CD with it.
-vecho "done."
+ vecho "done."
+fi
case "$CDDBMETHOD" in
cddb)
esac
if [ "$DOCDDB" = "y" ]; then
+ # start with a sane default:
+ CDDBLOCALSTATUS=notfound
if [ $CDDBUSELOCAL = "y" ]; then
do_localcddb
fi
if checkstatus cddb-choice > /dev/null; then
:
else
- if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
+ if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
case "$CDDBMETHOD" in
cddb)
do_cddbstat
| grep -v ^encode-output > "$ABCDETEMPDIR/status"
fi
+if checkstatus onetrack ; then ONETRACK=y ; fi
+
+if [ "$ONETRACK" = "y" ]; then
+ # Reuse the CUEFILE in case we created it in a previous run
+ if CUEFILE=$(checkstatus cuefile); then
+ IMPORTCUESHEET=y
+ fi
+fi
+
# Create playlist if needed (backgroundable) and start reading in tracks
(
if [ "$ONETRACK" = "y" ]; then
TRACKS="$FIRSTTRACK"
- if checkstatus readtrack-$FIRSTTRACK; then :; else
- if [ "$USEPIPES" = "y" ]; then
+ if [ "$USEPIPES" = "y" ]; then
+ if checkstatus readencodetrack-$FIRSTTRACK; then :; else
do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
- else
+ fi
+ else
+ if checkstatus readtrack-$FIRSTTRACK; then :; else
do_cdread onetrack $FIRSTTRACK $LASTTRACK
fi
fi