spotify-web-api-node
spotify-web-api-node copied to clipboard
[Help] how to iterate with next url?
as #45 didnt helped much so posting again, i have got body.tracks.next now how to get more tracks, with request module it can be done but feels a bit long can you add Object.nextUri something method?
I was searching for a solution to this, but couldn't find anything either, so I made my own little function.
const getAllTracks = async (playlist) => {
let tracks = []
const { body } = await spotify.getPlaylistTracks(playlist)
tracks = body.items
if (body.total > 100)
for (let i = 1; i < Math.ceil(body.total / 100); i++) {
const add = await spotify.getPlaylistTracks(playlist, { offset: 100 * i })
tracks = [...tracks, ...add.body.items]
}
return tracks
}
This returns an Array containing all the items in a given playlist. Could easily be modified to return the rest of the playlist info too, but in my case I just needed the tracks.