I'm trying to download the cover image from the trackSearch method of the last.fm API.
Here's what I've done :
lastfm.trackSearch({ q: song , limit : 1}, (err, data) => {
if (err) console.error(err)
else console.log(data)
//console.log(data.result[0].images[0]);
coverLink = data.result[0].images[0];
request = http.get(coverLink, function(response) {
response.pipe(file);
// after download completed close filestream
file.on("finish", () => {
file.close();
console.log("Download Completed");
});
});
})
Result :
{
meta: {
query: { q: 'Halfway Home - TV On The Radio\r\n', limit: 1 },
page: 1,
perPage: 1,
total: 163,
totalPages: 163
},
result: [
{
type: 'track',
name: 'Halfway Home',
artistName: 'TV on the Radio',
duration: undefined,
listeners: 282831,
images: [Array]
}
]
}
Then it downloads a file, but the url isn't the right one. (https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png)
What did I did wrong?