WebService-MusicBrainz-1.0.4000755000765000024 013241723022 16602 5ustar00robertfaiststaff000000000000WebService-MusicBrainz-1.0.4/Build.PL000444000765000024 134513241723022 20236 0ustar00robertfaiststaff000000000000use Module::Build; my $build = Module::Build->new ( module_name => 'WebService::MusicBrainz', dist_abstract => 'Web service API to MusicBrainz database', license => 'perl', requires => { 'perl' => '5.10.1', 'Mojolicious' => '7.13' }, configure_requires => { 'Module::Build' => '0.42' }, create_makefile_pl => 'traditional', dist_author => 'Bob Faist ', dist_version => '1.0.4', meta_merge => { resources => { repository => 'git://github.com/bfaist/webservice-musicbrainz.git' }, keywords => [ qw/musicbrainz webservice/ ] }, ); $build->create_build_script; WebService-MusicBrainz-1.0.4/Changes000444000765000024 1005413241723022 20252 0ustar00robertfaiststaff000000000000Revision history for Perl extension WebService::MusicBrainz. 0.01 Mon Apr 24 23:43:14 2006 - original version; created by h2xs 1.23 with options -AXn WebService::MusicBrainz 0.02 Thu Apr 27 2006 - Improved documentation - Removed debug print statement - Added factory object WebService::MusicBrainz - Improved test cases, added Factory.t test script - include META.yml which was missing originally - Remove .swp file accidentally left in distribution 0.03 Wed Sep 27 2006 - RT Bug 21511 fix (Thomas Adamcik) - RT Bug 21755 fix (Powder) 0.04 Wed Nov 15 2006 - Added feature for alternate mirrored host - Added more response objects to more closly match schema - Much closer to spec compliant (Schema: musicbrainz_mmd-1.0rc5.rng) 0.05 Thu Nov 16 2006 - Some test were failing so I corrected those and added a few more 0.06 Mon Nov 26 2006 - Incomplete MANIFEST file causing failures 0.07 Tue Feb 13 2007 - Failing test due to data change, test corrected (HairMetalAddict) 0.08 Web Apr 25 2007 - Another test was failing due to data change. 0.09 Sun May 13 2007 - Switched XML parsing from XML::Twig to XML::LibXML - Converted packaging to Module::Build with ExtUtils::MakeMaker compatibility - Fixed failing test in Release.t 0.10 Mon May 28 2007 - RT Bug 27287 fix (Ron Kuper) - More tests to check offsets are usable - Set user agent string 0.11 Mon Jul 9 2007 - LWP::UserAgent proxy enabled - Michael Ablassmeier - Fix bug with Response.pm - Michael Ablassmeier - Fixed failing tests in Release.t 0.12 Thu Nov 15 2007 - More compliant with 1.2 MMD Schema - Added "label" support and test cases - Fixed test case count in Release.t 0.13 Sun Dec 2 2007 - Fixed failing tests in Release.t 0.14 Mon Dec 3 2007 - Fixed test count in Release.t 0.15 Mon Dec 3 2007 - Added "URI" to required modules in Build.PL 0.16 Wed Dec 5 2007 - Updated t/Release.t 0.17 Sat Mar 2 2008 - Added URI escaping to URL (Edward Allen) - Added support for label, catno, and barcode in realease events - Changed how first object returned from collection (was shift, now ->[0]) - Added delays in test scripts to help not exceed webservice request threshold - Updated test cases 0.18 Wed May 14th 2008 - Update test in Release.t (Stefan) 0.19 Tue Oct 21st 2008 - RT bug 39945 - Chris Key 0.20 Mon Jan 5th 2009 - RT Bug 40597 - Slaven - Updated Build.PL perl version - RT Bug 42169 - pbryan - Fixed PUID object creation - Added test cases for PUID objects to Track.t 0.21 Mon Feb 2nd 2009 - RT Bug 42482 - orivej - Changed URI creation for multiple INC params - RT Bug 42534 - Chris Key - Applied patch to fix tag and alias parsing - fixed failing test in Artist.t - Added documentation about multiple INC params - Added test case to Artist.t for multiple INC params 0.22 Sat Apr 25th 2009 - RT Bug 44065 - Chris Key - Added new API "relation_lists" to Release response object - API method "relation_list" returns first relation list object - New API method "relation_lists" returns array ref with all relation lists - Added more tests to Release.t 0.90 Tue Oct 13th 2009 - RT Bug 48661 - Chris Key - Integrated supplied patch - Added ISRC support - RT Bug 50054 - Peter Oliver - Integrated supplied patch - Fixed UTF8 support - Made compliant with MMD 1.4 schema - Rewrote test cases (still more to do) - Added support for direct Lucene queries (suggest: Dave Hodgkinson) 0.91 Mon Oct 19th 2009 - RT Bug 50581 - Andreas Koenig - Added prereq for Test::More 0.88 0.92 Sat Nov 1st 2009 - Fixed failing test in Release.t 0.93 Fri Nov 27th 2009 - Release event lists are now sorted from earliest to the most recent 0.94 Tuesday Auguest 2016 - Fixed tests 1.0 2017 - Rewrite for version 2.0 of MusicBrainz API 1.0.1 Sunday March 26th 2017 - More tests - Fix minimum Mojolicious version 1.0.2 Friday June 2nd 2017 - Fix tests for busy server issues 1.0.3 Sunday December 17th 2017 - Added support to query for a discid (nguillaumin) WebService-MusicBrainz-1.0.4/MANIFEST000444000765000024 32413241723022 20047 0ustar00robertfaiststaff000000000000Build.PL Changes lib/WebService/MusicBrainz.pm lib/WebService/MusicBrainz/Request.pm Makefile.PL MANIFEST This list of files META.json META.yml README.md t/Area.t t/Artist.t t/Label.t t/Recording.t t/Release.t WebService-MusicBrainz-1.0.4/META.json000444000765000024 243513241723022 20364 0ustar00robertfaiststaff000000000000{ "abstract" : "Web service API to MusicBrainz database", "author" : [ "Bob Faist " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.422", "keywords" : [ "musicbrainz", "webservice" ], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "WebService-MusicBrainz", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0.42" } }, "runtime" : { "requires" : { "Mojolicious" : "7.13", "perl" : "v5.10.1" } } }, "provides" : { "WebService::MusicBrainz" : { "file" : "lib/WebService/MusicBrainz.pm", "version" : "v1.0.4" }, "WebService::MusicBrainz::Request" : { "file" : "lib/WebService/MusicBrainz/Request.pm", "version" : "1.0" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "git://github.com/bfaist/webservice-musicbrainz.git" } }, "version" : "v1.0.4", "x_serialization_backend" : "JSON::PP version 2.27400" } WebService-MusicBrainz-1.0.4/META.yml000444000765000024 156113241723022 20213 0ustar00robertfaiststaff000000000000--- abstract: 'Web service API to MusicBrainz database' author: - 'Bob Faist ' build_requires: {} configure_requires: Module::Build: '0.42' dynamic_config: 1 generated_by: 'Module::Build version 0.422, CPAN::Meta::Converter version 2.150010' keywords: - musicbrainz - webservice license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: WebService-MusicBrainz provides: WebService::MusicBrainz: file: lib/WebService/MusicBrainz.pm version: v1.0.4 WebService::MusicBrainz::Request: file: lib/WebService/MusicBrainz/Request.pm version: '1.0' requires: Mojolicious: '7.13' perl: v5.10.1 resources: license: http://dev.perl.org/licenses/ repository: git://github.com/bfaist/webservice-musicbrainz.git version: v1.0.4 x_serialization_backend: 'CPAN::Meta::YAML version 0.018' WebService-MusicBrainz-1.0.4/Makefile.PL000444000765000024 57513241723022 20700 0ustar00robertfaiststaff000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.4220 require 5.010001; use ExtUtils::MakeMaker; WriteMakefile ( 'VERSION_FROM' => 'lib/WebService/MusicBrainz.pm', 'INSTALLDIRS' => 'site', 'NAME' => 'WebService::MusicBrainz', 'PREREQ_PM' => { 'Mojolicious' => '7.13' }, 'EXE_FILES' => [], 'PL_FILES' => {} ) ; WebService-MusicBrainz-1.0.4/README.md000444000765000024 202113241723022 20211 0ustar00robertfaiststaff000000000000# WebService-MusicBrainz This module will search the MusicBrainz database through their web service and return objects with the found data. This module is not backward compatible with pre-1.0 versions. Version 1.0 is a complete re-write based on Mojolicious and implements [MusicBrainz Web Service Version 2](https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2). ## INSTALLATION To install this module, using the ExtUtils::MakeMaker method: perl Makefile.PL make make test make install To install this module using the Module::Build method: perl Build.PL ./Build ./Build test ./Build install ## DEPENDENCIES This module requires these other modules and libraries: * Mojolicious COPYRIGHT AND LICENSE Copyright (C) 2007-2017 by Bob Faist ( bob.faist at gmail.com ) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available. WebService-MusicBrainz-1.0.4/lib000755000765000024 013241723022 17350 5ustar00robertfaiststaff000000000000WebService-MusicBrainz-1.0.4/lib/WebService000755000765000024 013241723022 21406 5ustar00robertfaiststaff000000000000WebService-MusicBrainz-1.0.4/lib/WebService/MusicBrainz.pm000444000765000024 2310513241723022 24350 0ustar00robertfaiststaff000000000000package WebService::MusicBrainz; use strict; use Mojo::Base -base; use WebService::MusicBrainz::Request; our $VERSION = '1.0.4'; has 'request'; has valid_resources => sub { [ 'area', 'artist', 'discid', 'label', 'recording', 'release', 'release_group' ] }; has relationships => sub { my $rels = [ 'area-rels', 'artist-rels', 'event-rels', 'instrument-rels', 'label-rels', 'place-rels', 'recording-rels', 'release-rels', 'release-group-rels', 'series-rels', 'url-rels', 'work-rels' ]; return $rels; }; # inc subqueries our %subquery_map = ( _modifiers => [qw(discids media isrcs artist-credits various-artists)], _misc => [qw(aliases annotation tags ratings user-tags user-ratings)], artist => [qw(recordings releases release-groups works)], discid => [qw(artists artist-credits collections labels recordings release-groups)], label => [qw(releases)], recording => [qw(artists releases)], release => [qw(artists collections labels recordings release-groups)], release_group => [qw(artists releases)], ); has search_fields_by_resource => sub { my %search_fields; $search_fields{area} = [ 'aid', 'alias', 'area', 'begin', 'comment', 'end', 'ended', 'sortname', 'iso', 'iso1', 'iso2', 'iso3', 'type' ]; $search_fields{artist} = [ 'area', 'beginarea', 'endarea', 'arid', 'artist', 'artistaccent', 'alias', 'begin', 'comment', 'country', 'end', 'ended', 'gender', 'ipi', 'sortname', 'tag', 'type' ]; $search_fields{discid} = ['discid']; $search_fields{label} = [ 'alias', 'area', 'begin', 'code', 'comment', 'country', 'end', 'ended', 'ipi', 'label', 'labelaccent', 'laid', 'sortname', 'type', 'tag' ]; $search_fields{recording} = [ 'arid', 'artist', 'artistname', 'creditname', 'comment', 'country', 'date', 'dur', 'format', 'isrc', 'number', 'position', 'primarytype', 'puid', 'qdur', 'recording', 'recordingaccent', 'reid', 'release', 'rgid', 'rid', 'secondarytype', 'status', 'tid', 'trnum', 'tracks', 'tracksrelease', 'tag', 'type', 'video' ]; $search_fields{release_group} = [ 'arid', 'artist', 'comment', 'creditname', 'primarytype', 'rgid', 'releasegroup', 'releasegroupaccent', 'releases', 'release', 'reid', 'secondarytype', 'status', 'tag', 'type' ]; $search_fields{release} = [ 'arid', 'artist', 'artistname', 'asin', 'barcode', 'catno', 'comment', 'country', 'creditname', 'date', 'discids', 'discidsmedium', 'format', 'laid', 'label', 'lang', 'mediums', 'primarytype', 'puid', 'quality', 'reid', 'release', 'releaseaccent', 'rgid', 'script', 'secondarytype', 'status', 'tag', 'tracks', 'tracksmedium', 'type' ]; $search_fields{work} = [ 'alias', 'arid', 'artist', 'comment', 'iswc', 'lang', 'tag', 'type', 'wid', 'work', 'workaccent' ]; return \%search_fields; }; sub is_valid_subquery { my $self = shift; my $resource = shift; my $subqueries = shift; return unless ($resource); my $resource_map = $subquery_map{$resource}; return if ( !$resource_map ); my %valid_fields = map { $_ => 1 } ( @$resource_map, @{ $subquery_map{_modifiers} }, @{ $subquery_map{_misc} }, @{ $self->relationships } ); foreach my $subquery (@$subqueries) { return if ( !$valid_fields{$subquery} ); } return 1; } sub search { my $self = shift; my $search_resource = shift; my $search_query = shift; $self->request( WebService::MusicBrainz::Request->new() ); if ( !grep /^$search_resource$/, @{ $self->valid_resources() } ) { die "Not a valid resource for search ($search_resource)"; } $self->request()->search_resource($search_resource); if ( exists $search_query->{mbid} ) { $self->request()->mbid( $search_query->{mbid} ); delete $search_query->{mbid}; } if ( exists $search_query->{discid} ) { $self->request()->discid( $search_query->{discid} ); delete $search_query->{discid}; } my $inc_subqueries = delete $search_query->{inc}; # only use "inc" parameters when a specific MBID or DISCID is given if ( ( $self->request()->mbid() or $self->request()->discid() ) and $inc_subqueries ) { $inc_subqueries = [$inc_subqueries] if ( !ref $inc_subqueries ); if ( $self->is_valid_subquery( $search_resource, $inc_subqueries ) ) { $self->request()->inc($inc_subqueries); } else { my $subquery_str = join ", ", @$inc_subqueries; die "Not a valid \"inc\" subquery ($subquery_str) for resource: $search_resource"; } } if ( exists $search_query->{fmt} ) { $self->request()->format( $search_query->{fmt} ); delete $search_query->{fmt}; } if ( exists $search_query->{offset} ) { $self->request()->offset( $search_query->{offset} ); delete $search_query->{offset}; } foreach my $search_field ( keys %{$search_query} ) { if ( !grep /^$search_field$/, @{ $self->search_fields_by_resource->{$search_resource} } ) { die "Not a valid search field ($search_field) for resource \"$search_resource\""; } } $self->request->query_params($search_query); my $request_result = $self->request()->result(); return $request_result; } =head1 NAME WebService::MusicBrainz =head1 SYNOPSIS use WebService::MusicBrainz; my $mb = WebService::MusicBrainz->new(); my $result = $mb->search($resource => { $search_key => 'search value' }); my $result = $mb->search($resource => { $search_key => 'search value', fmt => 'json' }); # fmt => 'json' is default my $result_dom = $mb->search($resource => { $search_key => 'search value', fmt => 'xml' }); =head1 DESCRIPTION API to search the musicbrainz.org database =head1 VERSION Version 1.0 and future releases are not backward compatible with pre-1.0 releases. This is a complete re-write using version 2.0 of the MusicBrainz API and Mojolicious. =head1 METHODS =head2 new my $mb = WebService::MusicBrainz->new(); =head2 search my $result_list = $mb->search($resource => { param1 => 'value1' }); my $result = $mb->search($resource => { mbid => 'mbid' }); my $result_more = $mb->search($resource => { mbid => 'mbid', inc => 'extra stuff' }); Valid values for $resource are: area, artist, event, instrument, label, recording, release, release-group, series, work, url The default is to return decoded JSON as a perl data structure. Specify format => 'xml' to return the results as an instance of Mojo::DOM. =head3 Search by MBID my $result = $mb->search($resource => { mbid => 'xxxxxx' }); The "inc" search parameter is only allowed when searching for any particular "mbid". =head3 Search area my $area_list_results = $mb_ws->search(area => { iso => 'US-OH' }); my $area_list_results = $mb_ws->search(area => { area => 'cincinnati' }); my $area_list_results = $mb_ws->search(area => { alias => 'new york' }); my $area_list_results = $mb_ws->search(area => { sortname => 'new york' }); my $area_list_results = $mb_ws->search(area => { area => 'new york', type => 'city' }); my $area_result = $mb_ws->search(area => { mbid => '0573177b-9ff9-4643-80bc-ed2513419267' }); my $area_result = $mb_ws->search(area => { mbid => '0573177b-9ff9-4643-80bc-ed2513419267', inc => 'area-rels' }); =head3 Search artist # JSON example my $artists = $mb->search(artist => { artist => 'Ryan Adams' }); my $artists = $mb->search(artist => { artist => 'Ryan Adams', type => 'person' }); my $artist_country = $artists->{artists}->[0]->{country}; # XML example my $artists = $mb->search(artist => { artist => 'Ryan Adams', type => 'person', fmt => 'xml' }); my $artist_country = $artists->at('country')->text; # find this particular artist my $artist = $mb->search(artist => { mbid => '5c2d2520-950b-4c78-84fc-78a9328172a3' }); # find this particular artist and include release and artist relations (members of the band) my $artist = $mb->search(artist => { mbid => '5c2d2520-950b-4c78-84fc-78a9328172a3', inc => ['releases','artist-rels'] }); # artists that started in Cincinnati my $artists = $mb->search(artist => { beginarea => 'Cincinnati' }); =head3 Search label my $labels = $mb->search(label => { label => 'Death' }); =head3 Search recording my $recordings = $mb->search(recording => { artist => 'Taylor Swift' }); =head3 Search release my $releases = $mb->search(release => { release => 'Love Is Hell', status => 'official' }); print "RELEASE COUNT: ", $releases->{count}, "\n"; =head1 DEBUG Set environment variable MUSICBRAINZ_DEBUG=1 =over 1 =item The URL that is generated for the search will output to STDOUT. =item The formatted output (JSON or XML) will be output to STDOUT =back =head1 AUTHOR =over 4 =item Bob Faist =back =head1 COPYRIGHT AND LICENSE Copyright 2006-2017 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://musicbrainz.org/doc/Development/XML_Web_Service/Version_2 =cut 1; WebService-MusicBrainz-1.0.4/lib/WebService/MusicBrainz000755000765000024 013241723022 23634 5ustar00robertfaiststaff000000000000WebService-MusicBrainz-1.0.4/lib/WebService/MusicBrainz/Request.pm000444000765000024 503613241723022 25763 0ustar00robertfaiststaff000000000000package WebService::MusicBrainz::Request; use Mojo::Base -base; use Mojo::UserAgent; use Mojo::URL; use Mojo::Util qw/dumper/; has url_base => 'http://musicbrainz.org/ws/2'; has ua => sub { Mojo::UserAgent->new() }; has 'format' => 'json'; has 'search_resource'; has 'mbid'; has 'discid'; has 'inc' => sub { [] }; has 'query_params'; has offset => 0; has debug => sub { $ENV{MUSICBRAINZ_DEBUG} || 0 };; our $VERSION = '1.0'; binmode STDOUT, ":encoding(UTF-8)"; sub make_url { my $self = shift; my @url_parts; push @url_parts, $self->url_base(); push @url_parts, $self->search_resource(); push @url_parts, $self->mbid() if $self->mbid; push @url_parts, $self->discid() if $self->discid; my $url_str = join '/', @url_parts; $url_str .= '?fmt=' . $self->format; if(scalar(@{ $self->inc }) > 0) { my $inc_query = join '+', @{ $self->inc }; $url_str .= '&inc=' . $inc_query; } my @extra_params; foreach my $key (keys %{ $self->query_params }) { push @extra_params, $key . ':"' . $self->query_params->{$key} . '"'; } if(scalar(@extra_params) > 0) { my $extra_param_str = join ' AND ', @extra_params; $url_str .= '&query=' . $extra_param_str; } $url_str .= '&offset=' . $self->offset(); print "REQUEST URL: $url_str\n" if $self->debug(); my $url = Mojo::URL->new($url_str); return $url; } sub result { my $self = shift; my $request_url = $self->make_url(); my $get_result = $self->ua->get($request_url => { 'Accept-Encoding' => 'application/json' })->result; my $result_formatted; if($self->format eq 'json') { $result_formatted = $get_result->json; print "JSON RESULT: ", dumper($get_result->json) if $self->debug; } elsif($self->format eq 'xml') { $result_formatted = $get_result->dom; print "XML RESULT: ", $get_result->dom->to_string, "\n" if $self->debug; } else { warn "Unsupported format type : $self->format"; } return $result_formatted; } =head1 NAME WebService::MusicBrainz::Request =head1 SYNOPSIS =head1 ABSTRACT WebService::MusicBrainz::Request - Handle queries using the MusicBrainz WebService API version 2 =head1 DESCRIPTION =head1 METHODS =head1 AUTHOR =over 4 =item Bob Faist =back =head1 COPYRIGHT AND LICENSE Copyright 2006-2017 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; WebService-MusicBrainz-1.0.4/t000755000765000024 013241723022 17045 5ustar00robertfaiststaff000000000000WebService-MusicBrainz-1.0.4/t/Area.t000444000765000024 235413241723022 20243 0ustar00robertfaiststaff000000000000use strict; use Test::More; use WebService::MusicBrainz; sub exit_if_mb_busy { my $res = shift; if(exists $res->{error} && $res->{error} =~ m/^The MusicBrainz web server is currently busy/) { done_testing(); exit(0); } } my $ws = WebService::MusicBrainz->new(); ok($ws); # JSON TESTS my $s1_res = $ws->search(area => { mbid => '044208de-d843-4523-bd49-0957044e05ae' }); exit_if_mb_busy($s1_res); ok($s1_res->{type} eq 'City'); ok($s1_res->{name} eq 'Nashville'); ok($s1_res->{'sort-name'} eq 'Nashville'); sleep(1); my $s2_res = $ws->search(area => { area => 'cincinnati' }); exit_if_mb_busy($s2_res); ok($s2_res->{count} == 2); ok($s2_res->{areas}->[0]->{type} eq 'City'); ok($s2_res->{areas}->[1]->{type} eq 'City'); sleep(1); my $s3_res = $ws->search(area => { iso => 'US-OH' }); exit_if_mb_busy($s3_res); ok($s3_res->{count} == 1); ok($s3_res->{areas}->[0]->{name} eq 'Ohio'); sleep(1); eval { my $s4_res = $ws->search(area => { something => '99999' }) }; if($@) { ok($@) } # catch error sleep(1); my $s5_res = $ws->search(area => { iso => 'US-CA', fmt => 'xml' }); exit_if_mb_busy($s5_res); ok($s5_res->find('name')->first->text eq 'California'); ok($s5_res->at('area')->attr('ext:score') == 100); sleep(1); done_testing(); WebService-MusicBrainz-1.0.4/t/Artist.t000444000765000024 512613241723022 20641 0ustar00robertfaiststaff000000000000use strict; use Test::More; use WebService::MusicBrainz; sub exit_if_mb_busy { my $res = shift; if(exists $res->{error} && $res->{error} =~ m/^The MusicBrainz web server is currently busy/) { done_testing(); exit(0); } } my $ws = WebService::MusicBrainz->new(); ok($ws); # JSON TESTS my $s1_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e' }); exit_if_mb_busy($s1_res); ok($s1_res->{type} eq 'Person'); ok($s1_res->{'sort-name'} eq 'Prince'); ok($s1_res->{name} eq 'Prince'); ok($s1_res->{country} eq 'US'); ok($s1_res->{gender} eq 'Male'); sleep(1); my $s2_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', inc => 'releases' }); exit_if_mb_busy($s2_res); ok($s2_res->{type} eq 'Person'); ok(exists $s2_res->{releases}); ok($s2_res->{name} eq 'Prince'); sleep(1); my $s3_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', inc => ['releases','aliases'] }); exit_if_mb_busy($s3_res); ok(exists $s3_res->{releases}); ok(exists $s3_res->{aliases}); sleep(1); eval { my $s4_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', inc => 'nothing-here' }); exit_if_mb_busy($s4_res); }; like($@, qr/not a valid.*inc.*subquery/i); sleep(1); my $s5_res = $ws->search(artist => { artist => 'Coldplay' }); exit_if_mb_busy($s5_res); ok($s5_res->{artists}); ok($s5_res->{artists}->[0]->{name} eq 'Coldplay'); ok($s5_res->{artists}->[0]->{score} eq '100'); sleep(1); my $s6_res = $ws->search(artist => { artist => 'Van Halen', type => 'group' }); exit_if_mb_busy($s6_res); ok($s6_res->{count} == 1); ok($s6_res->{artists}->[0]->{type} eq 'Group'); ok($s6_res->{artists}->[0]->{id} eq 'b665b768-0d83-4363-950c-31ed39317c15'); sleep(1); my $s7_res = $ws->search(artist => { artist => 'Ryan Adams', type => 'person' }); exit_if_mb_busy($s7_res); ok($s7_res->{artists}->[0]->{'sort-name'} eq 'Adams, Ryan'); sleep(1); my $s8_res = $ws->search(artist => { artist => 'red' }); exit_if_mb_busy($s8_res); ok($s8_res->{count} >= 1700); ok($s8_res->{offset} == 0); sleep(1); my $s9_res = $ws->search(artist => { artist => 'red', offset => 30 }); exit_if_mb_busy($s9_res); ok($s9_res->{count} >= 1700); ok($s9_res->{offset} == 30); sleep(1); # XML TESTS my $s1_dom = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', fmt => 'xml' }); exit_if_mb_busy($s1_dom); ok($s1_dom->at('sort-name')->text eq 'Prince'); sleep(1); my $s2_dom = $ws->search(artist => { artist => 'Ryan Adams', type => 'person', fmt => 'xml' }); exit_if_mb_busy($s2_dom); ok($s2_dom->at('country')->text eq 'US'); done_testing(); WebService-MusicBrainz-1.0.4/t/Label.t000444000765000024 105113241723022 20403 0ustar00robertfaiststaff000000000000use strict; use Test::More; use WebService::MusicBrainz; sub exit_if_mb_busy { my $res = shift; if(exists $res->{error} && $res->{error} =~ m/^The MusicBrainz web server is currently busy/) { done_testing(); exit(0); } } my $ws = WebService::MusicBrainz->new(); ok($ws); # JSON TESTS my $s1_res = $ws->search(label => { label => 'original', country => 'US' }); exit_if_mb_busy($s1_res); ok($s1_res->{count} > 5); sleep(1); foreach my $label (@{ $s1_res->{labels} }) { ok($label->{name} =~ m/original/i); } done_testing(); WebService-MusicBrainz-1.0.4/t/Recording.t000444000765000024 150513241723022 21304 0ustar00robertfaiststaff000000000000use strict; use Test::More; use WebService::MusicBrainz; sub exit_if_mb_busy { my $res = shift; if(exists $res->{error} && $res->{error} =~ m/^The MusicBrainz web server is currently busy/) { done_testing(); exit(0); } } my $ws = WebService::MusicBrainz->new(); ok($ws); # JSON TESTS my $s1_res = $ws->search(recording => { artist => 'Taylor Swift', release => '1989' }); exit_if_mb_busy($s1_res); ok($s1_res->{count} > 70); sleep(1); my $s2_res = $ws->search(recording => { mbid => '1d43314e-1d7a-4aef-942e-799370be2b15' }); exit_if_mb_busy($s2_res); ok($s2_res->{length} == 233000); sleep(1); my $s3_res = $ws->search(recording => { mbid => '1d43314e-1d7a-4aef-942e-799370be2b15', inc => 'artists' }); exit_if_mb_busy($s3_res); ok($s3_res->{'artist-credit'}->[0]->{name} eq 'Taylor Swift'); done_testing(); WebService-MusicBrainz-1.0.4/t/Release.t000444000765000024 271113241723022 20750 0ustar00robertfaiststaff000000000000use strict; use Test::More; use WebService::MusicBrainz; sub exit_if_mb_busy { my $res = shift; if(exists $res->{error} && $res->{error} =~ m/^The MusicBrainz web server is currently busy/) { done_testing(); exit(0); } } my $ws = WebService::MusicBrainz->new(); ok($ws); my $s1_res = $ws->search(release => { mbid => '2139a963-42d2-4f3d-be3f-8e0177640c75' }); exit_if_mb_busy($s1_res); ok($s1_res->{title} eq 'Love Is Hell'); ok($s1_res->{quality} eq 'normal'); ok($s1_res->{date} eq '2004-05-03'); ok($s1_res->{country} eq 'US'); sleep(1); my $s2_res = $ws->search(release => { mbid => '2139a963-42d2-4f3d-be3f-8e0177640c75', inc => 'artists' }); exit_if_mb_busy($s2_res); ok(defined($s2_res->{'artist-credit'})); ok(defined($s2_res->{'artist-credit'}->[0]->{artist})); ok($s2_res->{'artist-credit'}->[0]->{artist}->{'sort-name'} eq 'Adams, Ryan'); sleep(1); my $s3_res = $ws->search(release => { mbid => '2139a963-42d2-4f3d-be3f-8e0177640c75', inc => 'url-rels' }); exit_if_mb_busy($s3_res); ok(defined($s3_res->{relations})); ok($s3_res->{relations}->[0]->{type} eq 'amazon asin'); ok($s3_res->{relations}->[0]->{direction} eq 'forward'); sleep(1); my $s4_res = $ws->search(release => { release => 'Love Is Hell', country => 'US', status => 'official' }); exit_if_mb_busy($s4_res); ok($s4_res->{count} > 5); for my $rel (@{ $s4_res->{releases} }) { ok($rel->{status} eq 'Official'); ok($rel->{country} eq 'US'); sleep(1) } done_testing();