1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
package MusicBrainz::DiscID;
################
#
# libdiscid: perl bindings
#
# Copyright 2009-2019 Nicholas J. Humfrey <njh@aelius.com>
#
use XSLoader;
use Carp;
use strict;
use vars qw/$VERSION/;
$VERSION="0.06";
XSLoader::load('MusicBrainz::DiscID', $VERSION);
sub default_device {
return MusicBrainz::DiscID::discid_get_default_device();
}
sub new {
my $class = shift;
my ($device) = @_;
# Get default device if none given
if (!defined $device) {
$device = MusicBrainz::DiscID::discid_get_default_device();
}
# Bless the hash into an object
my $self = { device => $device };
bless $self, $class;
# Create new DiscID instance
$self->{disc} = MusicBrainz::DiscID::discid_new();
if (!defined $self->{disc}) {
carp("Error creating DiscId structure");
undef $self;
}
return $self;
}
sub first_track_num {
my $self = shift;
return MusicBrainz::DiscID::discid_get_first_track_num($self->{disc});
}
sub error_msg {
my $self = shift;
return MusicBrainz::DiscID::discid_get_error_msg($self->{disc});
}
sub freedb_id {
my $self = shift;
return MusicBrainz::DiscID::discid_get_freedb_id($self->{disc});
}
sub id {
my $self = shift;
return MusicBrainz::DiscID::discid_get_id($self->{disc});
}
sub last_track_num {
my $self = shift;
return MusicBrainz::DiscID::discid_get_last_track_num($self->{disc});
}
sub put {
my $self = shift;
return MusicBrainz::DiscID::discid_put($self->{disc}, @_);
}
sub read {
my $self = shift;
$self->{device} = $_[0] if (defined $_[0]);
return MusicBrainz::DiscID::discid_read($self->{disc},$self->{device});
}
sub sectors {
my $self = shift;
return MusicBrainz::DiscID::discid_get_sectors($self->{disc});
}
sub submission_url {
my $self = shift;
return MusicBrainz::DiscID::discid_get_submission_url($self->{disc});
}
sub track_offset {
my $self = shift;
return MusicBrainz::DiscID::discid_get_track_offset($self->{disc}, $_[0]);
}
sub track_length {
my $self = shift;
return MusicBrainz::DiscID::discid_get_track_length($self->{disc}, $_[0]);
}
sub DESTROY {
my $self=shift;
if (defined $self->{disc}) {
MusicBrainz::DiscID::discid_free( $self->{disc} );
undef $self->{disc};
}
}
1;
__END__
=pod
=head1 NAME
MusicBrainz::DiscID - Perl interface for the MusicBrainz libdiscid library
=head1 SYNOPSIS
use MusicBrainz::DiscID;
my $discid = MusicBrainz::DiscID->new();
if ( $disc->read() == 0 ) {
print STDERR "Error: " . $discid->error_msg() . "\n";
exit(1);
}
print "DiscID: " . $discid->id() . "\n";
=head1 DESCRIPTION
MusicBrainz::DiscID is a class to calculate a MusicBrainz DiscID
from an audio CD in the drive. The coding style is slightly different to
the C interface to libdiscid, because it makes use of perl's Object Oriented
functionality.
=over 4
=item MusicBrainz::DiscID::default_device()
Returns a device string for the default device for this platform.
=item MusicBrainz::DiscID::new( [$device] )
Construct a new DiscID object.
As an optional argument the name of the device to read the ID from may
be given. If you don't specify a device here you can later read the ID with
the read method.
=item $discid->error_msg()
Return a human-readable error message of the last error that occurred.
=item $discid->first_track_num()
Return the number of the first track on this disc (usually 1).
Returns undef if no ID was yet read.
=item $discid->last_track_num()
Return the number of the last track on this disc.
=item $discid->id()
Returns the DiscID as a string.
Returns undef if no ID was yet read.
=item $discid->last_track_num()
Return the number of the last track on this disc.
Returns undef if no ID was yet read.
=item $discid->put( $first_track, $sectors, $offset1, $offset2, ... )
This function may be used if the TOC has been read earlier and you
want to calculate the disc ID afterwards, without accessing the disc
drive.
=item $discid->read( [$device] )
Read the disc ID from the given device.
If no device is given the default device of the platform will be used.
On error, this function returns false and sets the error message which you
can access $discid->error_msg().
=item $discid->sectors()
Return the length of the disc in sectors.
Returns undef if no ID was yet read.
=item $discid->submission_url()
Returns a submission URL for the DiscID as a string.
Returns undef if no ID was yet read.
=item $discid->track_length( $track_num )
Return the length of a track in sectors.
=item $discid->track_offset( $track_num )
Return the sector offset of a track.
=back
=head1 SEE ALSO
L<http://musicbrainz.org/doc/libdiscid>
=head1 AUTHOR
Nicholas J. Humfrey <njh@aelius.com>
=head1 COPYRIGHT AND LICENSE
The MIT License (MIT)
Copyright (c) 2009-2019 Nicholas J Humfrey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=cut
|