summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-09-21 01:17:09 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2024-09-21 01:17:09 +0200
commit0bb99307f17b19c397a7fb4d3f262368d6011e2f (patch)
tree655be8fd38a3e666ea5c8b474e7b2b71a2eb6fbb
parentfix order (diff)
downloadr-0bb99307f17b19c397a7fb4d3f262368d6011e2f.tar
r-0bb99307f17b19c397a7fb4d3f262368d6011e2f.tar.gz
r-0bb99307f17b19c397a7fb4d3f262368d6011e2f.tar.bz2
r-0bb99307f17b19c397a7fb4d3f262368d6011e2f.tar.lz
r-0bb99307f17b19c397a7fb4d3f262368d6011e2f.tar.xz
r-0bb99307f17b19c397a7fb4d3f262368d6011e2f.tar.zst
r-0bb99307f17b19c397a7fb4d3f262368d6011e2f.zip
-rwxr-xr-xskripti/spotify_publish_saved.py66
1 files changed, 35 insertions, 31 deletions
diff --git a/skripti/spotify_publish_saved.py b/skripti/spotify_publish_saved.py
index ece6cbd..a7f737a 100755
--- a/skripti/spotify_publish_saved.py
+++ b/skripti/spotify_publish_saved.py
@@ -6,34 +6,38 @@ 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 = "0ASvlSEvlQu5nyFwUZqf9n"
-results = {"items": [None]}
-offset = 0
-publicized_uris = []
-while len(results["items"]) != 0:
- results = sp.playlist_items(playlist, None, 100, offset)
- for idx, item in enumerate(results["items"]):
- publicized_uris.append(item["track"]["uri"])
- offset += 100
-results = {"items": [None]}
-offset = 0
-saved_items = []
-to_add = []
-while len(results["items"]) != 0:
- results = sp.current_user_saved_tracks(50, offset)
- for idx, item in enumerate(results['items']):
- saved_items.append(item)
- if item["track"]["uri"] not in publicized_uris:
- to_add.append(item["track"]["uri"])
- else:
- publicized_uris.remove(item["track"]["uri"])
- offset += 50
-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 ... order is correct, new songs get added counterintuitively at the bottom")
-print(json.dumps(saved_items))
+for playlist, rev in [("0ASvlSEvlQu5nyFwUZqf9n", False), ("4B9TSgOGQRRvFtOnQav42J", True)]:
+ publicized_uris = []
+ results = {"items": [None]}
+ offset = 0
+ while len(results["items"]) != 0:
+ results = sp.playlist_items(playlist, None, 100, offset)
+ for idx, item in enumerate(results["items"]):
+ publicized_uris.append(item["track"]["uri"])
+ offset += 100
+ results = {"items": [None]}
+ offset = 0
+ saved_items = []
+ to_add = []
+ while len(results["items"]) != 0:
+ results = sp.current_user_saved_tracks(50, offset)
+ for idx, item in enumerate(results['items']):
+ saved_items.append(item)
+ if item["track"]["uri"] not in publicized_uris:
+ to_add.append(item["track"]["uri"])
+ else:
+ publicized_uris.remove(item["track"]["uri"])
+ offset += 50
+ if rev == False:
+ to_add.reverse()
+ if len(to_add) != 0:
+ iterator = [to_add[i:i+50] for i in range(0, len(to_add), 50)]
+ if rev:
+ iterator = reversed(iterator)
+ for batch in iterator:
+ sp.playlist_add_items(playlist, batch, 0 if rev else None)
+ 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." + " [REVERSED]" if rev else "", public=True, collaborative=False, description=f"updated {todaystring} automatically daily using http://4a.si/spotsync")
+ print(json.dumps(saved_items))