I'm trying to use the Musixmatch TrackSearch NPM function to get the unique TrackID which can then be used on the Track.lyrics endpoint. However, when I pass in certain song titles/artist, the result set doesn't include the correct matches, even if I broaden the search to include many results.
Please see my code below:
const music = require('musicmatch')({ apikey: "MY_API KEY" });
music.trackSearch({ q: "Drake - God's Plan", page: 1, page_size: 3 })
.then(function (data) {
console.log(data.message.body.track_list);
}).catch(function (err) {
console.log(err);
})
This function returns two songs titled 'Empire' by Rick Ross & Drake and one Karaoke version of the song 'God's Plan' but nothing resembling the original version (which is currently #3 on the Billboard Hot 100). I find it hard to believe that 'God's Plan' does not exist in the Musixmatch database so I must be doing something wrong!
The root of your issue is that you're using the
q
search parameter. Per the docs,q
is searching:so if your search is
q: "drake"
you're going to get back any results that include Drake in the Title, Artists, OR Lyrics which is more than what you're looking for.There's a couple of things you can likely do to work around this but at a high level the simplest is probably to make use of the
f_artist_id
search property and use that to specify the artist_id (this may require you to have a separate function that finds the artist_id). EG:music.trackSearch({ q: "Drake - God's Plan", f_artist_id: "<drake's artist id>" ...
The other option is to set your
page_size
really high and filter through the results, but that seems...cumbersome.