Skip to content

Commit

Permalink
fix 100 track upload limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
teticio committed Aug 14, 2023
1 parent d4d0209 commit 8f6853a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/Spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ export default class Spotify extends SpotifyWebApi {
description: 'Created by Deej-A.I. https://deej-ai.online'
});
}
await this.replaceTracksInPlaylist(
playlist.id,
track_ids.map(track_id => `spotify:track:${track_id}`)
);
// Spotify limits the number of tracks that can be added in one call to 100
const chunks = [];
for (let i = 0; i < track_ids.length; i += 100) {
chunks.push(track_ids.slice(i, i + 100).map(track_id => `spotify:track:${track_id}`));
}
await this.replaceTracksInPlaylist(playlist.id, chunks[0]);
for (let i = 1; i < chunks.length; i++) {
await this.addTracksToPlaylist(playlist.id, chunks[i]);
}
return playlist;
}
}

0 comments on commit 8f6853a

Please sign in to comment.