Return random song from specified year and specified area (country)

Hi everyone

I’m a little new to working with API’s and I’m just getting my head around how relationships work. I’m trying to work how out to write the correct URL for it to return a random song from a specific range of years from a specific country.

This is where I am so far:
http://musicbrainz.org/ws/2/release?area=f45b47f8-5796-386e-b172-6c31b009a5d8&offset=12&limit=2

This returns 2 releases from Brazil (from any year) in what appears to be alphabetical order.

I’ve managed to get almost what I need using the advanced query syntax, like this:

https://musicbrainz.org/search?query=date%3A[1964+TO+1978]+AND+country%3Abr&type=release&limit=25&method=advanced

This will list all of the releases between 1964 and 1978 from Brazil. I’m struggling to work out how to achieve the same results with the API url. I don’t mind using my own code to pick a random release if there isn’t a way to do it using the API.

I was wondering if anyone would be able to guide me in the right direction and I can try and figure out the rest on my own - would appreciate the help!

Thanks

There’s search API documentation here: https://musicbrainz.org/doc/MusicBrainz_API/Search
Seems like this query will return more or less the same results as the site search: https://musicbrainz.org/ws/2/release?query=date:[1964+TO+1978]+AND+country:br&limit=25

3 Likes

Ah that looks about right. I did notice something a bit odd though. I removed the limit=25 so it returns all results, but it doesn’t seem to include this release by Milton Nascimento:

I’ve noticed it with a few others, but this one is just an example. It should meet the criteria, MusicBrainz has it down as being from country ‘br’ and release year ‘1972’, I’m not sure why the API get wouldn’t include it.

Any obvious reason why it would omit releases that should match the criteria?

EDIT: I noticed this doesn’t seem to be anything to do with the API, as the search results page also doesn’t include this album. If I specify for it to also search for the word ‘clube’ (the first word of the album name) it does include it. For example:
https://musicbrainz.org/ws/2/release?query=date:[1964+TO+1978]+AND+country:br+AND+clube
No idea why it doesn’t show it in the database unless you specify part of the release name

Note that there is still a limit, 25 is the default, 100 is the maximum. If you want more results you need to do additional requests with the offset parameter.

4 Likes

Got it! This is making more sense now - thanks for your help. So if I wanted to work out how many times I’d need to make additional requests to offset then would I look at the release-list count. So in this example it says its 1319, so I would need to do around 13 requests to get all of the data?

2 Likes

Yes, with 14 requests you should get 13×100+19 releases.
There is some rate limiting.

2 Likes