From 06f3025a088b3e8d13bc10136fb9e0bceef3b0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sat, 21 Sep 2024 00:49:52 +0200 Subject: fix order --- skripti/spotify_publish_saved.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/skripti/spotify_publish_saved.py b/skripti/spotify_publish_saved.py index 12f4149..ece6cbd 100755 --- a/skripti/spotify_publish_saved.py +++ b/skripti/spotify_publish_saved.py @@ -6,7 +6,7 @@ import sys import datetime scope = "user-library-read playlist-modify-public" sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope, client_id="1034e542fa064c27859b61a6ec5f864e", client_secret="2503172e78ce4d5e9146047db0a39077", redirect_uri="http://b.4a.si:25425/")) -playlist = "7IyZWvHG2e7CiGnHGTkFBl" +playlist = "0ASvlSEvlQu5nyFwUZqf9n" results = {"items": [None]} offset = 0 publicized_uris = [] @@ -18,9 +18,9 @@ while len(results["items"]) != 0: results = {"items": [None]} offset = 0 saved_items = [] +to_add = [] while len(results["items"]) != 0: results = sp.current_user_saved_tracks(50, offset) - to_add = [] for idx, item in enumerate(results['items']): saved_items.append(item) if item["track"]["uri"] not in publicized_uris: @@ -28,11 +28,12 @@ while len(results["items"]) != 0: else: publicized_uris.remove(item["track"]["uri"]) offset += 50 - if len(to_add) != 0: - sp.playlist_add_items(playlist, to_add) - # print(offset, file=sys.stderr) +to_add.reverse() +if len(to_add) != 0: + for batch in [to_add[i:i+50] for i in range(0, len(to_add), 50)]: + sp.playlist_add_items(playlist, batch) if len(publicized_uris) != 0: sp.playlist_remove_all_occurrences_of_items(playlist, publicized_uris) todaystring = datetime.datetime.now().isoformat().replace("T", " ").split(".")[0] -sp.playlist_change_details(playlist, name="public mirror of my liked songs.", public=True, collaborative=False, description=f"updated {todaystring} automatically daily using http://4a.si/spotsync") +sp.playlist_change_details(playlist, name="public mirror of my liked songs.", public=True, collaborative=False, description=f"updated {todaystring} automatically daily using http://4a.si/spotsync ... order is correct, new songs get added counterintuitively at the bottom") print(json.dumps(saved_items)) -- cgit v1.2.3