Skip to content
Snippets Groups Projects
Commit 7601b95a authored by Robert Goldmann's avatar Robert Goldmann
Browse files

SpotifyAutoPlaylistCreator: handle adding more than 100 songs to a playlist

parent 912168e0
Branches
Tags
No related merge requests found
...@@ -90,7 +90,14 @@ class SpotifyAutoPlaylistCreator: ...@@ -90,7 +90,14 @@ class SpotifyAutoPlaylistCreator:
LOGGER.info(f'>>> Adding tracks to destination playlist "{destinationPlaylist["name"]}"...') LOGGER.info(f'>>> Adding tracks to destination playlist "{destinationPlaylist["name"]}"...')
randomTrackUris = self.__extract_track_uris(randomTracks) randomTrackUris = self.__extract_track_uris(randomTracks)
self._spotify.playlist_add_items(self._destinationPlaylistInfo['id'], randomTrackUris)
for batch in self.__chunk_list(randomTrackUris, 100):
self._spotify.playlist_add_items(self._destinationPlaylistInfo['id'], batch)
@staticmethod
def __chunk_list(items, batchSize):
for i in range(0, len(items), batchSize):
yield items[i:i + batchSize]
def __CollectLatestTracks(self, sortedTracks): def __CollectLatestTracks(self, sortedTracks):
tracksToAdd = [] tracksToAdd = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment