]> diplodocus.org Git - flac-archive/commitdiff
fa-tags:
authorepg <>
Fri, 27 Aug 2004 03:07:55 +0000 (03:07 +0000)
committerepg <>
Fri, 27 Aug 2004 03:07:55 +0000 (03:07 +0000)
    Rewrite in Perl using MusicBrainz::Client::Simple.

fa-rip:
    Adapt to new fa-tags.  Use mktemp(1) to create work directory now
    that we don't have cd-discid.

README:
    No longer need cddb-tool and cd-discid.

README
fa-rip
fa-tags

diff --git a/README b/README
index 324eddd188508efd9b344537f1f0787b2b55c029..a1c241fb7bbc75b3391a56c4502e1a516445f636 100644 (file)
--- a/README
+++ b/README
@@ -2,7 +2,6 @@ $Id$
 
 Run perldoc fa-flacd for more information.
 
-flac-archive requires Perl >= 5.6, zsh >= 4.0, cddb-tool (part of
-abcde) and cd-discid, cdparanoia, and cdrdao.
+flac-archive requires Perl >= 5.6, zsh >= 4.0, cdparanoia, and cdrdao.
 
 flac2mp3 additionally requires lame.
diff --git a/fa-rip b/fa-rip
index a97e90c8b2696d8e2bec27809807c0a5f635d3ac..eabf52ea97878939f1418511c60f3aaaf190846d 100755 (executable)
--- a/fa-rip
+++ b/fa-rip
@@ -23,14 +23,14 @@ if [[ -z ${CDDEV} ]]; then
     fi
 fi
 
-discid=($(cd-discid ${CDDEV}))
+dir=$(mktemp -d flac-archive.XXXXXXXXXX)
+cd ${dir}
 
-[[ -d $discid[1] ]] || mkdir $discid[1]
-cd $discid[1]
+cdrdao read-toc --device ${CDDEV} --driver generic-mmc toc
+toc2cue toc cue
 
-eval fa-tags $discid &
+trackcount=$(grep -c 'TRACK.*AUDIO' cue)
 
-cdrdao read-toc --device ${CDDEV} --driver generic-mmc toc
-toc2cue toc cue &
+fa-tags ${trackcount}
 
 exec cdparanoia -d ${CDDEV} 1-$(grep -c 'TRACK.*AUDIO' cue) wav
diff --git a/fa-tags b/fa-tags
index 743736a2ecd1f4f8ab5c4c2f5fa5ddc4b60b3e54..d17dba34955064cac20a06f7d2ece972e83595b7 100755 (executable)
--- a/fa-tags
+++ b/fa-tags
-#! /usr/bin/env zsh
+#! /usr/bin/env perl
 
 # $Id$
 
-# Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
-# Copyright (c) 2003-2004 Jesus Climent <jesus.climent@hispalinux.es>
-# Copyright (c) 2004 Eric Gillespie <epg@pretzelnet.org>
-# This code is hereby licensed for public consumption under either the
-# GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
+use strict;
+use warnings;
 
-set -e
+use Getopt::Long;
+use Pod::Usage;
 
-if [[ -z ${CDDBURL} ]]; then
-    CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
-fi
+use MusicBrainz::Client::Simple;
 
-get_cddb_protocol () {
-    for CDDBPROTO in 5 4 3; do
-        if [[ \
-            $(cddb-tool stat $CDDBURL $USER $HOST $CDDBPROTO \
-            | sed 's/^\([0-9][0-9]*\).*/\1/;q') = '210' ]]; then
-            return 0
-        fi
-    done
+my $help;
+GetOptions(
+           'help|h|?' => \$help,
+          ) or pod2usage();
+$help and pod2usage(-exitstatus=>0, -verbose=>1);
 
-    echo "${CDDBURL} does not work"
-    exit 2
-}
-
-handle_read=$(<<EOF
-function rstrip_print(_s) {
-    sub(/[[:space:]]*\$/, "", _s)
-    print(_s)
-}
-
-BEGIN {
-    FS="="
-}
+my $trackcount = shift or pod2usage();
 
-/^DTITLE=/ {
-    split(\$2, a, /[[:blank:]]*\/[[:blank:]]*/)
-    rstrip_print("ARTIST=" a[1])
-    rstrip_print("ALBUM=" a[2])
-}
+my $mb = new MusicBrainz::Client::Simple;
+my @result = $mb->lookup_cd;
+die($mb->get_error) unless $mb->success;
 
-/^DYEAR=/ {
-    rstrip_print("DATE=" \$2)
-}
+open(F, '>candidate-tags-0') or die("open('>candidate-tags-0'): $!");
+print(F "$_=\n") for ('ARTIST', 'ALBUM', 'DATE');
+print(F "TITLE=\n") for 1 .. $trackcount;
+close(F) or die("close('>candidate-tags-0'): $!");
 
-/^TTITLE[[:digit:]]+/ {
-    rstrip_print("TITLE=" \$2)
-}
-EOF
-)
+my $i;
+for my $album (@result) {
+    $i++;
+    open(F, '>', "candidate-tags-$i") or die("open('>candidate-tags-$i'): $!");
 
-perl_handle_read=$(<<EOF
-(\$tag, \$value) = split(/=/, \$_, 2);
+    print(F 'ARTIST=', $album->get_artist->get_name, "\n");
+    print(F 'ALBUM=', $album->get_name, "\n");
+    print(F "DATE=\n");
 
-if (/^DTITLE=/) {
-    (\$artist, \$album) = split(/\\s*\\/\\s*/, \$value);
-    print("ARTIST=\$artist\\n");
-    print("ALBUM=\$album\\n");
+    my @tracks = $album->get_tracks;
+    my $name;
+    my $track;
+    for my $j (1 .. $trackcount) {
+        if ($track = shift(@tracks)) {
+            $name = $track->get_name;
+        } else {
+            $name = '';
+        }
+        print(F "TITLE=$name\n");
+    }
 
-} elsif (/^DYEAR=/) {
-    print("DATE=\$value\\n");
-
-} elsif (/^TTITLE\\d+/) {
-    print("TITLE=\$value\\n");
+    close(F) or die("close('>candidate-tags-$i'): $!");
 }
-EOF
-)
-
-handle_queries () {
-    local F
-    local i=1
-
-    # First eat the status line.
-    read F
-
-    while read -A F; do
-        [[ $F = '.' ]] && break
-        cddb-tool read $CDDBURL $CDDBPROTO $USER $HOST $F[1] $F[2] \
-            | nawk $handle_read > candidate-tags-$i
-# XXX The awk script has at least one problem; since we can't split to
-# exactly two components, we break on track names with equal signs.
-# Use Perl instead:
-#        cddb-tool read $CDDBURL $CDDBPROTO $USER $HOST $F[1] $F[2] \
-#            | perl -lne $handle_read > candidate-tags-$i
-        i=$(( $i + 1 ))
-    done
-}
-
-get_cddb_protocol
-(cddb-tool query $CDDBURL $CDDBPROTO $USER $HOST "$@" | handle_queries) &
-
-cat > candidate-tags-0 <<EOF
-ARTIST=
-ALBUM=
-DATE=
-EOF
-for (( i = 1; i <= $2; i++ )); do
-    echo 'TITLE=' >> candidate-tags-0
-done