README
1NAME
2 CDDB.pm - a high-level interface to cddb protocol servers (freedb and
3 CDDB)
4
5VERSION
6 version 1.222
7
8SYNOPSIS
9 use CDDB;
10
11 ### Connect to the cddbp server.
12 my $cddbp = new CDDB(
13 Host => 'freedb.freedb.org', # default
14 Port => 8880, # default
15 Login => $login_id, # defaults to %ENV's
16 ) or die $!;
17
18 ### Retrieve known genres.
19 my @genres = $cddbp->get_genres();
20
21 ### Calculate cddbp ID based on MSF info.
22 my @toc = (
23 '1 0 2 37', # track, CD-i MSF (space-delimited)
24 '999 1 38 17', # lead-out track MSF
25 '1000 0 0 Error!', # error track (don't include if ok)
26 );
27 my (
28 $cddbp_id, # used for further cddbp queries
29 $track_numbers, # padded with 0's (for convenience)
30 $track_lengths, # length of each track, in MM:SS format
31 $track_offsets, # absolute offsets (used for further cddbp queries)
32 $total_seconds # total play time, in seconds (for cddbp queries)
33 ) = $cddbp->calculate_id(@toc);
34
35 ### Query discs based on cddbp ID and other information.
36 my @discs = $cddbp->get_discs($cddbp_id, $track_offsets, $total_seconds);
37 foreach my $disc (@discs) {
38 my ($genre, $cddbp_id, $title) = @$disc;
39 }
40
41 ### Query disc details (usually done with get_discs() information).
42 my $disc_info = $cddbp->get_disc_details($genre, $cddbp_id);
43 my $disc_time = $disc_info->{'disc length'};
44 my $disc_id = $disc_info->{discid};
45 my $disc_title = $disc_info->{dtitle};
46 my @track_offsets = @{$disc_info->{offsets}};
47 my @track_seconds = @{$disc_info->{seconds}};
48 my @track_titles = @{$disc_info->{ttitles}};
49 # other information may be returned... explore!
50
51 ### Submit a disc via e-mail. (Requires MailTools)
52
53 die "can't submit a disc (no mail modules; see README)"
54 unless $cddbp->can_submit_disc();
55
56 # These are useful for prompting the user to fix defaults:
57 print "I will send mail through: ", $cddbp->get_mail_host(), "\n";
58 print "I assume your e-mail address is: ", $cddbp->get_mail_address(), "\n";
59
60 # Actually submit a disc record.
61 $cddbp->submit_disc(
62 Genre => 'classical',
63 Id => 'b811a20c',
64 Artist => 'Various',
65 DiscTitle => 'Cartoon Classics',
66 Offsets => $disc_info->{offsets}, # array reference
67 TrackTitles => $disc_info->{ttitles}, # array reference
68 From => 'login@host.domain.etc', # will try to determine
69 );
70
71DESCRIPTION
72 CDDB protocol (cddbp) servers provide compact disc information for
73 programs that need it. This allows such programs to display disc and
74 track titles automatically, and it provides extended information like
75 liner notes and lyrics.
76
77 This module provides a high-level Perl interface to cddbp servers. With
78 it, a Perl program can identify and possibly gather details about a CD
79 based on its "table of contents" (the disc's track times and offsets).
80
81 Disc details have been useful for generating CD catalogs, naming mp3
82 files, printing CD liners, or even just playing discs in an automated
83 jukebox.
84
85 Despite the module's name, it connects to FreeDB servers by default.
86 This began at version 1.04, when cddb.com changed its licensing model to
87 support end-user applications, not third-party libraries. Connections to
88 cddb.com may still work, and patches are welcome to maintain that
89 functionality, but it's no longer officially supported.
90
91PUBLIC METHODS
92 new PARAMETERS
93 Creates a high-level interface to a cddbp server, returning a handle
94 to it. The handle is not a filehandle. It is an object. The new()
95 constructor provides defaults for just about everything, but
96 everything is overrideable if the defaults aren't appropriate.
97
98 The interface will not actually connect to a cddbp server until it's
99 used, and a single cddbp interface may actually make several
100 connections (to possibly several servers) over the course of its
101 use.
102
103 The new() constructor accepts several parameters, all of which have
104 reasonable defaults.
105
106 Host and Port describe the cddbp server to connect to. These default
107 to 'freedb.freedb.org' and 8880, which is a multiplexor for all the
108 other freedb servers.
109
110 Utf8 is a boolean flag. If true, utf-8 will be used when submitting
111 CD info, and for interpreting the data reveived. This requires the
112 Encode module (and probably perl version at least 5.8.0). The
113 default is true if the Encode module can be loaded. Otherwise, it
114 will be false, meaning we fall back to ASCII.
115
116 Protocol_Version sets the cddbp version to use. CDDB.pm will not
117 connect to servers that don't support the version specified here.
118 The requested protocol version defaults to 1 if Utf8 is off, and to
119 6 if it is on.
120
121 Login is the login ID you want to advertise to the cddbp server. It
122 defaults to the login ID your computer assigns you, if that can be
123 determined. The default login ID is determined by the presence of a
124 LOGNAME or USER environment variable, or by the getpwuid() function.
125 On Windows systems, it defaults to "win32usr" if no default method
126 can be found and no Login parameter is set.
127
128 Submit_Address is the e-mail address where new disc submissions go.
129 This defaults to 'freedb-submit@freedb.org'. Note, that testing
130 submissions should be done via "test-submit@freedb.org".
131
132 Client_Name and Client_Version describe the client software used to
133 connect to the cddbp server. They default to 'CDDB.pm' and CDDB.pm's
134 version number. If developers change this, please consult freedb's
135 web site for a list of client names already in use.
136
137 Debug enables verbose operational information on STDERR when set to
138 true. It's normally not needed, but it can help explain why a
139 program is failing. If someone finds a reproduceable bug, the Debug
140 output and a test program would be a big help towards having it
141 fixed. In case of submission, if this flag is on, a copy of the
142 submission e-mail will be sent to the *From* address.
143
144 get_genres
145 Takes no parameters. Returns a list of genres known by the cddbp
146 server, or undef if there is a problem retrieving them.
147
148 calculate_id TOC
149 The cddb protocol defines an ID as a hash of track lengths and the
150 number of tracks, with an added checksum. The most basic information
151 required to calculate this is the CD table of contents (the CD-i
152 track offsets, in "MSF" [Minutes, Seconds, Frames] format).
153
154 Note however that there is no standard way to acquire this
155 information from a CD-ROM device. Therefore this module does not try
156 to read the TOC itself. Instead, developers must combine CDDB.pm
157 with a CD library which works with their system. The AudioCD suite
158 of modules is recommended: it has system specific code for MacOS,
159 Linux and FreeBSD. CDDB.pm's author has used external programs like
160 dagrab to fetch the offsets. Actual CDs aren't always necessary: the
161 author has heard of people generating TOC information from mp3 file
162 lengths.
163
164 That said, see parse_cdinfo() for a routine to parse "cdinfo" output
165 into a table of contents list suitable for calculate_id().
166
167 calculate_id() accepts TOC information as a list of strings. Each
168 string contains four fields, separated by whitespace:
169
170 offset 0: the track number
171
172 Track numbers start with 1 and run sequentially through the number
173 of tracks on a disc. Note: data tracks count on hybrid audio/data
174 CDs.
175
176 CDDB.pm understands two special track numbers. Track 999 holds the
177 lead-out information, which is required by the cddb protocol. Track
178 1000 holds information about errors which have occurred while
179 physically reading the disc.
180
181 offset 1: the track start time, minutes field
182
183 Tracks are often addressed on audio CDs using "MSF" offsets. This
184 stands for Minutes, Seconds, and Frames (fractions of a second). The
185 combination pinpoints the exact disc frame where a song starts.
186
187 Field 1 contains the M part of MSF. It is ignored for error tracks,
188 but it still must contain a number. Zero is suggested.
189
190 offset 2: the track start time, seconds field
191
192 This field contains the S part of MSF. It is ignored for error
193 tracks, but it still must contain a number. Zero is suggested.
194
195 offset 3: the track start time, frames field
196
197 This field contains the F part of MSF. For error tracks, it contains
198 a description of the error.
199
200 Example track file. Note: the comments should not appear in the
201 file.
202
203 1 0 2 37 # track 1 starts at 00:02 and 37 frames
204 2 1 38 17 # track 2 starts at 01:38 and 17 frames
205 3 11 57 30 # track 3 starts at 11:57 and 30 frames
206 ...
207 999 75 16 5 # leadout starts at 75:16 and 5 frames
208
209 Track 1000 should not be present if everything is okay:
210
211 1000 0 0 Error reading TOC: no disc in drive
212
213 In scalar context, calculate_id() returns just the cddbp ID. In a
214 list context, it returns an array containing the following values:
215
216 (
217 $cddbp_id,
218 $track_numbers,
219 $track_lengths,
220 $track_offsets,
221 $total_seconds
222 ) = $cddbp->calculate_id(@toc);
223
224 print(
225 "cddbp ID = $cddbp_id\n", # b811a20c
226 "track numbers = @$track_numbers\n", # 001 002 003 ...
227 "track lengths = @$track_lengths\n", # 01:36 10:19 04:29 ...
228 "track offsets = @$track_offsets\n", # 187 7367 53805 ...
229 "total seconds = $total_seconds\n", # 4514
230 );
231
232 CDDBP_ID
233
234 The 0th returned value is the hashed cddbp ID, required for any
235 queries or submissions involving this disc.
236
237 TRACK_NUMBERS
238
239 The 1st returned value is a reference to a list of track numbers,
240 one for each track (excluding the lead-out), padded to three
241 characters with leading zeroes. These values are provided for
242 convenience, but they are not required by cddbp servers.
243
244 TRACK_LENGTHS
245
246 The 2nd returned value is a reference to a list of track lengths,
247 one for each track (excluding the lead-out), in HH:MM format. These
248 values are returned as a convenience. They are not required by cddbp
249 servers.
250
251 TRACK_OFFSETS
252
253 The 3rd returned value is a reference to a list of absolute track
254 offsets, in frames. They are calculated from the MSF values, and
255 they are required by get_discs() and submit_disc().
256
257 TOTAL_SECONDS
258
259 The 4th and final value is the total playing time for the CD, in
260 seconds. The get_discs() function needs it.
261
262 get_discs CDDBP_ID, TRACK_OFFSETS, TOTAL_SECONDS
263 get_discs() asks the cddbp server for a summary of all the CDs
264 matching a given cddbp ID, track offsets, and total playing time.
265 These values can be retrieved from calculade_id().
266
267 my @id_info = $cddbp->calculate_id(@toc);
268 my $cddbp_id = $id_info->[0];
269 my $track_offsets = $id_info->[3];
270 my $total_seconds = $id_info->[4];
271
272 get_discs() returns an array of matching discs, each of which is
273 represented by an array reference. It returns an empty array if the
274 query succeeded but did not match, and it returns undef on error.
275
276 my @discs = $cddbp->get_discs( $cddbp_id, $track_offsets, $total_seconds );
277 foreach my $disc (@discs) {
278 my ($disc_genre, $disc_id, $disc_title) = @$disc;
279 print(
280 "disc id = $disc_id\n",
281 "disc genre = $disc_genre\n",
282 "disc title = $disc_title\n",
283 );
284 }
285
286 DISC_GENRE is the genre this disc falls into, as determined by
287 whoever submitted or last edited the disc. The genre is required
288 when requesting a disc's details. See get_genres() for how to
289 retrieve a list of cddbp genres.
290
291 CDDBP_ID is the cddbp ID of this disc. Cddbp servers perform fuzzy
292 matches, returning near misses as well as direct hits on a cddbp ID,
293 so knowing the exact ID for a disc is important when submitting
294 changes or requesting a particular near-miss' details.
295
296 DISC_TITLE is the disc's title, which may help a human to pick the
297 correct disc out of several close mathches.
298
299 get_discs_by_toc TOC
300 This function acts as a macro, combining calculate_id() and
301 get_discs() calls into one function. It takes the same parameters as
302 calculate_id(), and it returns the same information as get_discs().
303
304 get_discs_by_query QUERY_STRING
305 Fetch discs by a pre-built cddbp query string. Some disc querying
306 programs report this string, and get_discs_by_query() is a
307 convenient way to use that.
308
309 Cddb protocol query strings look like:
310
311 cddb query $cddbp_id $track_count @offsets $total_seconds
312
313 get_disc_details DISC_GENRE, CDDBP_ID
314 This function fetches a disc's detailed information from a cddbp
315 server. It takes two parameters: the DISC_GENRE and the CDDP_ID.
316 These parameters usually come from a call to get_discs().
317
318 The disc's details are returned in a reference to a fairly complex
319 hash. It includes information normally stored in comments. The most
320 common entries in this hash include:
321
322 $disc_details = get_disc_details( $disc_genre, $cddbp_id );
323
324 $disc_details->{"disc length"}
325
326 The disc length is commonly stored in the form "### seconds", where
327 ### is the disc's total playing time in seconds. It may hold other
328 time formats.
329
330 $disc_details->{discid}
331
332 This is a rehash (get it?) of the cddbp ID. It should match the
333 CDDBP_ID given to get_disc_details().
334
335 $disc_details->{dtitle}
336
337 This is the disc's title. I do not know whether it will match the
338 one returned by get_discs().
339
340 $disc_details->{offsets}
341
342 This is a reference to a list of absolute disc track offsets,
343 similar to the TRACK_OFFSETS returned by calculate_id().
344
345 $disc_details->{seconds}
346
347 This is a reference to a list of track length, in seconds.
348
349 $disc_details->{ttitles}
350
351 This is a reference to a list of track titles. These are the droids
352 you are looking for.
353
354 $disc_details->{"processed by"}
355
356 This is a comment field identifying the name and version of the
357 cddbp server which accepted and entered the disc record into the
358 database.
359
360 $disc_details->{revision}
361
362 This is the disc record's version number, used as a sanity check
363 (semaphore?) to prevent simultaneous revisions. Revisions start at 0
364 for new submissions and are incremented for every correction. It is
365 the responsibility of the submitter (be it a person or a program
366 using CDDB.pm) to provide a correct revision number.
367
368 $disc_details->{"submitted via"}
369
370 This is the name and version of the software that submitted this
371 cddbp record. The main intention is to identify records that are
372 submitted by broken software so they can be purged or corrected.
373
374 $disc_details->{xmcd_record}
375
376 The xmcd_record field contains a copy of the entire unprocessed
377 cddbp response that generated all the other fields.
378
379 $disc_details->{genre}
380
381 This is merely a copy of DISC_GENRE, since it's otherwise not
382 possible to determine it from the hash.
383
384 parse_xmcd_file XMCD_FILE_CONTENTS, [GENRE]
385 Parses an array ref of lines read from an XMCD file into the
386 disc_details hash described above. If the GENRE parameter is set it
387 will be included in disc_details.
388
389 can_submit_disc
390 Returns true or false, depending on whether CDDB.pm has enough
391 dependent modules to submit discs. If it returns false, you are
392 missing Mail::Internet, Mail::Header, or MIME::QuotedPrint.
393
394 get_mail_address
395 Returns what CDDB.pm thinks your e-mail address is, or what it was
396 last set to. It was added to fetch the default e-mail address so
397 users can see it and have an opportunity to correct it.
398
399 my $mail_from = $cddb->get_mail_address();
400 print "New e-mail address (or blank to keep <$mail_from>): ";
401 my $new_mail_from = <STDIN>;
402 $new_mail_from =~ s/^\s+//;
403 $new_mail_from =~ s/\s+$//;
404 $new_mail_from =~ s/\s+/ /g;
405 $mail_from = $new_mail_from if length $new_mail_from;
406
407 $cddbp->submit_disc(
408 ...,
409 From => $mail_from,
410 );
411
412 get_mail_host
413 Returns what CDDB.pm thinks your SMTP host is, or what it was last
414 set to. It was added to fetch the default e-mail transfer host so
415 users can see it and have an opportunity to correct it.
416
417 my $mail_host = $cddb->get_mail_host();
418 print "New e-mail host (or blank to keep <$mail_host>): ";
419 my $new_mail_host = <STDIN>;
420 $new_mail_host =~ s/^\s+//;
421 $new_mail_host =~ s/\s+$//;
422 $new_mail_host =~ s/\s+/ /g;
423 $mail_host = $new_mail_host if length $new_mail_host;
424
425 $cddbp->submit_disc(
426 ...,
427 Host => $mail_host,
428 );
429
430 parse_cdinfo CDINFO_FILE
431 Generates a table of contents suitable for calculate_id() based on
432 the output of a program called "cdinfo". CDINFO_FILE may either be a
433 text file, or it may be the cdinfo program itself.
434
435 my @toc = parse_cdinfo("cdinfo.txt"); # read cdinfo.txt
436 my @toc = parse_cdinfo("cdinfo|"); # run cdinfo directly
437
438 The table of contents can be passed directly to calculate_id().
439
440 submit_disc DISC_DETAILS
441 submit_disc() submits a disc record to a cddbp server. Currently it
442 only uses e-mail, although it will try different ways to send that.
443 It returns true or false depending on whether it was able to send
444 the submission e-mail.
445
446 The rest of CDDB.pm will work without the ability to submit discs.
447 While cddbp submissions are relatively rare, most CD collections
448 will have one or two discs not present in the system. Please submit
449 new discs to the system: the amazing number of existing discs got
450 there because others submitted them before you needed them.
451
452 submit_disc() takes six required parameters and two optional ones.
453 The parameters are named, like hash elements, and can appear in any
454 order.
455
456 Genre => DISC_GENRE
457
458 This is the disc's genre. It must be one of the genres that the
459 server knows. See get_genres().
460
461 Id => CDDBP_ID
462
463 This is the cddbp ID that identifies the disc. It should come from
464 calculate_id() if this is a new submission, or from
465 get_disc_details() if this is a revision.
466
467 Artist => DISC_ARTIST
468
469 This is the disc's artist, a freeform text field describing the
470 party responsible for the album. It will need to be entered from the
471 disc's notes for new submissions, or it can come from
472 get_disc_details() on subsequent revisions.
473
474 DiscTitle => DISC_TITLE
475
476 This is the disc's title, a freeform text field describing the
477 album. It must be entered from the disc's notes for new submissions.
478 It can come from get_disc_details() on subsequent revisions.
479
480 Offsets => TRACK_OFFSETS
481
482 This is a reference to an array of absolute track offsets, as
483 provided by calculate_id().
484
485 TrackTitles => TRACK_TITLES
486
487 This is a reference to an array of track titles, either entered by a
488 human or provided by get_disc_details().
489
490 From => EMAIL_ADDRESS
491
492 This is the disc submitter's e-mail address. It's not required, and
493 CDDB.pm will try to figure one out on its own if an address is
494 omitted. It may be more reliable to provide your own, however.
495
496 The default return address may not be a deliverable one, especially
497 if CDDB.pm is being used on a dial-up machine that isn't running its
498 own MTA. If the current machine has its own MTA, problems still may
499 occur if the machine's Internet address changes.
500
501 Host => SMTP_HOST
502
503 This is the SMTP host to contact when sending mail. It's not
504 required, and CDDB.pm will try to figure one out on its own. It will
505 look at the SMTPHOSTS environment variable is not defined, it will
506 try 'mail' and 'localhost' before finally failing.
507
508 Revision => REVISION
509
510 The revision number. Should be 1 for new submissions, and one higher
511 than the previous one for updates. The previous revision number is
512 available as the "revision" field in the hash returned by
513 get_disc_details().
514
515PRIVATE METHODS
516 Documented as being not documented.
517
518EXAMPLES
519 Please see the cddb.t program in the t (tests) directory. It exercises
520 every aspect of CDDB.pm, including submissions.
521
522COMPATIBILITY
523 CDDB.pm uses standard Perl modules. It has been tested at one point or
524 another on OS/2, MacOS and FreeBSD systems, as well as the systems
525 listed at:
526
527 http://testers.cpan.org/search?request=dist&dist=CDDB
528
529 If you want to submit disc information to the CDDB, you will need to
530 install two other modules:
531
532 Mail::Internet will allow CDDB.pm to send email submissions, and it
533 automagically includes Mail::Header.
534
535 MIME::QuotedPrint will allow CDDB.pm to send non-ASCII text
536 unscathed. Currently only ISO-8859-1 and ASCII are supported.
537
538 All other features will work without these modules.
539
540KNOWN TEST FAILURES
541 The last test in the "make test" suite will try to send a sample
542 submission to the CDDB if MailTools is present. It expects to find an
543 SMTP host in the SMTPHOST environment variable. It will fall back to
544 "mail" if SMTPHOST doesn't exist. If neither works, the test will be
545 skipped. To see why it's skipped:
546
547 make test TEST_VERBOSE=1
548
549 Some of the tests (most notably numbers 25, 27 and 29) compare data
550 returned by a cddbp server against a stored copy of a previous query.
551 These tests fail occasionally since the database is constantly in flux.
552 Starting with version 1.00, the test program uses fuzzy comparisons that
553 should fail less. Version 1.04 saw even fuzzier comparisons. Please
554 report any problems so they can be fixed.
555
556LINKS
557 BUG TRACKER
558 https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=CDDB
559
560 REPOSITORY
561 http://github.com/rcaputo/cddb-perl
562 http://gitorious.org/cddb-freedb-perl
563
564 OTHER RESOURCES
565 http://search.cpan.org/dist/CDDB/
566
567CONTACT AND COPYRIGHT
568 Copyright 1998-2013 Rocco Caputo. All rights reserved. This program is
569 free software; you can redistribute it and/or modify it under the same
570 terms as Perl itself.
571
572
README.mkdn
1# NAME
2
3CDDB.pm - a high-level interface to cddb protocol servers (freedb and CDDB)
4
5# VERSION
6
7version 1.222
8
9# SYNOPSIS
10
11 use CDDB;
12
13 ### Connect to the cddbp server.
14 my $cddbp = new CDDB(
15 Host => 'freedb.freedb.org', # default
16 Port => 8880, # default
17 Login => $login_id, # defaults to %ENV's
18 ) or die $!;
19
20 ### Retrieve known genres.
21 my @genres = $cddbp->get_genres();
22
23 ### Calculate cddbp ID based on MSF info.
24 my @toc = (
25 '1 0 2 37', # track, CD-i MSF (space-delimited)
26 '999 1 38 17', # lead-out track MSF
27 '1000 0 0 Error!', # error track (don't include if ok)
28 );
29 my (
30 $cddbp_id, # used for further cddbp queries
31 $track_numbers, # padded with 0's (for convenience)
32 $track_lengths, # length of each track, in MM:SS format
33 $track_offsets, # absolute offsets (used for further cddbp queries)
34 $total_seconds # total play time, in seconds (for cddbp queries)
35 ) = $cddbp->calculate_id(@toc);
36
37 ### Query discs based on cddbp ID and other information.
38 my @discs = $cddbp->get_discs($cddbp_id, $track_offsets, $total_seconds);
39 foreach my $disc (@discs) {
40 my ($genre, $cddbp_id, $title) = @$disc;
41 }
42
43 ### Query disc details (usually done with get_discs() information).
44 my $disc_info = $cddbp->get_disc_details($genre, $cddbp_id);
45 my $disc_time = $disc_info->{'disc length'};
46 my $disc_id = $disc_info->{discid};
47 my $disc_title = $disc_info->{dtitle};
48 my @track_offsets = @{$disc_info->{offsets}};
49 my @track_seconds = @{$disc_info->{seconds}};
50 my @track_titles = @{$disc_info->{ttitles}};
51 # other information may be returned... explore!
52
53 ### Submit a disc via e-mail. (Requires MailTools)
54
55 die "can't submit a disc (no mail modules; see README)"
56 unless $cddbp->can_submit_disc();
57
58 # These are useful for prompting the user to fix defaults:
59 print "I will send mail through: ", $cddbp->get_mail_host(), "\n";
60 print "I assume your e-mail address is: ", $cddbp->get_mail_address(), "\n";
61
62 # Actually submit a disc record.
63 $cddbp->submit_disc(
64 Genre => 'classical',
65 Id => 'b811a20c',
66 Artist => 'Various',
67 DiscTitle => 'Cartoon Classics',
68 Offsets => $disc_info->{offsets}, # array reference
69 TrackTitles => $disc_info->{ttitles}, # array reference
70 From => 'login@host.domain.etc', # will try to determine
71 );
72
73# DESCRIPTION
74
75CDDB protocol (cddbp) servers provide compact disc information for
76programs that need it. This allows such programs to display disc and
77track titles automatically, and it provides extended information like
78liner notes and lyrics.
79
80This module provides a high-level Perl interface to cddbp servers.
81With it, a Perl program can identify and possibly gather details about
82a CD based on its "table of contents" (the disc's track times and
83offsets).
84
85Disc details have been useful for generating CD catalogs, naming mp3
86files, printing CD liners, or even just playing discs in an automated
87jukebox.
88
89Despite the module's name, it connects to FreeDB servers by default.
90This began at version 1.04, when cddb.com changed its licensing model
91to support end-user applications, not third-party libraries.
92Connections to cddb.com may still work, and patches are welcome to
93maintain that functionality, but it's no longer officially supported.
94
95# PUBLIC METHODS
96
97- new PARAMETERS
98
99 Creates a high-level interface to a cddbp server, returning a handle
100 to it. The handle is not a filehandle. It is an object. The new()
101 constructor provides defaults for just about everything, but
102 everything is overrideable if the defaults aren't appropriate.
103
104 The interface will not actually connect to a cddbp server until it's
105 used, and a single cddbp interface may actually make several
106 connections (to possibly several servers) over the course of its use.
107
108 The new() constructor accepts several parameters, all of which have
109 reasonable defaults.
110
111 __Host__ and __Port__ describe the cddbp server to connect to. These
112 default to 'freedb.freedb.org' and 8880, which is a multiplexor for
113 all the other freedb servers.
114
115 __Utf8__ is a boolean flag. If true, utf-8 will be used when submitting
116 CD info, and for interpreting the data reveived. This requires the
117 [Encode](http://search.cpan.org/perldoc?Encode) module (and probably perl version at least 5.8.0). The
118 default is true if the [Encode](http://search.cpan.org/perldoc?Encode) module can be loaded. Otherwise, it
119 will be false, meaning we fall back to ASCII.
120
121 __Protocol\_Version__ sets the cddbp version to use. CDDB.pm will not
122 connect to servers that don't support the version specified here. The
123 requested protocol version defaults to 1 if __Utf8__ is off, and to 6
124 if it is on.
125
126 __Login__ is the login ID you want to advertise to the cddbp server.
127 It defaults to the login ID your computer assigns you, if that can be
128 determined. The default login ID is determined by the presence of a
129 LOGNAME or USER environment variable, or by the getpwuid() function.
130 On Windows systems, it defaults to "win32usr" if no default method can
131 be found and no Login parameter is set.
132
133 __Submit\_Address__ is the e-mail address where new disc submissions go.
134 This defaults to 'freedb-submit@freedb.org'. Note, that testing
135 submissions should be done via `test-submit@freedb.org`.
136
137 __Client\_Name__ and __Client\_Version__ describe the client software used
138 to connect to the cddbp server. They default to 'CDDB.pm' and
139 CDDB.pm's version number. If developers change this, please consult
140 freedb's web site for a list of client names already in use.
141
142 __Debug__ enables verbose operational information on STDERR when set to
143 true. It's normally not needed, but it can help explain why a program
144 is failing. If someone finds a reproduceable bug, the Debug output
145 and a test program would be a big help towards having it fixed. In
146 case of submission, if this flag is on, a copy of the submission
147 e-mail will be sent to the _From_ address.
148
149- get\_genres
150
151 Takes no parameters. Returns a list of genres known by the cddbp
152 server, or undef if there is a problem retrieving them.
153
154- calculate\_id TOC
155
156 The cddb protocol defines an ID as a hash of track lengths and the
157 number of tracks, with an added checksum. The most basic information
158 required to calculate this is the CD table of contents (the CD-i track
159 offsets, in "MSF" \[Minutes, Seconds, Frames\] format).
160
161 Note however that there is no standard way to acquire this information
162 from a CD-ROM device. Therefore this module does not try to read the
163 TOC itself. Instead, developers must combine CDDB.pm with a CD
164 library which works with their system. The AudioCD suite of modules
165 is recommended: it has system specific code for MacOS, Linux and
166 FreeBSD. CDDB.pm's author has used external programs like dagrab to
167 fetch the offsets. Actual CDs aren't always necessary: the author has
168 heard of people generating TOC information from mp3 file lengths.
169
170 That said, see parse\_cdinfo() for a routine to parse "cdinfo" output
171 into a table of contents list suitable for calculate\_id().
172
173 calculate\_id() accepts TOC information as a list of strings. Each
174 string contains four fields, separated by whitespace:
175
176 offset 0: the track number
177
178 Track numbers start with 1 and run sequentially through the number of
179 tracks on a disc. Note: data tracks count on hybrid audio/data CDs.
180
181 CDDB.pm understands two special track numbers. Track 999 holds the
182 lead-out information, which is required by the cddb protocol. Track
183 1000 holds information about errors which have occurred while
184 physically reading the disc.
185
186 offset 1: the track start time, minutes field
187
188 Tracks are often addressed on audio CDs using "MSF" offsets. This
189 stands for Minutes, Seconds, and Frames (fractions of a second). The
190 combination pinpoints the exact disc frame where a song starts.
191
192 Field 1 contains the M part of MSF. It is ignored for error tracks,
193 but it still must contain a number. Zero is suggested.
194
195 offset 2: the track start time, seconds field
196
197 This field contains the S part of MSF. It is ignored for error
198 tracks, but it still must contain a number. Zero is suggested.
199
200 offset 3: the track start time, frames field
201
202 This field contains the F part of MSF. For error tracks, it contains
203 a description of the error.
204
205 Example track file. Note: the comments should not appear in the file.
206
207 1 0 2 37 # track 1 starts at 00:02 and 37 frames
208 2 1 38 17 # track 2 starts at 01:38 and 17 frames
209 3 11 57 30 # track 3 starts at 11:57 and 30 frames
210 ...
211 999 75 16 5 # leadout starts at 75:16 and 5 frames
212
213 Track 1000 should not be present if everything is okay:
214
215 1000 0 0 Error reading TOC: no disc in drive
216
217 In scalar context, calculate\_id() returns just the cddbp ID. In a
218 list context, it returns an array containing the following values:
219
220 (
221 $cddbp_id,
222 $track_numbers,
223 $track_lengths,
224 $track_offsets,
225 $total_seconds
226 ) = $cddbp->calculate_id(@toc);
227
228 print(
229 "cddbp ID = $cddbp_id\n", # b811a20c
230 "track numbers = @$track_numbers\n", # 001 002 003 ...
231 "track lengths = @$track_lengths\n", # 01:36 10:19 04:29 ...
232 "track offsets = @$track_offsets\n", # 187 7367 53805 ...
233 "total seconds = $total_seconds\n", # 4514
234 );
235
236 CDDBP\_ID
237
238 The 0th returned value is the hashed cddbp ID, required for any
239 queries or submissions involving this disc.
240
241 TRACK\_NUMBERS
242
243 The 1st returned value is a reference to a list of track numbers, one
244 for each track (excluding the lead-out), padded to three characters
245 with leading zeroes. These values are provided for convenience, but
246 they are not required by cddbp servers.
247
248 TRACK\_LENGTHS
249
250 The 2nd returned value is a reference to a list of track lengths, one
251 for each track (excluding the lead-out), in HH:MM format. These
252 values are returned as a convenience. They are not required by cddbp
253 servers.
254
255 TRACK\_OFFSETS
256
257 The 3rd returned value is a reference to a list of absolute track
258 offsets, in frames. They are calculated from the MSF values, and they
259 are required by get\_discs() and submit\_disc().
260
261 TOTAL\_SECONDS
262
263 The 4th and final value is the total playing time for the CD, in
264 seconds. The get\_discs() function needs it.
265
266- get\_discs CDDBP\_ID, TRACK\_OFFSETS, TOTAL\_SECONDS
267
268 get\_discs() asks the cddbp server for a summary of all the CDs
269 matching a given cddbp ID, track offsets, and total playing time.
270 These values can be retrieved from calculade\_id().
271
272 my @id_info = $cddbp->calculate_id(@toc);
273 my $cddbp_id = $id_info->[0];
274 my $track_offsets = $id_info->[3];
275 my $total_seconds = $id_info->[4];
276
277 get\_discs() returns an array of matching discs, each of which is
278 represented by an array reference. It returns an empty array if the
279 query succeeded but did not match, and it returns undef on error.
280
281 my @discs = $cddbp->get_discs( $cddbp_id, $track_offsets, $total_seconds );
282 foreach my $disc (@discs) {
283 my ($disc_genre, $disc_id, $disc_title) = @$disc;
284 print(
285 "disc id = $disc_id\n",
286 "disc genre = $disc_genre\n",
287 "disc title = $disc_title\n",
288 );
289 }
290
291 DISC\_GENRE is the genre this disc falls into, as determined by whoever
292 submitted or last edited the disc. The genre is required when
293 requesting a disc's details. See get\_genres() for how to retrieve a
294 list of cddbp genres.
295
296 CDDBP\_ID is the cddbp ID of this disc. Cddbp servers perform fuzzy
297 matches, returning near misses as well as direct hits on a cddbp ID,
298 so knowing the exact ID for a disc is important when submitting
299 changes or requesting a particular near-miss' details.
300
301 DISC\_TITLE is the disc's title, which may help a human to pick the
302 correct disc out of several close mathches.
303
304- get\_discs\_by\_toc TOC
305
306 This function acts as a macro, combining calculate\_id() and
307 get\_discs() calls into one function. It takes the same parameters as
308 calculate\_id(), and it returns the same information as get\_discs().
309
310- get\_discs\_by\_query QUERY\_STRING
311
312 Fetch discs by a pre-built cddbp query string. Some disc querying
313 programs report this string, and get\_discs\_by\_query() is a convenient
314 way to use that.
315
316 Cddb protocol query strings look like:
317
318 cddb query $cddbp_id $track_count @offsets $total_seconds
319
320- get\_disc\_details DISC\_GENRE, CDDBP\_ID
321
322 This function fetches a disc's detailed information from a cddbp
323 server. It takes two parameters: the DISC\_GENRE and the CDDP\_ID.
324 These parameters usually come from a call to get\_discs().
325
326 The disc's details are returned in a reference to a fairly complex
327 hash. It includes information normally stored in comments. The most
328 common entries in this hash include:
329
330 $disc_details = get_disc_details( $disc_genre, $cddbp_id );
331
332 $disc\_details->{"disc length"}
333
334 The disc length is commonly stored in the form "\#\#\# seconds", where
335 \#\#\# is the disc's total playing time in seconds. It may hold other
336 time formats.
337
338 $disc\_details->{discid}
339
340 This is a rehash (get it?) of the cddbp ID. It should match the
341 CDDBP\_ID given to get\_disc\_details().
342
343 $disc\_details->{dtitle}
344
345 This is the disc's title. I do not know whether it will match the one
346 returned by get\_discs().
347
348 $disc\_details->{offsets}
349
350 This is a reference to a list of absolute disc track offsets, similar
351 to the TRACK\_OFFSETS returned by calculate\_id().
352
353 $disc\_details->{seconds}
354
355 This is a reference to a list of track length, in seconds.
356
357 $disc\_details->{ttitles}
358
359 This is a reference to a list of track titles. These are the droids
360 you are looking for.
361
362 $disc\_details->{"processed by"}
363
364 This is a comment field identifying the name and version of the cddbp
365 server which accepted and entered the disc record into the database.
366
367 $disc\_details->{revision}
368
369 This is the disc record's version number, used as a sanity check
370 (semaphore?) to prevent simultaneous revisions. Revisions start at 0
371 for new submissions and are incremented for every correction. It is
372 the responsibility of the submitter (be it a person or a program using
373 CDDB.pm) to provide a correct revision number.
374
375 $disc\_details->{"submitted via"}
376
377 This is the name and version of the software that submitted this cddbp
378 record. The main intention is to identify records that are submitted
379 by broken software so they can be purged or corrected.
380
381 $disc\_details->{xmcd\_record}
382
383 The xmcd\_record field contains a copy of the entire unprocessed cddbp
384 response that generated all the other fields.
385
386 $disc\_details->{genre}
387
388 This is merely a copy of DISC\_GENRE, since it's otherwise not possible
389 to determine it from the hash.
390
391- parse\_xmcd\_file XMCD\_FILE\_CONTENTS, \[GENRE\]
392
393 Parses an array ref of lines read from an XMCD file into the
394 disc\_details hash described above. If the GENRE parameter is set it
395 will be included in disc\_details.
396
397- can\_submit\_disc
398
399 Returns true or false, depending on whether CDDB.pm has enough
400 dependent modules to submit discs. If it returns false, you are
401 missing Mail::Internet, Mail::Header, or MIME::QuotedPrint.
402
403- get\_mail\_address
404
405 Returns what CDDB.pm thinks your e-mail address is, or what it was
406 last set to. It was added to fetch the default e-mail address so
407 users can see it and have an opportunity to correct it.
408
409 my $mail_from = $cddb->get_mail_address();
410 print "New e-mail address (or blank to keep <$mail_from>): ";
411 my $new_mail_from = <STDIN>;
412 $new_mail_from =~ s/^\s+//;
413 $new_mail_from =~ s/\s+$//;
414 $new_mail_from =~ s/\s+/ /g;
415 $mail_from = $new_mail_from if length $new_mail_from;
416
417 $cddbp->submit_disc(
418 ...,
419 From => $mail_from,
420 );
421
422- get\_mail\_host
423
424 Returns what CDDB.pm thinks your SMTP host is, or what it was last set
425 to. It was added to fetch the default e-mail transfer host so users
426 can see it and have an opportunity to correct it.
427
428 my $mail_host = $cddb->get_mail_host();
429 print "New e-mail host (or blank to keep <$mail_host>): ";
430 my $new_mail_host = <STDIN>;
431 $new_mail_host =~ s/^\s+//;
432 $new_mail_host =~ s/\s+$//;
433 $new_mail_host =~ s/\s+/ /g;
434 $mail_host = $new_mail_host if length $new_mail_host;
435
436 $cddbp->submit_disc(
437 ...,
438 Host => $mail_host,
439 );
440
441- parse\_cdinfo CDINFO\_FILE
442
443 Generates a table of contents suitable for calculate\_id() based on the
444 output of a program called "cdinfo". CDINFO\_FILE may either be a text
445 file, or it may be the cdinfo program itself.
446
447 my @toc = parse_cdinfo("cdinfo.txt"); # read cdinfo.txt
448 my @toc = parse_cdinfo("cdinfo|"); # run cdinfo directly
449
450 The table of contents can be passed directly to calculate\_id().
451
452- submit\_disc DISC\_DETAILS
453
454 submit\_disc() submits a disc record to a cddbp server. Currently it
455 only uses e-mail, although it will try different ways to send that.
456 It returns true or false depending on whether it was able to send the
457 submission e-mail.
458
459 The rest of CDDB.pm will work without the ability to submit discs.
460 While cddbp submissions are relatively rare, most CD collections will
461 have one or two discs not present in the system. Please submit new
462 discs to the system: the amazing number of existing discs got there
463 because others submitted them before you needed them.
464
465 submit\_disc() takes six required parameters and two optional ones.
466 The parameters are named, like hash elements, and can appear in any
467 order.
468
469 Genre => DISC\_GENRE
470
471 This is the disc's genre. It must be one of the genres that the
472 server knows. See get\_genres().
473
474 Id => CDDBP\_ID
475
476 This is the cddbp ID that identifies the disc. It should come from
477 calculate\_id() if this is a new submission, or from get\_disc\_details()
478 if this is a revision.
479
480 Artist => DISC\_ARTIST
481
482 This is the disc's artist, a freeform text field describing the party
483 responsible for the album. It will need to be entered from the disc's
484 notes for new submissions, or it can come from get\_disc\_details() on
485 subsequent revisions.
486
487 DiscTitle => DISC\_TITLE
488
489 This is the disc's title, a freeform text field describing the album.
490 It must be entered from the disc's notes for new submissions. It can
491 come from get\_disc\_details() on subsequent revisions.
492
493 Offsets => TRACK\_OFFSETS
494
495 This is a reference to an array of absolute track offsets, as provided
496 by calculate\_id().
497
498 TrackTitles => TRACK\_TITLES
499
500 This is a reference to an array of track titles, either entered by a
501 human or provided by get\_disc\_details().
502
503 From => EMAIL\_ADDRESS
504
505 This is the disc submitter's e-mail address. It's not required, and
506 CDDB.pm will try to figure one out on its own if an address is
507 omitted. It may be more reliable to provide your own, however.
508
509 The default return address may not be a deliverable one, especially if
510 CDDB.pm is being used on a dial-up machine that isn't running its own
511 MTA. If the current machine has its own MTA, problems still may occur
512 if the machine's Internet address changes.
513
514 Host => SMTP\_HOST
515
516 This is the SMTP host to contact when sending mail. It's not
517 required, and CDDB.pm will try to figure one out on its own. It will
518 look at the SMTPHOSTS environment variable is not defined, it will try
519 'mail' and 'localhost' before finally failing.
520
521 Revision => REVISION
522
523 The revision number. Should be 1 for new submissions, and one higher
524 than the previous one for updates. The previous revision number is
525 available as the `revision` field in the hash returned by
526 get\_disc\_details().
527
528# PRIVATE METHODS
529
530Documented as being not documented.
531
532# EXAMPLES
533
534Please see the cddb.t program in the t (tests) directory. It
535exercises every aspect of CDDB.pm, including submissions.
536
537# COMPATIBILITY
538
539CDDB.pm uses standard Perl modules. It has been tested at one point
540or another on OS/2, MacOS and FreeBSD systems, as well as the systems
541listed at:
542
543 http://testers.cpan.org/search?request=dist&dist=CDDB
544
545If you want to submit disc information to the CDDB, you will need to
546install two other modules:
547
548 Mail::Internet will allow CDDB.pm to send email submissions, and it
549 automagically includes Mail::Header.
550
551 MIME::QuotedPrint will allow CDDB.pm to send non-ASCII text
552 unscathed. Currently only ISO-8859-1 and ASCII are supported.
553
554All other features will work without these modules.
555
556# KNOWN TEST FAILURES
557
558The last test in the "make test" suite will try to send a sample
559submission to the CDDB if MailTools is present. It expects to find an
560SMTP host in the SMTPHOST environment variable. It will fall back to
561"mail" if SMTPHOST doesn't exist. If neither works, the test will be
562skipped. To see why it's skipped:
563
564 make test TEST_VERBOSE=1
565
566Some of the tests (most notably numbers 25, 27 and 29) compare data
567returned by a cddbp server against a stored copy of a previous query.
568These tests fail occasionally since the database is constantly in
569flux. Starting with version 1.00, the test program uses fuzzy
570comparisons that should fail less. Version 1.04 saw even fuzzier
571comparisons. Please report any problems so they can be fixed.
572
573# LINKS
574
575## BUG TRACKER
576
577https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=CDDB
578
579## REPOSITORY
580
581http://github.com/rcaputo/cddb-perl
582http://gitorious.org/cddb-freedb-perl
583
584## OTHER RESOURCES
585
586http://search.cpan.org/dist/CDDB/
587
588# CONTACT AND COPYRIGHT
589
590Copyright 1998-2013 Rocco Caputo. All rights reserved. This program
591is free software; you can redistribute it and/or modify it under the
592same terms as Perl itself.
593