0

Im using the Musicbrainz cpan module to look up an album but Im having a few issues trying to decipher the output I recieve. I used data::Dumper to have a look at it, and it appears to be a hash or array of some sort but when I try to check the type I run into problems.

my $ws = WebService::MusicBrainz::Release->new();

my $response = $ws->search({ TITLE => 'ok computer' });


if (ref($response) eq "REF" || ref($response) eq "SCALAR" || ref($response) eq "ARRAY" || ref($response) eq "HASH" || ref($response) eq "CODE" || ref($response) eq "GLOBE")

 {
 print "\n What sort of thing is it? \n";
 }

Thanks

asaf
  • 1

2 Answers2

2

It's a WebService::MusicBrainz::Response object.

use WebService::MusicBrainz::Release;

my $ws = WebService::MusicBrainz::Release->new();
my $response = $ws->search({ TITLE => 'ok computer' });
my $release = $response->release(); # grab first one in the list
print $release->title(), " (", $release->type(), ") - ", $release->artist()->name(), "\n";
cjm
  • 61,471
  • 9
  • 126
  • 175
Brian Roach
  • 76,169
  • 12
  • 136
  • 161
  • ok, thank you, but Im still unsure of how to use it. In the example given how would you get multiple results, rather than just the first one in the list? – asaf Mar 20 '11 at 03:26
  • I copied and pasted that from the documentation. Which I linked to. Which contains all the information for using the module. For example, the `release_list()` method. – Brian Roach Mar 20 '11 at 04:40
0

Like already said, it is a WebService::MusicBrainz::Response object. You can retrieve multiple results with accessing the release_list() which gives an array of WebService::MusicBrainz::Response::Release objects.

use WebService::MusicBrainz::Release;

my $ws = WebService::MusicBrainz::Release->new();
my $response = $ws->search({ TITLE => 'ok computer' });

my @releaselist = $response->release_list();
foreach my $release ( @releaselist ) {
  print $release->title(), " - ", $release->artist()->name(), "\n";
}

However, that perl module is somewhat unmaintained and the XML Web service Version 1 it is using is deprecated.

You better use Version 2 of the Web Service. With python-musicbrainzngs there is a python module available that uses the new (next generation scheme) Web Service.

JonnyJD
  • 2,593
  • 1
  • 28
  • 44