Offset not respected
justekoro opened this issue · 7 comments
hi,
I'm using the latest version of spotify-web-api-node (5.0.2) and I made a code that is supposed to clone a spotify playlist.
It looks like the following:
spotifyApi.addTracksToPlaylist(d.body.id, tracksList).then(()=>{
if (data.body.tracks.total <= data.body.tracks.limit) {
spinner.succeed("Added tracks to playlist! My job is now done.");
process.exit(0);
} else {
let nb = Math.floor(data.body.tracks.total/data.body.tracks.limit)+1;
for(let i = 0; i < nb;i++) {
console.log(i*data.body.tracks.limit);
spotifyApi.getPlaylistTracks(plid,{offset: i*data.body.tracks.limit}).then(d => {
console.log(d);
})
}
}
})
Even if I put the {offset: i*data.body.tracks.limit}
, the offset is not respected and it keeps giving me only the 100 first tracks of the playlist. Is there a way to solve the issue?
I can confirm that the offset and limit options of getPlaylistTracks() works as of the time of this posting. I'd like to help but I don't seem to entirely understand your issue. Reading your code I would expect spotifyApi.getPlaylistTracks(plid,{offset: i*data.body.tracks.limit}).then(d => {console.log(d);})
to print two api calls, one with a track offset of 0 and one with and offset of 100. Is the issue that both calls have the same offset? If you could show more of your output that would be great.
hi! any news?
Can you share the output with the console logs? such as console.log(i*data.body.tracks.limit);
My theory is that there is an asynchronous issue with your for loop. For loops + API calls can sometimes lead to unexpected results