-
Notifications
You must be signed in to change notification settings - Fork 5
/
mb-artist-release
61 lines (46 loc) · 1.63 KB
/
mb-artist-release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper::Compact qw(ddc);
use Net::CoverArtArchive;
use WebService::MusicBrainz;
#$ENV{MUSICBRAINZ_DEBUG} = 1;
my $who = shift || 'david bowie'; # artist
my $what = shift || '';#'Diamond Dogs'; # release
my $image;
my $caa = Net::CoverArtArchive->new;
my $mb = WebService::MusicBrainz->new;
# XXX No:
#my $result = $mb->search('release-group' => { artist => $who });
#for my $r ($result->{'release-groups'}->@*) {
# printf "%s - %s\n", $r->{title}, $r->{'secondary-types'};#unless $r->{'secondary-types'};
#}
my $result = $mb->search(artist => { artist => $who });
my $artist_id = $result->{artists}[0]{id};
my $key = 'release-groups';
$result = $mb->search(artist => { mbid => $artist_id, inc => [$key]});
#warn ddc($result, {max_width=>128});exit;
print "$who ($artist_id):\n";
my $i = 0;
for my $group ($result->{$key}->@*) {
my $condition = $what
? $group->{title} eq $what
: !$group->{'secondary-types'}->@*; # studio albums only
if ($condition) {
$i++;
print "$i. $group->{title} ($group->{id}):\n";
$key = 'releases';
$result = $mb->search('release-group' => { mbid => $group->{id}, inc => [$key]});
#warn ddc($result, {max_width=>128});
for my $release ($result->{$key}->@*) {
my $release_id = $release->{id};
my $artwork = $caa->find_available_artwork($release_id);
#warn ddc($artwork, {max_width=>128});
if ($artwork->[0]{image}) {
print "\t", $artwork->[0]{image}, "\n";
last;
}
}
last if $what;
}
}