1

What is the best way to get the cd-title and the cd-track-names from an audio CD? I tried this module, but it didn't work.

#!/usr/bin/env perl
use warnings;
use strict;
use CDDB_get qw( get_cddb );

my %config;
$config{CDDB_HOST} = "freedb.freedb.org";
$config{CDDB_PORT} = 8880;
$config{CDDB_MODE} = "cddb";
$config{CD_DEVICE} = "/dev/sr1";

# user interaction welcome?
$config{input} = 1;

my %cd = get_cddb( \%config ); # line 16

print "$_ : $cd{$_}\n" for keys %cd;

unless( defined $cd{title} ) {
    die "no cddb entry found";
}

print "artist: $cd{artist}\n";
print "title: $cd{title}\n";
print "category: $cd{cat}\n";
print "cddbid: $cd{id}\n";
print "trackno: $cd{tno}\n";

my $n = 1;
for my $i ( @{$cd{track}} ) {
    print "track $n: $i\n";
    $n++;
}

# OUT:
# Odd number of elements in hash assignment at ./cddb_get.pl line 16.
# Use of uninitialized value in list assignment at ./cddb_get.pl line 16.
# Use of uninitialized value in concatenation (.) or string at ./cddb_get.pl line 18.
#  :
# no cddb entry found at ./cddb_get.pl line 21.
nicael
  • 18,550
  • 13
  • 57
  • 90
sid_com
  • 24,137
  • 26
  • 96
  • 187
  • What, more specifically, didn't work? – kb. Feb 15 '10 at 08:37
  • Uups, it works, but not with all cd's. – sid_com Feb 15 '10 at 09:35
  • 1
    @sid_com Of course not. Not all CDs are in FreeDB. :) – bzlm Feb 15 '10 at 15:53
  • 1
    Just to note: that information isn't on a normal audio CD. You collect fingerprint information from the CD and use that to query a database that attempts to match up what you sent it. Ensure that a program such as iTunes can fetch that information before you think your script is broken. :) – brian d foy Feb 22 '10 at 00:59
  • I have read in now more den 200 CD's; for five CD's there were no entry in the database, four of them are a little bit exotic, so I wouldn't have tried with these. Unfortunately I used the only "normal" CD, that didn't work to test the script and I looked too much at the script, so it didn't cross my mind to change the CD. – sid_com Feb 22 '10 at 07:17

3 Answers3

4

Try putting

BEGIN { $CDDB_get::debug = 1 }

before the use CDDB_get line in order to get debugging output to STDERR.

cjm
  • 61,471
  • 9
  • 126
  • 175
2

Are you sure the API URL to FreeDB is correct in the module?

Can you try HTTP instead of CDDBP?

From the FreeDB documentation:

Configure your CDDB1- or freedb-aware software to point to freedb.freedb.org (Random freedb server) as your CDDB/freedb-server.

All official freedb servers are running cddbp at port 8880 and http at port 80. The path for http-access is /~cddb/cddb.cgi.

bzlm
  • 9,626
  • 6
  • 65
  • 92
1

I would consider looking information up on musicbrainz.org instead.

Using MusicBrainz::DiscID to find the discid of a cd and WebService::MusicBrainz to retrieve the data is quite easy:

#!/usr/bin/perl

use strict;
use warnings;

use MusicBrainz::DiscID;
use WebService::MusicBrainz;

my $discid=MusicBrainz::DiscID->new;
if ( !$discid->read ) {
    print STDERR "Error: " . $discid->error_msg . "\n";
    exit 1;
}
print "DiscID: " . $discid->id . "\n";

my $service=WebService::MusicBrainz->new_release;
my $response=$service->search({ DISCID=>$discid->id });
my $release=$response->release;

print "ARTIST: " . $release->artist->name . "\n";
print "ALBUM:  " . $release->title . "\n";
asjo
  • 3,084
  • 2
  • 26
  • 20