update spotify playlist with pagination
This commit is contained in:
parent
a9bbe2e9f6
commit
175a2a9b0c
11
main.py
11
main.py
|
@ -80,7 +80,16 @@ def update_spotify_from_export():
|
|||
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
sp.playlist(SPOTIFY_PLAYLIST_ID)
|
||||
print(sp.playlist_replace_items(SPOTIFY_PLAYLIST_ID, [s for s in spotify_links if not s.startswith('https://open.spotify.com/playlist/')]))
|
||||
|
||||
# clean playlist itself from spotify links
|
||||
spotify_links = [s for s in spotify_links if not s.startswith('https://open.spotify.com/playlist/')]
|
||||
|
||||
# paginated update of spotify playlist
|
||||
for i, sublist in enumerate(_split_seq(spotify_links, 100)):
|
||||
if i==0:
|
||||
sp.playlist_replace_items(SPOTIFY_PLAYLIST_ID, sublist)
|
||||
else:
|
||||
sp.playlist_add_items(SPOTIFY_PLAYLIST_ID, sublist)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue