Debian Codegraph @

README

raw
1 NAME
2 CDDB.pm - a high-level interface to cddb protocol servers (freedb and
3 CDDB)
4
5 VERSION
6 version 1.222
7
8 SYNOPSIS
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 => '[email protected]', # will try to determine
69 );
70
71 DESCRIPTION
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
91 PUBLIC 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 '[email protected]'. Note, that testing
130 submissions should be done via "[email protected]".
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
515 PRIVATE METHODS
516 Documented as being not documented.
517
518 EXAMPLES
519 Please see the cddb.t program in the t (tests) directory. It exercises
520 every aspect of CDDB.pm, including submissions.
521
522 COMPATIBILITY
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
540 KNOWN 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
556 LINKS
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
567 CONTACT 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