4

Is there any way of getting a list of albums for an artist (band), along with a link to album art and runtime?

I've been given this endpoint, but the data it returns is confusing: http://musicbrainz.org/ws/2/recording?query=artist:%22Queen%22%20and%20type:album&fmt=json

The data isn't really organized around albums, and the "length" data returns something like 203000. But it's better if you see it in context, so here's the first bit of it (sorry I couldn't get it indented):

{
"created": "2018-02-17T03:47:57.052Z",
"count": 9533710,
"offset": 0,
"recordings": [
{
"id": "c2e919f7-ecb9-4fdf-9162-3c26d0127fa0",
"score": "100",
"title": "Son and Daughter",
"length": 203000,
"video": null,
"artist-credit": [
{
"artist": {
"id": "0383dadf-2a4e-4d10-a46a-e9e041da8eb3",
"name": "Queen",
"sort-name": "Queen",
"disambiguation": "UK rock group",
"aliases": [
{
"sort-name": "Queen + Adam Lambert",
"name": "Queen + Adam Lambert",
"locale": null,
"type": null,
"primary": null,
"begin-date": "2011",
"end-date": null
}
]
}
}
],
"releases": [
{
"id": "bb19abaf-80b3-4a3e-846d-5f12b12af827",
"title": "Queen",
"status": "Official",
"release-group": {
"id": "810068af-2b3c-3e9c-b2ab-68a3f3e3787d",
"primary-type": "Album"
},
"date": "1994",
"country": "NL",
"release-events": [
{
"date": "1994",
"area": {
"id": "ef1b7cc0-cd26-36f4-8ea0-04d9623786c7",
"name": "Netherlands",
"sort-name": "Netherlands",
"iso-3166-1-codes": [
"NL"
]
}
}
],
"track-count": 10,
"media": [
{
"position": 1,
"format": "CD",
"track": [
{
"id": "3a26455e-2660-30dc-a652-6a2b40f1fbe5",
"number": "8",
"title": "Son and Daughter",
"length": 203400
}
],
"track-count": 10,
"track-offset": 7
}
]
},
{
"id": "1783da6a-9315-3602-a488-1738eb733a0f",
"title": "Queen",
"status": "Official",
"release-group": {
"id": "810068af-2b3c-3e9c-b2ab-68a3f3e3787d",
"primary-type": "Album"
},
"date": "1973-09-04",
"country": "US",
"release-events": [
{
"date": "1973-09-04",
"area": {
"id": "489ce91b-6658-3307-9877-795b68554c98",
"name": "United States",
"sort-name": "United States",
"iso-3166-1-codes": [
"US"
]
}
}
],

If someone can explain this data to me, then I don't need another endpoint. But I've been hunting around the musicbrainz docs and they're not super helpful.

Preferably it would be with one call, but I can do successive calls if necessary.

Thanks for your help.

NotoriousWebmaster
  • 3,298
  • 7
  • 37
  • 49
  • The MusicBrainz documentation can be found here: https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2 The albums you want are called "releases" (instead of using the recordigs end point). – JonnyJD Feb 18 '18 at 17:56
  • You wouldn't believe how many musicbrainz tabs I have open right now. Yes, I've looked at the docs, and now I'm turning to SO for some help. Thanks for the "releases" info. – NotoriousWebmaster Feb 18 '18 at 18:01
  • Not sure what you have been hunting but you can use http://musicbrainz.org/ws/2/release?query=artist:%22Queen%22%20and%20type:album&fmt=json to get the guids for the releases and then for every release: http://musicbrainz.org/ws/2/release/f0b24d7d-1e21-401d-9345-4b6c20ffc1ef?fmt=json&inc=recordings I don't know why the inc 'recordings' doesn't work for the "browse request". That might have changed at some time. You might also want to use a library like the ones listed at the MusicBrainz documentation. You can usually find devs on IRC: https://metabrainz.org/contact – JonnyJD Feb 19 '18 at 09:02

2 Answers2

9

First off:

Is there any way of getting a list of albums for an artist (band), along with a link to album art and runtime?

Yes, definitely.

First you will want to find the artist, say, the Queen that did Bohemian Rhapsody. They're identified with MusicBrainz Artist ID "0383dadf-2a4e-4d10-a46a-e9e041da8eb3", so you can do a browse request for Releases by this artist: https://musicbrainz.org/ws/2/release/?artist=0383dadf-2a4e-4d10-a46a-e9e041da8eb3&inc=recordings&fmt=json (note the inc=recordings)

This gives you most of what you are asking for. A list of releases and their runtime—kind of. Each Release should have one or more medium properties that in turn have a track-list with a number of tracks. The sum of the length of each of these tracks is what makes up the runtime (the length is given in milliseconds).

For cover art, you may notice that the output has a cover-art-archive property. For cover art, MusicBrainz uses Cover Art Archive which uses MusicBrainz IDs as identifiers. The cover-art-archive attribute states whether any cover art exists in Cover Art Archive and a few details about this—e.g., does CAA have any images at all (artwork)? Does it have a back image (back) and/or a front image (front)? How many images are there in all for the release (count)? If the cover-art-archiveartwork is true, we can go on and fetch cover art from the CAA. The CAA's API is really simple: to get the "front" image of a release, say the 1974 UK single "Killer Queen" that has MusicBrainz Release ID "a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc", you can simply do https://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc/front You can also do https://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc to get a JSON document with more details about what cover art images are available (e.g., this one has two images: one Front+Medium and one Back+Medium image).

The Cover Art Archive API is documented at https://musicbrainz.org/doc/Cover_Art_Archive/API and the MusicBrainz API/web service documentation can be found at https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2

Note that using browse requests you can page through the results using offset and vary the amount of results per query using limit, see the "Paging" section under the browse request section in the MusicBrainz WS documentation.


Secondly: Though you don't ask about this directly, you're using a search query using a generic term in your question, so I thought I'd talk about this for a bit. In MusicBrainz everything is identified using MusicBrainz identifiers (IDs). (I kind of mentioned them in the first section too.)

The reason for this is that many, many names are not unique. There are as of this writing three unique artists known as "Queen" in MusicBrainz: https://musicbrainz.org/search?query=%22queen%22&type=artist&method=advanced – not counting any of the 321 other artists that have "queen" as part of their name. Without more information, it is not possible for MusicBrainz to know which of them you want to find out information from, so your first step will likely be to somehow either narrow the search (e.g., add type:group narrows the search to 123 results, using country:gb limits to 21 results, doing both gives 11 results (see the search syntax documentation for more details)) or somehow filter afterwards.

Once you've narrowed it down to the specific artist you want, you can continue with the steps outlined above to get the details you want. The steps for narrowing it down will depend on your specific application/use case.


Finally: You seem to have some missing understanding at the asbstract level about how MusicBrainz's data is structured. E.g., all of the above is assuming that by album you mean a specific released version like the 1974 UK "Killer Queen" single, and not a more generic concept of a release like any version of the "Killer Queen" single, which in MusicBrainz terminology would be a Release Group.

https://musicbrainz.org/doc/MusicBrainz_Entity is a list of entities used in MusicBrainz. Understanding the differences between a Release Group and a Release as well as between Tracks and Recordings (and Works) will put you in a much better position to effectively use the web service and the MusicBrainz data in general.

https://musicbrainz.org/doc/MusicBrainz_Database/Schema is a introduction to how MusicBrainz is structured. Knowing how artist credits, ("advanced") relationships, and mediums play into things is also likely to save you a lot of headache later.

Freso
  • 149
  • 1
  • 7
  • Thanks @Freso. The CAA link was valuable. The result set for the first link you provided says there are 885 releases, but only provide 25 in the data. How do you access the rest? I'm guessing it's successive calls, with some additional parameter, indicating which "page", but I haven't been able to find examples of it in the docs. – NotoriousWebmaster Feb 20 '18 at 01:24
  • 2
    @NotoriousWebmaster Yeah, my original version has "browse requests" be a link to https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#Browse which has a "paging" section where this is described. Basically, `offset=X` allows you to "skip" X results and `limit=X` allows you to set the amount of results returned per query (with a max. of 100). So if you do `&limit=100&offset=0`, `&limit=100&offset=100`, `&limit=100&offset=200`, … it should be what you're looking for. Added a comment about this in the answer too. – Freso Feb 20 '18 at 09:13
0

You need to understand the format of the data returned, copy the result in to a JSON formatting service such as https://jsonformatter.curiousconcept.com/

You will then realise you have multiple artists in the returned data, which is why it's not as simple as "albums by artist"

I’m guessing the "length" data is in milliseconds.

Tony
  • 9,672
  • 3
  • 47
  • 75
  • Thanks for the response, @Tony. 203,000 seconds is 56.388888 hours. That doesn't seem likely. So the question is, how to get the data ONLY for a single artist, only albums, and the length of each album. But thank you for pointing me to the jsonformatter! – NotoriousWebmaster Feb 18 '18 at 04:57
  • 1
    Yes, seconds would be rather long :) I meant to say milliseconds, so 203,000 would be about three minutes and twenty five seconds – Tony Feb 18 '18 at 14:01