spotify-web-api-node icon indicating copy to clipboard operation
spotify-web-api-node copied to clipboard

how to search for a song with the song link (https://open.spotify.com/track/5kJLPjc6YlvkoEm3aZ0VBV?si=zheh1KQWTfOOeleGlK5CiQ)

Open Sekai966 opened this issue 4 years ago • 2 comments

how to search for a song with the song link (https://open.spotify.com/track/5kJLPjc6YlvkoEm3aZ0VBV?si=zheh1KQWTfOOeleGlK5CiQ)

i mean the docs says only how to search with artist name etc.. and i want to search with a url

Sekai966 avatar Feb 01 '21 14:02 Sekai966

I think you can just split the link so you get the trackID and then use getTrack.

sigesig avatar Feb 10 '21 20:02 sigesig

how to search for a song with the song link (https://open.spotify.com/track/5kJLPjc6YlvkoEm3aZ0VBV?si=zheh1KQWTfOOeleGlK5CiQ)

i mean the docs says only how to search with artist name etc.. and i want to search with a url

Parse the Track id from the URL:

For eg: URL : https://open.spotify.com/track/5kJLPjc6YlvkoEm3aZ0VBV?si=zheh1KQWTfOOeleGlK5CiQ Id of the Track : 5kJLPjc6YlvkoEm3aZ0VBV

Then use the Following methods to get info of the Track:

spotifyApi.getTrack(spotifyTrackId).then(
  function (data) {
    let temp = data.body;
    artists = temp.album.artists[0].name;
    images = temp.album.images[0].url;
    album = temp.album.name;
    title = temp.name;
    date = temp.album.release_date;
    spotifyTrackName = `${title} ${artists}`;
    getYtLink(spotifyTrackName);
  },
  function (err) {
    console.error(err);
  }
);

Deep-Codes avatar Feb 17 '21 16:02 Deep-Codes