]>
diplodocus.org Git - flac-archive/blob - fa-mb
5 B<fa-mb> - Query MusicBrainz
9 B<fa-mb> B<-Q> B<ARTIST> B<TITLE>
10 B<fa-mb> [B<-p>] B<RELEASE-ID>
14 The first form queries for releases by B<ARTIST> and B<TITLE>, listing a
15 summary, one per line. The first column is the id, which is used as the
16 B<RELEASE-ID> argument to the second form.
18 The second form looks up a release by B<RELEASE-ID>, listing all the tags for
19 each disc in the release in the form expected by B<fa-rip>.
21 The second form accepts a B<-p> option which enables the PAREN HACK, which is
22 quite gross. I like to put information such as "(live)" in the VERSION tag
23 rather than TITLE tag. This information comes out of MusicBrainz parenthesized
24 at the end of the track title, so this just strips out any parenthesized parts.
25 Frequently it is incorrect: pay attention!
27 The tags listing also hacks various Unicode characters that work just fine with
28 their ASCII equivalents, e.g. quotation marks.
32 package epg
::flac
::archive
::mb
;
38 use Exporter
'import';
56 # TODO need to apply these everywhere! also seen in ARTIST and ALBUM
67 my $parsed = decode_json
(shift);
68 my $release = release_metadata
($parsed);
69 # TODO this is dumb. put it into release_metadata
70 # TODO only include "format": "CD" (i.e. exclude "format": "DVD-Video")
71 $release->{discs
} = [map { tracks
($_->{tracks
}) } @{$parsed->{media
}}];
75 sub release_metadata
{
77 my $date = $_->{date
} // 'UNKNOWN';
78 my $events = $_->{'release-events'};
79 if (defined($events)) {
81 # TODO e.g. https://musicbrainz.org/release/d9bfd2d6-2bab-4fd8-9b5d-84d2a7d1457b
82 # Some Great Reward has two release events: 0. Europe; 1. Germany
84 warn('found example of multiple release events! ' . $_->{id
} . ' ' . Dumper
($events))
86 my $event_date = $events->[0]->{date
};
87 if (defined($event_date)) {
88 if ($event_date ne $date) {
89 warn("release-events has date $event_date (vs. $date)");
93 my ($discs, $tracks) = (0, 0);
94 for my $m (@{$_->{media
} // []}) {
95 $discs += $m->{'disc-count'} // 0;
96 $tracks += $m->{'track-count'} // 0;
98 if ($tracks == 0 && defined($_->{'disc-count'})) {
99 $tracks = $_->{'disc-count'};
101 if (defined($_->{'disc-count'})) {
102 warn('disc count defined at release root!');
105 my $artcred = $_->{'artist-credit'};
106 if (defined($artcred)) {
107 $artist = join('', map {
108 # warn('HEYEPG! ', join(', ', keys(%$_)));
109 # warn("HEYEPG ", $_->{name}, 'join=', ($_->{joinphrase} // ''));
110 $_->{name
}, ($_->{joinphrase
} // '') } @$artcred);
116 artist
=> $artist // 'UNKNOWN',
117 title
=> $_->{title
},
120 country
=> $_->{country
} // '--',
122 labels
=> join(', ', map { $_->{label
}->{name
} // 'UNKNOWN' } @{$_->{'label-info'} // []}),
123 disambiguation
=> $_->{disambiguation
} // '',
124 status
=> $_->{status
} // '',
130 my $parsed = decode_json
(shift);
131 [map { release_metadata
($_) } @{$parsed->{releases
}}]
136 my $releases = shift;
139 sprintf('%s %-10s %3d tracks / %2d discs in %s %s by %s; %s, %s',
140 $_->{id
}, $_->{date
},
141 $_->{tracks
}, $_->{discs
},
142 $_->{country
}, $_->{title
}, $_->{labels
},
143 $_->{disambiguation
}, $_->{status
},
151 my $hack_parens = $parm{hack_parens
} // 0;
152 my $release = $parm{release
};
153 my $artist = 'ARTIST=' . $release->{artist
};
154 my $album = 'ALBUM=' . $release->{title
};
155 my $date = 'DATE=' . $release->{date
};
156 my $discs = $release->{discs
};
157 my $multi = @$discs > 1;
164 @discnum = ("DISCNUMBER=$d");
168 $artist, $album, $date, @discnum,
176 if (length($version)) {
180 @tags = ("TITLE[$t]=$title", "VERSION[$t]=$version");
182 @tags = ("TITLE[$t]=$title")
185 @tags = ("TITLE[$t]=$_");
195 my $arg = shift || die;
197 my $artist = shift || die;
198 my $title = shift || die;
200 'https://musicbrainz.org/ws/2/release?query='
201 . uri_escape
("artist:\"$artist\" AND \"$title\" AND format:CD");
202 open(my $fh, '-|', 'curl', '--silent', '-Haccept:application/json', $url)
208 say(list_releases
(read_releases
(join('', @body))));
214 } else { $hack_parens = 0 }
215 my $url = "https://musicbrainz.org/ws/2/release/$arg?inc=artist-credits+recordings";
216 open(my $fh, '-|', 'curl', '--silent', '-Haccept:application/json', $url)
219 hack_parens
=> $hack_parens,
220 release
=> read_release
(join('', <$fh>)),
233 # perl-indent-level: 8
234 # indent-tabs-mode: t