From: data Date: Thu, 5 Jan 2006 14:42:32 +0000 (+0000) Subject: More work on musicbrainz support X-Git-Url: https://git.hcoop.net/clinton/abcde.git/commitdiff_plain/6d81edb6ec135d2c5ef91d77692fb7402e4e86a5?ds=inline More work on musicbrainz support git-svn-id: http://abcde.googlecode.com/svn/trunk@174 a0fa61bc-5347-0410-a1a9-7f54aa4e1825 --- diff --git a/abcde b/abcde index 139b353..7efa584 100755 --- a/abcde +++ b/abcde @@ -53,6 +53,7 @@ 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 "-r " 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 " echo " Show dielfs from the CDDB info (year,genre)" @@ -1623,40 +1624,59 @@ do_localcddb () CDDBLOCALSUCCESS="n" 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 [ "$(echo "${CDDBLOCALRESULTS}" | wc -l)" = "1" ]; then + CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBLOCALRESULTS}" + CDDBLOCALMATCH=single + elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then + CDDBLOCALMATCH=multiple else - #echo "Not using local copy of CDDB data" - CDDBLOCALSUCCESS="n" + CDDBLOCALMATCH=none fi + elif [ -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 + single) + # 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" + else + #echo "Not using local copy of CDDB data" + CDDBLOCALSUCCESS="n" + fi + ;; + none) + CDDBLOCALSUCCESS="n" + ;; + esac fi } @@ -1862,8 +1882,12 @@ do_cddbedit () 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" ;; *) @@ -3061,6 +3085,12 @@ case "$CUEREADERSYNTAX" in ;; 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" @@ -3202,14 +3232,16 @@ fi 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) diff --git a/abcde.conf b/abcde.conf index ac50e7b..8a7fcda 100644 --- a/abcde.conf +++ b/abcde.conf @@ -23,6 +23,7 @@ # are cached locally in $CDDBLOCALDIR #CDDBCOPYLOCAL="n" #CDDBLOCALDIR="$HOME/.cddb" +#CDDBLOCALRECURSIVE="n" # If NOSUBMIT is set to y, then abcde will never prompt asking if you # wish to submit your edited cddb file. diff --git a/examples/musicbrainz-get-tracks b/examples/musicbrainz-get-tracks index 1d38480..be0b3b1 100755 --- a/examples/musicbrainz-get-tracks +++ b/examples/musicbrainz-get-tracks @@ -9,43 +9,22 @@ import musicbrainz.queries as mq DEF_CD_DEV = '/dev/cdrom' -# TODO: -# -# * --cdrom should take an argument, e.g. /dev/cdrom1. musicbrainz.queries -# doesn't seem to provide for this. - -def get_toc_discid(mb): - mb.Query(mq.MBQ_GetCDTOC) - return mb.GetResultData(mq.MBE_TOCGetCDIndexId) +def get_toc_discid(mb, dev): + mb.SetDevice(dev) + try: + mb.Query(mq.MBQ_GetCDTOC) + return mb.GetResultData(mq.MBE_TOCGetCDIndexId) + except musicbrainz.MusicBrainzError: + print >>sys.stderr, "error: could not read TOC from disc" + sys.exit(1) def lookup_discid(mb, id): mb.QueryWithArgs(mq.MBQ_GetCDInfoFromCDIndexId, [id]) -if __name__ == "__main__": - shortopts = 'cd:' - longopts = ['cdrom', 'discid='] - - mb = musicbrainz.mb() - mb.SetDepth(2) - - opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts) - - id = None - if opts: - for opt, arg in opts: - if opt in ('--cdrom', '-c'): - id = get_toc_discid(mb) - lookup_discid(mb, id) - if opt in ('--discid', '-d'): - id = arg - lookup_discid(mb, id) - else: - id = get_toc_discid(mb) - lookup_discid(mb, id) - +def fake_cddb(mb): matches = mb.GetResultInt(mq.MBE_GetNumAlbums) if matches == 0: - print >>sys.stderr, "could not find an entry for this CD" + print >>sys.stderr, "error: could not find an entry for this disc" sys.exit(1) if matches > 1: print >>sys.stderr, "warning: multiple matches, using first" @@ -121,3 +100,31 @@ if __name__ == "__main__": print "PLAYORDER=" print "." + +if __name__ == "__main__": + shortopts = 'nd:i:' + longopts = ['no-lookup', 'device=', 'id='] + + mb = musicbrainz.mb() + mb.SetDepth(2) + + opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts) + + id = None + lookup = True + if opts: + for opt, arg in opts: + if opt in ('--no-lookup', '-n'): + lookup = False + if opt in ('--device', '-d'): + id = get_toc_discid(mb, arg) + if opt in ('--id', '-i'): + id = arg + if not id: + id = get_toc_discid(mb, DEF_CD_DEV) + + if lookup: + lookup_discid(mb, id) + fake_cddb(mb) + else: + print id