Skip to content

Instantly share code, notes, and snippets.

@bazzaar
Created April 1, 2020 10:41
Show Gist options
  • Save bazzaar/fb30f16b2623164e75b1c52c6360c74e to your computer and use it in GitHub Desktop.
Save bazzaar/fb30f16b2623164e75b1c52c6360c74e to your computer and use it in GitHub Desktop.
get_musicbrainz_release_info_by_specifying_discid
use Cro::HTTP::Client;
use JSON::Fast;
use Pretty::Table;
my $client = Cro::HTTP::Client.new(
headers => [
User-agent => 'HTTP::API::MusicBrainz/0.0.1'
]);
my $discid = 'M3ATxcfK.GATL5ED0AXxljjcva8-'; # obtained from libdiscid calculation
my $url = 'http://musicbrainz.org/ws/2/discid/' ~ $discid ~ '?inc=release-groups+artists+labels&fmt=json';
my $resp = await $client.get($url); # Make the request, get the search result link
my $json = await $resp.body-text; # Pull the data
my %releases-containing-specific-discid = from-json($json); # Parse the JSON
my $table = Pretty::Table.new;
given $table {
.add-column('date' , %releases-containing-specific-discid{'releases'}»{'date'});
.add-column('release-MBID' , %releases-containing-specific-discid{'releases'}»{'id'});
.add-column('title' , %releases-containing-specific-discid{'releases'}»{'title'});
.add-column('barcode' , %releases-containing-specific-discid{'releases'}»{'barcode'});
}
$table.title('Releases containing disc-id : ' ~ $discid);
$table.align(%(:title<l>,:release-MBID<l>));
$table.sort-by('date');
$table.junction-char('*');
put $table;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment