Skip Menu |

This queue is for tickets about the MusicBrainz-Client CPAN distribution.

Report information
The Basics
Id: 6672
Status: resolved
Worked: 2 min
Priority: 0/
Queue: MusicBrainz-Client

People
Owner: svanzoest [...] cpan.org
Requestors: andy [...] hybridized.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.08
Fixed in: (no value)



Subject: Client not parsing RDF properly?
Thanks, the module now runs without any errors. However, now I am trying to use the following code which is returning no results. It gets the RDF data from MB just fine, but doesn't appear to be parsing it properly. my $mb = MusicBrainz::Client->new; $mb->set_debug(1); if ( !$mb->query_with_args( MBQ_GetAlbumById, [ 'cb36140d-2202-4170-8649-c2e1c20d9d96' ] ) ) { die("Query failed: ", $mb->get_query_error(), "\n"); } print "Amazon Cover URL: " . $mb->get_result_data(MBE_AlbumGetAmazonCoverartURL) . "\n"; Output: url: http://mm.musicbrainz.org:80/mm-2.1/album/cb36140d-2202-4170-8649-c2e1c20d9d96/2 query: result: <?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc = "http://purl.org/dc/elements/1.1/" xmlns:mq = "http://musicbrainz.org/mm/mq-1.1#" xmlns:mm = "http://musicbrainz.org/mm/mm-2.1#" xmlns:az = "http://www.amazon.com/gp/aws/landing.html#"> <mq:Result> <mq:status>OK</mq:status> <mm:albumList> <rdf:Bag> <rdf:li rdf:resource="http://musicbrainz.org/album/cb36140d-2202-4170-8649-c2e1c20d9d96"/> </rdf:Bag> </mm:albumList> </mq:Result> <mm:Album rdf:about="http://musicbrainz.org/album/cb36140d-2202-4170-8649-c2e1c20d9d96"> <dc:title>Mind Fruit</dc:title> <dc:creator rdf:resource="http://musicbrainz.org/artist/89240fa8-7e01-490f-8b4c-59f3f488eec6"/> <mm:cdindexidList> <rdf:Bag> <rdf:li rdf:resource="http://musicbrainz.org/cdindex/b3Wz.nJkbWNBfE6FyAFvRyE6M2c-"/> </rdf:Bag> </mm:cdindexidList> <mm:releaseType rdf:resource="http://musicbrainz.org/mm/mm-2.1#TypeAlbum"/> <mm:releaseStatus rdf:resource="http://musicbrainz.org/mm/mm-2.1#StatusOfficial"/> <mm:releaseDateList> <rdf:Seq> <rdf:li> <mm:ReleaseDate> <dc:date>1992-08-18</dc:date> <mm:country>US</mm:country> </mm:ReleaseDate> </rdf:li> </rdf:Seq> </mm:releaseDateList> <az:Asin>B000002JPG</az:Asin> <mm:coverart rdf:resource="http://images.amazon.com/images/P/B000002JPG.01.MZZZZZZZ.jpg"/> </mm:Album> </rdf:RDF> Amazon Cover URL:
[AGRUNDMA - Fri Jun 18 15:30:29 2004]: Show quoted text
> Thanks, the module now runs without any errors. However, now I am > trying to use the following code which is returning no results. It > gets the RDF data from MB just fine, but doesn't appear to be > parsing it properly.
Hmm.. did you add MBE_AlbumGetAmazonCoverartURL to your export list for MusicBrainz::Queries? I made a quick change to the getalbum.t test (attached) and ran in it on a FreeBSD 4.6-STABLE box with perl 5.8.4 with the following results. -- getalbum.out -- 1..1 MusicBrainz::Client version: 0.08 MusicBrainz::Queries version: 0.07 libmusicbrainz version: 2.1.1 AlbumId: cb36140d-2202-4170-8649-c2e1c20d9d96 Name: Mind Fruit Cover URL: http://images.amazon.com/images/P/B000002JPG.01.MZZZZZZZ.jpg NumTracks: 10 Track: It's A Fine Day TrackId : bc47584e-9f79-4851-bdac-b6d5224c07f8 TrackNum : 1 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: I Talk To The Wind TrackId : 53f0c7be-50f1-42fa-aaff-f200544b66c1 TrackNum : 2 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Flow TrackId : d088d101-21ff-4701-bfa6-aa845890990c TrackNum : 3 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Stars In My Pocket TrackId : a28dd509-bee0-4e6b-a942-63c07ae6e970 TrackNum : 4 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Sea People TrackId : ae25fb46-5366-4d7c-9ee0-57d3d77282d7 TrackNum : 5 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Evolution TrackId : 7aabbee0-a4c0-417d-9533-2a62af29ae94 TrackNum : 6 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Into This Universe TrackId : 61cde77a-b00f-4263-b0da-1786f2c61f81 TrackNum : 7 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Up TrackId : 02d311b8-0dd6-4a15-9416-62174a17cc67 TrackNum : 8 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Alzir TrackId : 20c62fa0-2f35-4a73-8779-ebd610a9400c TrackNum : 9 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 Track: Outro TrackId : c49f1c13-3587-4389-81a0-470a179571a2 TrackNum : 10 TrackArtist : Opus III ArtistId : 89240fa8-7e01-490f-8b4c-59f3f488eec6 ok 1 -- end --
BEGIN { $| =1; print "1..1\n"; } END { print "not ok 1\n" unless $loaded; } # # $Id$ # use strict; use MusicBrainz::Client qw(MB_CDINDEX_ID_LEN); use MusicBrainz::Queries qw(MBQ_GetAlbumById MBQ_GetCDInfoFromCDIndexId MBS_SelectAlbum MBE_AlbumGetAlbumId MBE_AlbumGetAlbumName MBE_AlbumGetAmazonCoverartURL MBE_AlbumGetNumTracks MBE_AlbumGetArtistId MBE_AlbumGetArtistName MBE_AlbumGetTrackName MBE_AlbumGetTrackId MBE_AlbumGetTrackList); #use constant ID => "dd4ff740-2a73-444d-8b55-d16fde79f429"; use constant ID => "cb36140d-2202-4170-8649-c2e1c20d9d96"; use constant MB_SERVER => "mm.musicbrainz.org"; use constant MB_PORT => 80; use constant MB_DEBUG => 0; use constant MB_DEPTH => 4; my $mb = new MusicBrainz::Client(); if( $^O eq "MSWin32" ) { $mb->WSAInit(); } # Tell the client library to return data in ISO8859-1 and not UTF-8 $mb->use_utf8(0); # Tell the server to return 10 items. $mb->set_max_items(10); # Set the proper server to use. Defaults to mm.musicbrainz.org:80 $mb->set_server(MB_SERVER, MB_PORT); # Check to see if the debug env var has been set $mb->set_debug(MB_DEBUG); # Tell the server to only return 2 levels of data, unless the MB_DEPTH var # is set $mb->set_depth(MB_DEPTH); printf("MusicBrainz::Client version: %s\n", $MusicBrainz::Client::VERSION); printf("MusicBrainz::Queries version: %s\n", $MusicBrainz::Queries::VERSION); printf("libmusicbrainz version: %d.%d.%d\n", $mb->get_version()); print "\n"; # Execute the MB_GetALbumById or a GetCDInfoFromCDIndexId query my $ret; if( length(ID) != MB_CDINDEX_ID_LEN ) { $ret = $mb->query_with_args( MBQ_GetAlbumById, [ ID ]); } else { $ret = $mb->query_with_args( MBQ_GetCDInfoFromCDIndexId, [ ID ]); } if( !$ret) { print "Query failed: ", $mb->get_query_error(), "\n"; exit(0); } # Select the first album $mb->select1(MBS_SelectAlbum, 1); my $data; # Pull back the album id to see if we got the album unless( $data = $mb->get_result_data( MBE_AlbumGetAlbumId ) ) { print "Album not found.\n"; exit(0); } print " AlbumId: ", $mb->get_id_from_url( $data ) || "", "\n"; # Extract the album name if( $data = $mb->get_result_data( MBE_AlbumGetAlbumName ) ) { print " Name: ", $data, "\n"; } if( $data = $mb->get_result_data( MBE_AlbumGetAmazonCoverartURL ) ) { print " Cover URL: ", $data, "\n"; } # Extract the number of tracks my $num_tracks = $mb->get_result_int( MBE_AlbumGetNumTracks ); if( $num_tracks > 0 && $num_tracks < 100 ) { print " NumTracks: ", $num_tracks, "\n"; } # Check to see if there is more than one artist for this album my $is_multiple_artist = 0; for(my $i = 1; $i <= $num_tracks; $i++) { unless( $data = $mb->get_result_data1( MBE_AlbumGetArtistId, $i ) ) { next; } my $temp = $data if( $i == 1 ); if( $temp eq $data ) { $is_multiple_artist = 1; last; } } unless( $is_multiple_artist ) { # Extract the artist name from the album if( $data = $mb->get_result_data1( MBE_AlbumGetArtistName, 1 ) ){ print "AlbumArtist: ", $data, "\n"; } if( $data = $mb->get_result_data1( MBE_AlbumGetArtistId, 1 ) ) { print "AlbumId : ", $data, "\n"; } } print "\n"; for( my $i = 1; $i <= $num_tracks; $i++ ) { # Extract the track name from the album. if( $data = $mb->get_result_data1( MBE_AlbumGetTrackName, $i ) ) { print "Track: ", $data, "\n"; } else { next; } # Extract the album id from the track. Just use the first album that # this track appreas on if( $data = $mb->get_result_data1( MBE_AlbumGetTrackId, $i ) ) { print "TrackId : ", $mb->get_id_from_url($data) || "", "\n"; # Extract the track number my $track_num = $mb->get_ordinal_from_list(MBE_AlbumGetTrackList, $data); if( $track_num > 0 && $track_num < 100 ) { print "TrackNum : ", $track_num, "\n"; } } # If its a multiple artist album, print out the artist for each track if( $is_multiple_artist ) { # Extract the artist name from this track if( $data = $mb->get_result_data1( MBE_AlbumGetArtistName, $i ) ) { print "TrackArtist : ", $data, "\n"; } if( $data = $mb->get_result_data1( MBE_AlbumGetArtistId, $i ) ) { print "ArtistId : ", $mb->get_id_from_url($data) || "", "\n"; } } print "\n"; } if( $^O eq "MSWin32" ) { $mb->WSAStop(); } our $loaded = 1; print "ok 1\n";
[AGRUNDMA - Fri Jun 18 15:30:29 2004]: Show quoted text
> Thanks, the module now runs without any errors. However, now I am > trying to use the following code which is returning no results. It > gets the RDF data from MB just fine, but doesn't appear to be > parsing it properly. > > my $mb = MusicBrainz::Client->new; > $mb->set_debug(1); > if ( !$mb->query_with_args( MBQ_GetAlbumById, [ 'cb36140d-2202-4170- > 8649-c2e1c20d9d96' ] ) ) { > die("Query failed: ", $mb->get_query_error(), "\n"); > } > print "Amazon Cover URL: " . $mb-
> >get_result_data(MBE_AlbumGetAmazonCoverartURL) . "\n";
Ahh.. I looked at your above code in more detail. You are missing the call to select the album. If you add the following line after the query, you should see the URL being printed: $mb->select1(MBS_SelectAlbum, 1); Alternatively, you could look at MusicBrainz::Client::Simple in the same package to get a more intuitive perl-ish interface to the library. hmm.. that reminds me. we need to add the new Queries to the MusicBrainz::Client::Simple::Album module. HTH, -- Sander
[SVANZOEST - Sun Jun 20 01:41:57 2004]: Show quoted text
> [AGRUNDMA - Fri Jun 18 15:30:29 2004]: >
> > Thanks, the module now runs without any errors. However, now I am > > trying to use the following code which is returning no results. It > > gets the RDF data from MB just fine, but doesn't appear to be > > parsing it properly. > > > > my $mb = MusicBrainz::Client->new; > > $mb->set_debug(1); > > if ( !$mb->query_with_args( MBQ_GetAlbumById, [ 'cb36140d-2202-4170- > > 8649-c2e1c20d9d96' ] ) ) { > > die("Query failed: ", $mb->get_query_error(), "\n"); > > } > > print "Amazon Cover URL: " . $mb-
> > >get_result_data(MBE_AlbumGetAmazonCoverartURL) . "\n";
> > Ahh.. I looked at your above code in more detail. > > You are missing the call to select the album. > > If you add the following line after the query, you should see the URL > being printed: > $mb->select1(MBS_SelectAlbum, 1); > > Alternatively, you could look at MusicBrainz::Client::Simple in the same > package to get a more intuitive perl-ish interface to the library. > > hmm.. that reminds me. we need to add the new Queries to the > MusicBrainz::Client::Simple::Album module. > > HTH, > > -- Sander
Thanks! That did the trick. It's a bit strange that the API requires you to call select1 even though you will always get only 1 album back when doing an AlbumId query. I will definitely check out the Simple API. -Andy
Hi, I released 0.09 today. This version no longer supports the Amazon Cover Art URL because of potential legal liability. Sorry for the inconvenience. -- Sander