Question

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.
Was it helpful?

Solution

Try putting

BEGIN { $CDDB_get::debug = 1 }

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

OTHER TIPS

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.

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";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top