MusicBrainz-DiscID-0.03/0000755000076500000240000000000011256507516013431 5ustar njhstaffMusicBrainz-DiscID-0.03/Build.PL0000444000076500000240000000310711256507516014724 0ustar njhstaff#!/usr/bin/perl # use Module::Build; use strict; # Check for pkg-config my $pkgconfig = `which pkg-config`; chomp($pkgconfig); if ($pkgconfig !~ /pkg-config/ or $pkgconfig =~ /not found/i) { die "Error: pkgconfig is not available on your system\n". "It is available from http://pkgconfig.freedesktop.org/\n"; } else { my $pkgconfig_version = `$pkgconfig --version`; chomp( $pkgconfig_version ); print "Found pkg-config version $pkgconfig_version.\n"; } # Display libdiscid version my $libdiscid_version = `$pkgconfig --modversion libdiscid`; chomp($libdiscid_version); if ($libdiscid_version =~ /^\d+\.\d+/) { print "Found libdiscid library version $libdiscid_version.\n"; } # Check libdiscid is new enough my $status = system("$pkgconfig --atleast-version=0.2.2 libdiscid"); if ($status != 0) { die "Error: libdiscid version 0.2.2 or higher is required.\n"; } # Get libdiscid CFLAGS my $LIBDISCID_CFLAGS = `$pkgconfig --cflags libdiscid`; chomp( $LIBDISCID_CFLAGS ); print " LIBDISCID_CFLAGS = $LIBDISCID_CFLAGS\n"; # Get libdiscid LIBS my $LIBDISCID_LIBS = `$pkgconfig --libs libdiscid`; chomp( $LIBDISCID_LIBS ); print " LIBDISCID_LIBS = $LIBDISCID_LIBS\n"; # Create the Build script my $build = Module::Build->new ( module_name => 'MusicBrainz::DiscID', license => 'gpl', build_requires => { 'Module::Build' => '0.20' }, requires => { 'Test' => '1.00', 'Test::More' => 0, }, # Optional modules recommends => { 'Test::Pod' => '1.00', }, extra_compiler_flags => $LIBDISCID_CFLAGS, extra_linker_flags => $LIBDISCID_LIBS, ); $build->create_build_script; MusicBrainz-DiscID-0.03/Changes0000444000076500000240000000041211256507516014717 0ustar njhstaffRevision history for libdiscid perl bindings 0.03 Wed 23 Sep 2009 22:07:22 BST - Corrections to synopsis from Adam Sjżgren 0.02 Wed 27 May 2009 23:19:11 BST - Proper tests - Added support for put method 0.01 Wed May 27 16:21:52 BST 2009 - First release MusicBrainz-DiscID-0.03/examples/0000755000076500000240000000000011256507516015247 5ustar njhstaffMusicBrainz-DiscID-0.03/examples/discid.pl0000444000076500000240000000150311256507516017040 0ustar njhstaff#!/usr/bin/perl use MusicBrainz::DiscID; use strict; my $disc = new MusicBrainz::DiscID(); # read the disc in the default disc drive */ if ( $disc->read() == 0 ) { printf STDERR "Error: %s\n", $disc->error_msg(); exit(1); } printf("DiscID : %s\n", $disc->id()); printf("FreeDB DiscID : %s\n", $disc->freedb_id()); printf("First track : %d\n", $disc->first_track_num()); printf("Last track : %d\n", $disc->last_track_num()); printf("Length : %d sectors\n", $disc->sectors()); for ( my $i = $disc->first_track_num; $i <= $disc->last_track_num; $i++ ) { printf("Track %-2d : %8d %8d\n", $i, $disc->track_offset($i), $disc->track_length($i)); } printf("Submit via : %s\n", $disc->submission_url()); printf("WS url : %s\n", $disc->webservice_url()); undef $disc; MusicBrainz-DiscID-0.03/lib/0000755000076500000240000000000011256507516014177 5ustar njhstaffMusicBrainz-DiscID-0.03/lib/MusicBrainz/0000755000076500000240000000000011256507516016425 5ustar njhstaffMusicBrainz-DiscID-0.03/lib/MusicBrainz/DiscID.pm0000444000076500000240000001276511256507516020073 0ustar njhstaffpackage MusicBrainz::DiscID; ################ # # libdiscid: perl bindings # # Copyright 2009 Nicholas J. Humfrey # use XSLoader; use Carp; use strict; use vars qw/$VERSION/; $VERSION="0.03"; 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 webservice_url { my $self = shift; return MusicBrainz::DiscID::discid_get_webservice_url($self->{disc}); } 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 occured. =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. =item $discid->webservice_url() Returns a Webservice URL for the DiscID as a string. Returns undef if no ID was yet read. =back =head1 SEE ALSO L =head1 AUTHOR Nicholas J. Humfrey =head1 COPYRIGHT AND LICENSE Copyright (C) 2009 Nicholas J. Humfrey This program is free software; you can redistribute it and/or modify it under the terms of 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =cut MusicBrainz-DiscID-0.03/lib/MusicBrainz/DiscID.xs0000444000076500000240000000427211256507516020103 0ustar njhstaff/* libdiscid perl bindings Copyright 2009 Nicholas J. Humfrey */ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include MODULE = MusicBrainz::DiscID PACKAGE = MusicBrainz::DiscID ## ## Return the name of the default disc drive for this operating system. ## char* discid_get_default_device() ## ## Return a handle for a new DiscId object. ## DiscId* discid_new() ## ## Release the memory allocated for the DiscId object. ## void discid_free( disc ) DiscId *disc ## ## Read the disc in the given CD-ROM/DVD-ROM drive. ## int discid_read( disc, device ) DiscId *disc char* device ## ## Return a human-readable error message. ## char* discid_get_error_msg( disc ) DiscId *disc ## ## Return a MusicBrainz DiscID. ## char* discid_get_id( disc ) DiscId *disc ## ## Return a FreeDB DiscID. ## char* discid_get_freedb_id( disc ) DiscId *disc ## ## Return an URL for submitting the DiscID to MusicBrainz. ## char* discid_get_submission_url( disc ) DiscId *disc ## ## Return an URL for retrieving CD information from MusicBrainz' web service. ## char* discid_get_webservice_url( disc ) DiscId *disc ## ## Return the number of the first track on this disc. ## int discid_get_first_track_num( disc ) DiscId *disc ## ## Return the number of the last track on this disc. ## int discid_get_last_track_num( disc ) DiscId *disc ## ## Return the length of the disc in sectors. ## int discid_get_sectors( disc ) DiscId *disc ## ## Return the sector offset of a track. ## int discid_get_track_offset( disc, track_num ) DiscId *disc int track_num ## ## Return the length of a track in sectors. ## int discid_get_track_length( disc, track_num ) DiscId *disc int track_num ## ## Provides the TOC of a known CD. ## int discid_put( disc, first_track, sectors, offsets ... ) DiscId *disc int first_track int sectors PREINIT: int i, last_track, offsets[100]; CODE: for (i=0;i<100;i++); offsets[i] = 0; for (i=3; i' abstract: Perl interface for the MusicBrainz libdiscid library license: gpl resources: license: http://opensource.org/licenses/gpl-license.php requires: Test: 1.00 Test::More: 0 build_requires: Module::Build: 0.20 recommends: Test::Pod: 1.00 provides: MusicBrainz::DiscID: file: lib/MusicBrainz/DiscID.pm version: 0.03 generated_by: Module::Build version 0.280801 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 MusicBrainz-DiscID-0.03/README0000444000076500000240000000206411256507516014311 0ustar njhstafflibdiscid perl binding ====================== Perl binding for the libdiscid library. libdiscid library version 0.2.2 or higher is required. http://musicbrainz.org/doc/libdiscid Pkg-config version 0.11 or higher is required: http://pkgconfig.freedesktop.org/ INSTALLATION ------------ I use Module::Build to build and install the module. To install this module type the following: perl Build.PL ./Build ./Build test And then as root: ./Build install AUTHOR ------ Nicholas J. Humfrey, njh@aelius.com COPYRIGHT --------- Copyright (C) 2009 Nicholas J. Humfrey This program is free software; you can redistribute it and/or modify it under the terms of 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. MusicBrainz-DiscID-0.03/t/0000755000076500000240000000000011256507516013674 5ustar njhstaffMusicBrainz-DiscID-0.03/t/00use.t0000444000076500000240000000032211256507516015010 0ustar njhstaff#!/usr/bin/perl use strict; use Test; # use a BEGIN block so we print our plan before loading modules BEGIN { plan tests => 1 } # Check MusicBrainz::DiscID loads ok use MusicBrainz::DiscID; ok(1); exit; MusicBrainz-DiscID-0.03/t/05pod.t0000444000076500000240000000031411256507516015004 0ustar njhstaff#!/usr/bin/perl # # Check that the POD documentation is Ok # use strict; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); MusicBrainz-DiscID-0.03/t/10discid.t0000444000076500000240000000552511256507516015466 0ustar njhstaff#!/usr/bin/perl # use strict; use Test::More; # use a BEGIN block so we print our plan before modules are loaded BEGIN { plan tests => 54 } # load modules use MusicBrainz::DiscID; # Create a new object my $disc = new MusicBrainz::DiscID(); ok( $disc ); is(ref $disc, 'MusicBrainz::DiscID'); ok( $disc->put( 1, 303602, 150, 9700, 25887, 39297, 53795, 63735, 77517, 94877, 107270, 123552, 135522, 148422, 161197, 174790, 192022, 205545, 218010, 228700, 239590, 255470, 266932, 288750 ) ); is( $disc->id, 'xUp1F2NkfP8s8jaeFn_Av3jNEI4-'); is( $disc->first_track_num, 1); is( $disc->freedb_id, '370fce16'); is( $disc->last_track_num, 22); is( $disc->sectors, 303602); is( $disc->submission_url, 'http://mm.musicbrainz.org/bare/cdlookup.html?id=xUp1F2NkfP8s8jaeFn_Av3jNEI4-&tracks=22&toc=1+22+303602+150+9700+25887+39297+53795+63735+77517+94877+107270+123552+135522+148422+161197+174790+192022+205545+218010+228700+239590+255470+266932+288750'); is( $disc->webservice_url, 'http://mm.musicbrainz.org/ws/1/release?type=xml&discid=xUp1F2NkfP8s8jaeFn_Av3jNEI4-&toc=1+22+303602+150+9700+25887+39297+53795+63735+77517+94877+107270+123552+135522+148422+161197+174790+192022+205545+218010+228700+239590+255470+266932+288750'); is( $disc->track_offset(1), 150); is( $disc->track_offset(2), 9700); is( $disc->track_offset(3), 25887); is( $disc->track_offset(4), 39297); is( $disc->track_offset(5), 53795); is( $disc->track_offset(6), 63735); is( $disc->track_offset(7), 77517); is( $disc->track_offset(8), 94877); is( $disc->track_offset(9), 107270); is( $disc->track_offset(10), 123552); is( $disc->track_offset(11), 135522); is( $disc->track_offset(12), 148422); is( $disc->track_offset(13), 161197); is( $disc->track_offset(14), 174790); is( $disc->track_offset(15), 192022); is( $disc->track_offset(16), 205545); is( $disc->track_offset(17), 218010); is( $disc->track_offset(18), 228700); is( $disc->track_offset(19), 239590); is( $disc->track_offset(20), 255470); is( $disc->track_offset(21), 266932); is( $disc->track_offset(22), 288750); is( $disc->track_length(1), 9550); is( $disc->track_length(2), 16187); is( $disc->track_length(3), 13410); is( $disc->track_length(4), 14498); is( $disc->track_length(5), 9940); is( $disc->track_length(6), 13782); is( $disc->track_length(7), 17360); is( $disc->track_length(8), 12393); is( $disc->track_length(9), 16282); is( $disc->track_length(10), 11970); is( $disc->track_length(11), 12900); is( $disc->track_length(12), 12775); is( $disc->track_length(13), 13593); is( $disc->track_length(14), 17232); is( $disc->track_length(15), 13523); is( $disc->track_length(16), 12465); is( $disc->track_length(17), 10690); is( $disc->track_length(18), 10890); is( $disc->track_length(19), 15880); is( $disc->track_length(20), 11462); is( $disc->track_length(21), 21818); is( $disc->track_length(22), 14852); undef $disc;