Thanks for the info, I hadn’t realised that.
(This reply is more for my own notes and in case someone else is trying to do something similar, no need to answer!)
This gives me a new challenge, which is to figure out which of the query results is the “canonical” recording that I want to then do a query with the “inc”. My original query gives me 100+ recordings (some of which are marked as compilations, some of which are compilations that aren’t marked with “secondarytype”, and some are remixes). I’ve modified the query to exclude remixes and compilations, and only include releases in UK, Europe and Worldwide.
http://musicbrainz.org/ws/2/recording/?query=%22Right%20Here%20Right%20Now%22%20AND%20artistname:%22Fatboy%20Slim%22%20%20AND%20(NOT%20recording:%22remix%22)%20AND%20(country:GB%20OR%20country:XE%20OR%20country:XW)%20AND%20(NOT%20secondarytype:Compilation)&fmt=json&limit=100
This gets me down to 16 results, which is an improvement. I then figured the best way to get the “canonical” version is to find the one with the earliest release date, which I do with the following jq:
( [ try ( ( if (."first-release-date" | length == 4) then ."first-release-date" + "-01-01" elif (."first-release-date" | length == 7) then ."first-release-date" + "-01" else ."first-release-date" end ) | strptime("%Y-%m-%d") | mktime ) catch 2524608000 ] | min ) as $first | .recordings[] | select( ."first-release-date" <= ($first | strftime("%Y-%m-%d") ) ) | { "recordingid": .id, "releasedate" : ."first-release-date", "title": .title, "artist": ."artist-credit"[0].name }
The first section up to as $first safely converts the first-release-date to a timestamp, bearing in mind that the date could be expressed in MusicBrainz as “2026-07-31”, or “2026-07”, or “2026”; the try-catch is an extra safety so that if the date is in an unexpected format it defaults to 2524608000 (“2050-01-01”). It then finds the lowest timestamp and stores it in $first.
The second part selects the recording(s) with the earliest dates by converting the timestamp back to date and comparing it to the first-release-date, and then pulls out the relevant keys that I can use for a follow-up query using inc=work-rels.
This may be a crazy way to do things but I’m learning about the API and jq as I go; I’ll probably end up wrapping this in a bash script. I’d probably be able to do all of this a lot more easily in psql but I’m not ready to download the entire schema!