Best way to get cover art from artist/track (minimal number of requests, lowest impact on database,...)

Hi !

I’m new and kinda noobs on using MB. I’m trying (for fun and personal interest) to write a small webpage to listen to a webradio and have covert art. I can only have the name of the artist and the name of the song and I’d like to have a picture.
Let’s say I have “Deep Purple” and “Child In Time” tags and I want the front cover art of “In rock”.

I understand that I need to make a first resquest like /ws/2/artist?query=artist:“deep purple” in order to get the arid of Deep Purple (first answer probably) and then a second request to get the albums : one like /ws/2/recording?query=something and if I find something interesting, take the album_id and make a final request to coverartarchive.org. Am I correct ?

Is using the arid the best choice or would it be better to put the artist name in the recording request ?

As far as I understand things with my interactive tests on the website, if I use the latter, I get albums by all artists that played a song of Deep Purple and then much more answers.

It seems to me that I would have greater chance to get the best answer in the first place if I would filter with status(:Official) and type(only Album and no other type like Compilation, EP, Live, Single, etc. ) .

How would you write those requests to make them the most efficient ?

Thanks for reading me and thanks for your help,
Best regards,

David

https://beta.musicbrainz.org/ws/2/recording?query='child%20in%20time'%20AND%20arid:79491354-3d83-40e3-9d8e-7592d58d790a

In this request, how can I say “AND NOT secondary-type:Compilation” ?

Thanks for your reply or a link to a similar subject

I’m far from an expert using the search API, but

I guess using the artist name would avoid one query. You have more risks of selecting an homonym but artist+title will probably be unique. Not sure why you get cover results with other artists than Deep Purple.

The keyword is “secondarytype” (Indexed Search Syntax - MusicBrainz)

So your query should look like:
https://beta.musicbrainz.org/ws/2/recording?query=artist%3A"Deep+Purple"+AND+recording%3A"Child+In+Time"+AND+NOT+secondarytype%3A"compilation"&limit=2&method=advanced&fmt=json
followed probably by a filter on score and release year

In javascript a basic version would probably look like

fetch(
'/ws/2/recording?query=artist%3A%22Deep+Purple%22+AND+recording%3A%22Child+In+Time%22+AND+NOT+secondarytype%3A%22compilation%22&limit=2&method=advanced&fmt=json'
).then(
    resp => resp.json()
).then(
    json => console.log(
        json.recordings.filter(
            rec => rec.score > 90
        ).map(
            rec => rec.releases[0].id
        )
    )
)

Then your second query on CAA should follow Cover Art Archive / API - MusicBrainz

2 Likes

Thank you very much !
I guess my mistakes were that I forgot method=advanced and I mistyped secondarytype with a ‘-’ which led to these filters to be ignored.
I’m going to try this tonight, thanks again !

That part is probably not necessary