Best way to get cover art when only a RecordingID is known

cover-art
release
musicbrainz
recordings
Tags: #<Tag:0x00007f23c6478d58> #<Tag:0x00007f23c6478b78> #<Tag:0x00007f23c6478970> #<Tag:0x00007f23c6478650>

#1

I’m writing this app in javascript, and I need a function which can return the front cover art when all I have is a Recording_ID (rid) value. I can get the releaseID from that, and the cover-art from the releaseID - unless there’s a better way?

So I figured I could do it with a json post call, but I think I’m missing the syntax for adding authentication to the Get call.

Can anyone show me some example javascript which works with authentication to make a musicbrainz query like this, (for example) and returns the result in json format?

http://musicbrainz.org/ws/2/recording/?query=rid:e9f558ad-ac69-4762-9eb6-ed5093038bb6?inc=releases&fmt=json

Thanks in advance.


#2

If you have the ID already you can query the recording directly:

http://musicbrainz.org/ws/2/recording/e9f558ad-ac69-4762-9eb6-ed5093038bb6?inc=releases&fmt=json


#3

You are likely being blocked by rate limiting as you have not set a user agent string.
https://wiki.musicbrainz.org/XML_Web_Service/Rate_Limiting#Provide_meaningful_User-Agent_strings
I have no idea how to change this in java script.

A recording can exist on multiple releases.
Not all releases have cover art and you will need to work out what release is the best for your needs.
You may want to find singles/ep’s then the album and avoid using cover art from a random compilation.


#4

Thanks for your replies guys. I need to clarify my question: Following is the key lines of javascript I’m trying to use to send a POST request in json format to musicbrainz:

var rUrl=“http://musicbrainz.org/ws/2/recording/”;
var inc="?inc=releases"
var fMt = "&fmt=json"
var relID = ""
var urlCall = rUrl + Rid + inc + fMt
$.post(urlCall, function(results) {
relID = results.recordings[0].releases[0].id;
});

The set of variables above sends a post in this format to MB:
http://musicbrainz.org/ws/2/recording/38639372-ec86-4307-aefa-1701a43cc933?inc=releases&fmt=json

… and that works fine in my browser.

However, I’m given a 401 unauthorised error in the console when running it from js, presumably because I’m not authorising it correctly. I think I should be specifying the user-agent somehow but I just don’t know how in js, and can’t find any examples online.

Can anyone can show me how to add the user-agent info, and authorise my MB request in a javascript call?

Thanks


#5

There is no authorization involved here, you simply need to use a GET, not a POST :wink: