Net-FreeDB
view release on metacpan or search on metacpan
}
}
return $disc_data;
}
sub _read
{
my $self = shift;
my $data = $self->obj->read_until_dot
or return undef;
return $data;
}
sub _query_line_to_hash
{
my $line = shift;
chomp($line);
my ($category, $disc_id, $the_rest) = split(/\s/, $line, 3);
my ($artist, $album) = split(/\s\/\s/, $the_rest);
return {
Category => $category,
DiscID => $disc_id,
Artist => $artist,
Album => $album,
};
}
sub _run_command
{
my ($self, @arguments) = @_;
my $response_code = undef;
if ($self->obj->command(@arguments)) {
$response_code = $self->obj->response();
if ($response_code != CMD_OK) {
my $error = $self->obj->message();
chomp($error);
$self->error($error);
}
}
return $response_code;
}
1;
__END__
=head1 NAME
Net::FreeDB - Perl interface to freedb server(s)
=head1 SYNOPSIS
use Net::FreeDB;
$freedb = Net::FreeDB->new();
$discdata = $freedb->getdiscdata('/dev/cdrom');
my $cddb_file_object = $freedb->read('rock', $discdata->{ID});
print $cddb_file_object->id;
=head1 DESCRIPTION
Net::FreeDB was inspired by Net::CDDB. And in-fact
was designed as a replacement in-part by Net::CDDB's
author Jeremy D. Zawodny. Net::FreeDB allows an
oop interface to the freedb server(s) as well as
some basic cdrom functionality like determining
disc ids, track offsets, etc.
=head2 METHODS
=over
=item new(remote_host => $h, remote_port => $p, user => $u, hostname => $hn, timeout => $to)
Constructor:
Creates a new Net::FreeDB object.
Parameters:
Set to username or user-string you'd like to be logged as. Defaults to $ENV{USER}
HOSTNAME: (optional)
Set to the hostname you'd like to be known as. Defaults to $ENV{HOSTNAME}
TIMEOUT: (optional)
Set to the number of seconds to timeout on freedb server. Defaults to 120
new() creates and returns a new Net::FreeDB object that is connected
to either the given host or freedb.freedb.org as default.
=item lscat
Returns a list of all available categories on the server.
Sets $obj->error on error
=item query($id, $num_trks, $trk_offset1, $trk_offset2, $trk_offset3...)
Parameters:
query($$$...) takes:
1: a discid
2: the number of tracks
3: first track offset
4: second track offset... etc.
Query expects $num_trks number of extra params after the first two.
query() returns an array of hashes. The hashes looks like:
{
Category => 'newage',
DiscID => 'discid',
Artist => 'artist',
Album => 'title'
}
Sets $obj->error on error
Database entries => <num_db_entries>
The total number of entries in the database.
<category_name => <num_db_entries>
The total number of entries in the database by category.
=item update
Parameters:
None
Tells the server to update the database (if you have permission).
Sets $obj->error on error.
=item validate($validating_string)
Parameters:
1: A string to be validated.
If you have permission, given a string the server will validate the string
as valid for use in a write call or not.
Sets $obj->error on error.
=item ver
Parameters:
None
Returns a string of the server's version.
=item whom
Parameters:
None
If you have permission, returns a list of usernames of all connected users.
Sets $obj->error on error.
=item get_local_disc_id
Parameters:
getdiscid($) takes the device you want to use.
Basically this means '/dev/cdrom' or whatever on linux machines
but it's an array index in the number of cdrom drives on windows
machines starting at 0. (Sorry, I may change this at a later time).
So, if you have only 1 cdrom drive then getdiscid(0) would work fine.
getdiscid() returns the discid of the current disc in the given drive.
NOTE: See BUGS
=item get_local_disc_data
Parameters:
getdiscdata($) takes the device you want to use. See getdiscid()
for full description.
getdiscdata() returns a hash of the given disc data as you would
require for a call to query. The returns hash look like:
{
ID => 'd00b3d10',
NUM_TRKS => '3',
TRACKS => [
'150',
'18082',
'29172'
],
SECONDS => '2879'
}
NOTE: A different return type/design may be developed.
=back
=head1 BUGS
The current version of getdiscid() and getdiscdata()
on the Windows platform takes ANY string in a single
cdrom configuration and works fine. That is if you
only have 1 cdrom drive; you can pass in ANY string
and it will still scan that cdrom drive and return
the correct data. If you have more then 1 cdrom drive
giving the correct drive number will return in an
accurate return.
=head1 Resources
The current version of the CDDB Server Protocol can be
found at: http://ftp.freedb.org/pub/freedb/latest/CDDBPROTO
=head1 AUTHOR
David Shultz E<lt>dshultz@cpan.orgE<gt>
Peter Pentchev E<lt>roam@ringlet.netE<gt>
=head1 CREDITS
Jeremy D. Zawodny E<lt>jzawodn@users.sourceforge.netE<gt>
Pete Jordon E<lt>ramtops@users.sourceforge.netE<gt>
=head1 COPYRIGHT
Copyright (c) 2002, 2014 David Shultz.
Copyright (c) 2005, 2006 Peter Pentchev.
All rights reserved.
This program is free software; you can redistribute it
and/or modify if under the same terms as Perl itself.
=cut
( run in 1.000 second using v1.01-cache-2.11-cpan-22024b96cdf )