Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
oldschoolshuffle
async function getSimplePlaylistTracks(playlistId){
//track_number is what track number a song is on the album
try {
const tracks = await spotifyApi.getPlaylistTracks(playlistId);
//getPlaylistTracks has a bunch of meta data about the playlist we don't need
//once again items is the property we really want. It's an array of tracks
const simpleTracks = tracks.items.map((trackObject) => {
const track = trackObject.track;
const album = trackObject.track.album;
const artist = trackObject.track.artists[0]
return {
trackId: track.id,
trackName: track.name,
trackUri: track.uri,
trackNumber: track.track_number,
albumId: album.id,
albumName: album.name,
albumUri: album.uri,
artistId: artist.id,
artistName: artist.name,
artistUri: artist.uri,
}
})
return simpleTracks
}
catch(err) {
console.error('Error: getSimplePlaylistTracks in spotifyFunctions', err);
console.error(err.stack);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.