I'm trying to retrieve release info from the MusicBrainz database using a PHP script on my server. I have a list of songs, with song title and artist name, and I'm trying to retrieve the date of the first release of that song, along with other info about that release.
I realise that the search won't always be 100% accurate, but the list consists of fairly rare and unique songs so it should at least get me on a good track.
I've gotten pretty far with my script, it returns results and everything, but I'm unsure about how to write the query exactly. The documentation is quite confusing and doesn't feature an example where you search for both song title and artist.
This is my code:
// this info is normally fetched from my DB, but just as a simple example (as it is returned):
$artist = "ZZTop";
$song_title = "It's only Love";
// I'm having trouble with this part:
$mb_query = 'http://www.musicbrainz.org/ws/2/recording?query=' . $song_title .' ANDartist:' . $artist ;
$xml = simplexml_load_file($mb_query);
$releasedate = $xml->{'recording-list'}->recording[0]->{'release-list'}->release[0]->date;
At first I've tried to rawurlencode()
the $artist
and $song_title
, but funnily enough, that didn't return any results, so I figured I'd just leave it as a plain string. The query returns results, but they are really off and I have the feeling only part of the query is getting picked up (for instance only the song title and not the artist).
Does anyone know the right way to do this?