]>
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';
66 my $parsed = decode_json
(shift);
67 my $release = release_metadata
($parsed);
68 # TODO this is dumb. put it into release_metadata
69 # TODO only include "format": "CD" (i.e. exclude "format": "DVD-Video")
70 $release->{discs
} = [map { tracks
($_->{tracks
}) } @{$parsed->{media
}}];
74 sub release_metadata
{
76 my $date = $_->{date
} // 'UNKNOWN';
77 my $events = $_->{'release-events'};
78 if (defined($events)) {
80 warn('found example of multiple release events!');
82 my $event_date = $events->[0]->{date
};
83 if (defined($event_date)) {
84 if ($event_date ne $date) {
85 warn("release-events has date $event_date (vs. $date)");
89 my ($discs, $tracks) = (0, 0);
90 for my $m (@{$_->{media
} // []}) {
91 $discs += $m->{'disc-count'} // 0;
92 $tracks += $m->{'track-count'} // 0;
94 if ($tracks == 0 && defined($_->{'disc-count'})) {
95 $tracks = $_->{'disc-count'};
97 if (defined($_->{'disc-count'})) {
98 warn('disc count defined at release root!');
101 my $artcred = $_->{'artist-credit'};
102 if (defined($artcred)) {
103 $artist = join('', map {
104 # warn('HEYEPG! ', join(', ', keys(%$_)));
105 # warn("HEYEPG ", $_->{name}, 'join=', ($_->{joinphrase} // ''));
106 $_->{name
}, ($_->{joinphrase
} // '') } @$artcred);
112 artist
=> $artist // 'UNKNOWN',
113 title
=> $_->{title
},
116 country
=> $_->{country
} // '--',
118 labels
=> join(', ', map { $_->{label
}->{name
} // 'UNKNOWN' } @{$_->{'label-info'} // []}),
119 disambiguation
=> $_->{disambiguation
} // '',
120 status
=> $_->{status
},
126 my $parsed = decode_json
(shift);
127 [map { release_metadata
($_) } @{$parsed->{releases
}}]
132 my $releases = shift;
135 sprintf('%s %-10s %3d tracks / %2d discs in %s %s by %s; %s, %s',
136 $_->{id
}, $_->{date
},
137 $_->{tracks
}, $_->{discs
},
138 $_->{country
}, $_->{title
}, $_->{labels
}
139 , $_->{disambiguation
}, $_->{status
},
147 my $hack_parens = $parm{hack_parens
} // 0;
148 my $release = $parm{release
};
149 my $artist = 'ARTIST=' . $release->{artist
};
150 my $album = 'ALBUM=' . $release->{title
};
151 my $date = 'DATE=' . $release->{date
};
152 my $discs = $release->{discs
};
153 my $multi = @$discs > 1;
160 @discnum = ("DISCNUMBER=$d");
164 $artist, $album, $date, @discnum,
172 if (length($version)) {
176 @tags = ("TITLE[$t]=$title", "VERSION[$t]=$version");
178 @tags = ("TITLE[$t]=$title")
181 @tags = ("TITLE[$t]=$_");
191 my $arg = shift || die;
193 my $artist = shift || die;
194 my $title = shift || die;
196 'https://musicbrainz.org/ws/2/release?query='
197 . uri_escape
("artist:\"$artist\" AND \"$title\" AND format:CD");
198 open(my $fh, '-|', 'curl', '--silent', '-Haccept:application/json', $url)
204 say(list_releases
(read_releases
(join('', @body))));
210 } else { $hack_parens = 0 }
211 my $url = "https://musicbrainz.org/ws/2/release/$arg?inc=artist-credits+recordings";
212 open(my $fh, '-|', 'curl', '--silent', '-Haccept:application/json', $url)
215 hack_parens
=> $hack_parens,
216 release
=> read_release
(join('', <$fh>)),
229 # perl-indent-level: 8
230 # indent-tabs-mode: t