Reputation: 93
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!
Upvotes: 1
Views: 1536
Reputation: 135
Slight continuing of drldcsta answer: the following curl command returns the 1 one song immediately:
curl --url "http://api.musixmatch.com/ws/1.1/track.search?q_artist=Drake&q_track=God%20Plan&apikey="
partial curl output: {"message":{"header":{"status_code":200,"execute_time":0.010561227798462,"available":1},"body":{"track_list":[{"track":{"track_id":153434470,"track_name":"God's Plan","track_name_translation_list":[],"track_rating":87,"commontrack_id":80272661,"instrumental":0,"explicit":1,"has_lyrics":1,"has_subtitles":1,"has_richsync":1,"num_favourite":7695,"album_id":29365716,"album_name":"Scorpion","artist_id":33491453,"artist_name":"Drake","track_share_url":"https://www
I would avoid the 'q' input parameter if you can. 'q' will take longer to return data, the other 'q_' input parameters will be quicker and use less bandwidth.
Upvotes: 0
Reputation: 423
The root of your issue is that you're using the q
search parameter. Per the docs, q
is searching:
within track titles,artists,lyrics
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.
Upvotes: 0