Skip to content

Instantly share code, notes, and snippets.

@gate5th
Created September 12, 2018 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gate5th/968b55664205e85a7ecadc8943e54836 to your computer and use it in GitHub Desktop.
Save gate5th/968b55664205e85a7ecadc8943e54836 to your computer and use it in GitHub Desktop.
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