CDDB::Fake - Fake CDDB entries if you have none


    use CDDB::Fake;
    my $cddb = CDDB::Fake->new("music/Egg/Egg/.nocddb");
    print "Artist: ", $cddb->artist, "\n";
    foreach my $track ( $cddb->tracks ) {
        print "Track ", $track->number, ": ", $track->title, "\n";


Sometimes there's no CDDB file available for a piece of music. For example, when you created a collection of tracks from other albums. In this case, a text file containing the name of the artist / album, followed by a mere list of the track titles can be used as a fall-back.

CDDB::Fake implements a part of the CDDB::File API based on manually crafted fall-back files.

I've adopted the convention to name files with CDDB data .cddb, and the fake data .nocddb.

For example, you can cut the results of a search at Gracenote ( and paste it into the file .nocddb. For example:

    Birelli Lagrene / Standards

       1. C'est Si Bon
       2. Softly, As in a Morning Sunrise
       3. Days of Wine and Roses
      12. Nuages

The track titles may be optionally followed by trailing TABs (not spaces) and a MM:SS time indicator (which may have a leading space if it's M:SS).

Extra track information can be passed on lines that follow the track title. These lines must start with whitespace, and may not begin with a number. Anything that follows the list of tracks is considered extra disc information. For example:

    Birelli Lagrene / Standards

       1. C'est Si Bon
          Original version
       2. Softly, As in a Morning Sunrise
          Live recording.
          Probably incomplete.
       3. Days of Wine and Roses
      12. Nuages

    This album was recorded in the Olympia Studios in Paris.

Multiple lines of additional info are concatenated with newlines inbetween. However, if one of the lines contains \n (that's backslash-n), all lines are conctenated using a single whitespace, and the \n's are turned into real newlines.

A tool is included to generate a fake file from the names of the files in the directory.

WARNING: CDDB::Fake implements only a part of the CDDB::File API.


new file

The new() package method takes the name of a file, and parses it. A CDDB::Fake object is then created from the file data.


Returns the name of the artist.


Returns the name of the album.


Returns the number of tracks.


Returns a list of track objects.


Returns the (fake) id for this disc.


These methods return empty strings since the information is not available in CDDB::Fake files.


This method will return the accumulated length of all the tracks, provided this information is present in the fake file.


Returns the extended disc information, that is everything that follows the list of tracks in the fake file.


Returns the data in the format of a CDDB entry.

Track objects provide the following methods:


The artist, usually the same as the artist of the disc.


The track number, starting with 1.


The track title.


The track length (in seconds).

This will be zero unless a track length was specified in the fake info.


The track offset.

This will be bogus unless track offsets could be estimated using the length information.


This extended track info, if present.


It is often handy to generalize the handling of real and fake files:

    use CDDB::File;     # the real one
    use CDDB::Fake;     # the fake one
    use Carp;

    # Return a CDDB::File object if a .cddb file is present, otherwise
    # return a CDDB::Fake onkect from a .nocddb file, if present.

    sub cddb_info($) {
        my $df = shift;
        croak("cddb_info(dir)\n") unless -d $df;
        return CDDB::File->new("$df/.cddb")   if -s "$df/.cddb";
        return CDDB::Fake->new("$df/.nocddb") if -s "$df/.nocddb";




Johan Vromans <>


This programs is Copyright 2003,2004, Squirrel Consultancy.

This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License or the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 458:

You forgot a '=back' before '=head1'