0

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?

Herbiv
  • 1
  • 2
  • Add `coverart: 1` to your query `q: song , limit : 1` – Jishan Shaikh Dec 12 '22 at 15:28
  • it doesn't work either, the uploaded image doesn't match the one in the album – Herbiv Dec 12 '22 at 19:59
  • Looks like a bug in that API. If you really want the correct image use a subsequent `track.getInfo` call to retrieve the right image. See also https://stackoverflow.com/questions/75362287/why-lastfm-api-returns-the-wrong-image – jmizv Jun 30 '23 at 09:43

0 Answers0