Skip to content

Commit

Permalink
Merge branch 'nguillaumin-discid-query'
Browse files Browse the repository at this point in the history
  • Loading branch information
bfaist committed Jan 9, 2018
2 parents 9d16fbb + 4f44f46 commit 1194285
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pm_to_blib
*.bak
*.old
*.skip
Makefile
2 changes: 1 addition & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ my $build = Module::Build->new
},
create_makefile_pl => 'traditional',
dist_author => 'Bob Faist <[email protected]>',
dist_version => '1.0.1',
dist_version => '1.0.3',
meta_merge => {
resources => {
repository => 'git://github.com/bfaist/webservice-musicbrainz.git'
Expand Down
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ Revision history for Perl extension WebService::MusicBrainz.
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)
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"provides" : {
"WebService::MusicBrainz" : {
"file" : "lib/WebService/MusicBrainz.pm",
"version" : "v1.0.1"
"version" : "v1.0.2"
},
"WebService::MusicBrainz::Request" : {
"file" : "lib/WebService/MusicBrainz/Request.pm",
Expand All @@ -49,6 +49,6 @@
"url" : "git://github.com/bfaist/webservice-musicbrainz.git"
}
},
"version" : "v1.0.1",
"version" : "v1.0.2",
"x_serialization_backend" : "JSON::PP version 2.27400"
}
4 changes: 2 additions & 2 deletions META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ name: WebService-MusicBrainz
provides:
WebService::MusicBrainz:
file: lib/WebService/MusicBrainz.pm
version: v1.0.1
version: v1.0.2
WebService::MusicBrainz::Request:
file: lib/WebService/MusicBrainz/Request.pm
version: '1.0'
Expand All @@ -28,5 +28,5 @@ requires:
resources:
license: http://dev.perl.org/licenses/
repository: git://github.com/bfaist/webservice-musicbrainz.git
version: v1.0.1
version: v1.0.2
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
4 changes: 2 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ require 5.010001;
use ExtUtils::MakeMaker;
WriteMakefile
(
'NAME' => 'WebService::MusicBrainz',
'PREREQ_PM' => {
'Mojolicious' => '7.13'
},
'PL_FILES' => {},
'INSTALLDIRS' => 'site',
'PL_FILES' => {},
'EXE_FILES' => [],
'NAME' => 'WebService::MusicBrainz',
'VERSION_FROM' => 'lib/WebService/MusicBrainz.pm'
)
;
15 changes: 12 additions & 3 deletions lib/WebService/MusicBrainz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use Mojo::Base -base;
use WebService::MusicBrainz::Request;
use Data::Dumper;

our $VERSION = '1.0.1';
our $VERSION = '1.0.3';

has 'request';
has valid_resources => sub { ['area','artist','label','recording','release','release_group'] };
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;
Expand All @@ -19,6 +19,7 @@ has subquery_map => sub {
my %subquery_map;

$subquery_map{artist} = ['recordings','releases','release-groups','works'];
$subquery_map{discid} = ['artists','artist-credits','collections','labels','recordings','release-groups' ];
$subquery_map{label} = ['releases'];
$subquery_map{recording} = ['artists','releases'];
$subquery_map{release} = ['artists','collections','labels','recordings','release-groups' ];
Expand All @@ -32,6 +33,7 @@ has search_fields_by_resource => sub {

$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'];
Expand Down Expand Up @@ -84,8 +86,15 @@ sub search {
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};
}

# only use "inc" parameters when a specific MBID is given
# only use "inc" parameters when a specific MBID or DISCID is given
if ($self->request()->mbid() or $self->request()->discid()) {
if(exists $search_query->{inc}) {
my @inc_subqueries;

Expand Down
2 changes: 2 additions & 0 deletions lib/WebService/MusicBrainz/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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;
Expand All @@ -27,6 +28,7 @@ sub make_url {
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;

Expand Down
13 changes: 12 additions & 1 deletion t/Area.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@ use strict;
use Test::More;

use WebService::MusicBrainz;
use Data::Dumper;

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);
Expand All @@ -30,6 +40,7 @@ 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);
Expand Down
22 changes: 21 additions & 1 deletion t/Artist.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ use strict;
use Test::More;

use WebService::MusicBrainz;
use Data::Dumper;

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');
Expand All @@ -17,52 +26,63 @@ 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);

my $s4_res = $ws->search(artist => { mbid => '070d193a-845c-479f-980e-bef15710653e', inc => 'nothing-here' });
exit_if_mb_busy($s4_res);
ok(exists $s4_res->{error});
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();
41 changes: 41 additions & 0 deletions t/DiscID.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use strict;
use Test::More;

use WebService::MusicBrainz;
use Data::Dumper;

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

my $s1_res = $ws->search(discid => { discid => 'NmFqfPXBZfk05ZpbTcL.IvmEtQY-' });
ok($s1_res->{'offset-count'} eq 16);
ok(@{$s1_res->{offsets}} eq 16);
ok($s1_res->{offsets}->[0] eq 150);
ok($s1_res->{offsets}->[1] eq 20822);
ok($s1_res->{offsets}->[2] eq 39976);
ok($s1_res->{offsets}->[3] eq 57651);
ok($s1_res->{offsets}->[4] eq 82691);
ok($s1_res->{offsets}->[5] eq 97773);
ok($s1_res->{offsets}->[6] eq 116625);
ok($s1_res->{offsets}->[7] eq 140670);
ok($s1_res->{offsets}->[8] eq 160155);
ok($s1_res->{offsets}->[9] eq 183516);
ok($s1_res->{offsets}->[10] eq 194429);
ok($s1_res->{offsets}->[11] eq 210901);
ok($s1_res->{offsets}->[12] eq 228250);
ok($s1_res->{offsets}->[13] eq 246216);
ok($s1_res->{offsets}->[14] eq 272031);
ok($s1_res->{offsets}->[15] eq 285133);
ok($s1_res->{id} eq 'NmFqfPXBZfk05ZpbTcL.IvmEtQY-');
ok($s1_res->{sectors} eq 308410);
ok(@{$s1_res->{releases}} > 0);
ok(not defined @{$s1_res->{releases}}[0]->{'artist-credit'});
sleep(1);

my $s2_res = $ws->search(discid => { discid => 'NmFqfPXBZfk05ZpbTcL.IvmEtQY-', inc => ' artists' });
ok(@{$s2_res->{releases}} > 0);
ok(defined @{$s2_res->{releases}}[0]->{'artist-credit'});
ok(defined @{$s2_res->{releases}}[0]->{'artist-credit'}->[0]->{artist});
ok(@{$s2_res->{releases}}[0]->{'artist-credit'}->[0]->{artist}->{'sort-name'} eq 'Adams, Ryan');

done_testing();
10 changes: 9 additions & 1 deletion t/Label.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ use strict;
use Test::More;

use WebService::MusicBrainz;
use Data::Dumper;

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);

Expand Down
12 changes: 11 additions & 1 deletion t/Recording.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ use strict;
use Test::More;

use WebService::MusicBrainz;
use Data::Dumper;

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();
Loading

0 comments on commit 1194285

Please sign in to comment.