Subject: | WebService-MusicBrainz-0.22: Add ISRC support |
Date: | Wed, 12 Aug 2009 18:22:02 +0100 |
To: | bug-WebService-MusicBrainz [...] rt.cpan.org |
From: | Christopher Key <cjk32 [...] cam.ac.uk> |
The attached patch adds support for retrieving ISRCs from MusicBrainz.
It's based on the code for puids.. Currently, the code looks for a
puid-list within either a track or release element. It's not clear how
an isrc (or puid) could be attached to a release, so this has been left
out. Are there any circumstances where a puid-list could be returned
within a release element (and does this apply to isrc-lists too), or
should the relevant puid code be removed?
diff -urN WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response/Isrc.pm WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response/Isrc.pm
--- WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response/Isrc.pm 1970-01-01 01:00:00.000000000 +0100
+++ WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response/Isrc.pm 2009-08-12 18:01:08.000000000 +0100
@@ -0,0 +1,47 @@
+package WebService::MusicBrainz::Response::Isrc;
+
+use strict;
+use base 'Class::Accessor';
+
+our $VERSION = '0.22';
+
+=head1 NAME
+
+WebService::MusicBrainz::Response::Isrc
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+All the methods listed below are accessor methods. They can take a scalar argument to set the state of the object or without and argument, they will return that state if it is available.
+
+=head2 id()
+
+=cut
+
+__PACKAGE__->mk_accessors(qw/id/);
+
+=head1 AUTHOR
+
+=over 4
+
+=item Bob Faist <bob.faist@gmail.com>
+
+=back
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2006-2007 by Bob Faist
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+http://wiki.musicbrainz.org/XMLWebService
+
+=cut
+
+1;
diff -urN WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response/IsrcList.pm WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response/IsrcList.pm
--- WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response/IsrcList.pm 1970-01-01 01:00:00.000000000 +0100
+++ WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response/IsrcList.pm 2009-08-12 18:01:01.000000000 +0100
@@ -0,0 +1,51 @@
+package WebService::MusicBrainz::Response::IsrcList;
+
+use strict;
+use base 'Class::Accessor';
+
+our $VERSION = '0.22';
+
+=head1 NAME
+
+WebService::MusicBrainz::Response::IsrcList
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+All the methods listed below are accessor methods. They can take a scalar argument to set the state of the object or without and argument, they will return that state if it is available.
+
+=head2 isrcs()
+
+=head2 count()
+
+=head2 offset()
+
+=cut
+
+__PACKAGE__->mk_accessors(qw/isrcs count offset/);
+
+=head1 AUTHOR
+
+=over 4
+
+=item Bob Faist <bob.faist@gmail.com>
+
+=back
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2006-2007 by Bob Faist
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+http://wiki.musicbrainz.org/XMLWebService
+
+=cut
+
+1;
diff -urN WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response/Track.pm WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response/Track.pm
--- WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response/Track.pm 2009-04-26 04:49:12.000000000 +0100
+++ WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response/Track.pm 2009-08-12 17:53:30.000000000 +0100
@@ -37,7 +37,7 @@
=cut
-__PACKAGE__->mk_accessors(qw/id title duration artist release_list puid_list relation_list relation_lists score/);
+__PACKAGE__->mk_accessors(qw/id title duration artist release_list puid_list isrc_list relation_list relation_lists score/);
=head1 AUTHOR
diff -urN WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response.pm WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response.pm
--- WebService-MusicBrainz-0.22/lib/WebService/MusicBrainz/Response.pm 2009-04-26 04:49:12.000000000 +0100
+++ WebService-MusicBrainz-0.22-ISRC/lib/WebService/MusicBrainz/Response.pm 2009-08-12 17:59:42.000000000 +0100
@@ -415,6 +415,7 @@
my ($xArtist) = $xpc->findnodes('mmd:artist[1]', $xTrack);
my ($xReleaseList) = $xpc->findnodes('mmd:release-list[1]', $xTrack);
my ($xPuidList) = $xpc->findnodes('mmd:puid-list[1]', $xTrack);
+ my ($xIsrcList) = $xpc->findnodes('mmd:isrc-list[1]', $xTrack);
my @xRelationList = $xpc->findnodes('mmd:relation-list', $xTrack);
my ($xTagList) = $xpc->findnodes('mmd:tag-list[1]', $xTrack);
@@ -429,6 +430,7 @@
$track->artist( $self->_create_artist( $xArtist ) ) if $xArtist;
$track->release_list( $self->_create_release_list( $xReleaseList ) ) if $xReleaseList;
$track->puid_list( $self->_create_puid_list( $xPuidList ) ) if $xPuidList;
+ $track->isrc_list( $self->_create_isrc_list( $xIsrcList ) ) if $xIsrcList;
$track->tag_list( $self->_create_tag_list( $xTagList ) ) if $xTagList;
my $relationLists = $self->_create_relation_lists( \@xRelationList );
@@ -784,6 +786,44 @@
return $puid_list;
}
+sub _create_isrc {
+ my $self = shift;
+ my ($xIsrc) = @_;
+
+ require WebService::MusicBrainz::Response::Isrc;
+
+ my $isrc = WebService::MusicBrainz::Response::Isrc->new();
+
+ $isrc->id( $xIsrc->getAttribute('id') ) if $xIsrc->getAttribute('id');
+
+ return $isrc;
+}
+
+sub _create_isrc_list {
+ my $self = shift;
+ my ($xIsrcList) = @_;
+
+ my $xpc = $self->xpc();
+
+ require WebService::MusicBrainz::Response::IsrcList;
+
+ my $isrc_list = WebService::MusicBrainz::Response::IsrcList->new();
+
+ $isrc_list->count( $xIsrcList->getAttribute('count') ) if $xIsrcList->getAttribute('count');
+ $isrc_list->offset( $xIsrcList->getAttribute('offset') ) if $xIsrcList->getAttribute('offset');
+
+ my @isrcs;
+
+ foreach my $xIsrc ($xpc->findnodes('mmd:isrc', $xIsrcList)) {
+ my $isrc = $self->_create_isrc( $xIsrc );
+ push @isrcs, $isrc;
+ }
+
+ $isrc_list->isrcs( \@isrcs );
+
+ return $isrc_list;
+}
+
sub _create_tag {
my $self = shift;
my ($xTag) = @_;