summaryrefslogtreecommitdiffstats
path: root/skripti
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-09-20 23:51:01 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2024-09-20 23:51:01 +0200
commit0287352cfa380ebdbac0ba9531a17e3afc95b523 (patch)
tree59da542d0dc4830c168669150086b6ad724ed666 /skripti
parentcv (diff)
downloadr-0287352cfa380ebdbac0ba9531a17e3afc95b523.tar
r-0287352cfa380ebdbac0ba9531a17e3afc95b523.tar.gz
r-0287352cfa380ebdbac0ba9531a17e3afc95b523.tar.bz2
r-0287352cfa380ebdbac0ba9531a17e3afc95b523.tar.lz
r-0287352cfa380ebdbac0ba9531a17e3afc95b523.tar.xz
r-0287352cfa380ebdbac0ba9531a17e3afc95b523.tar.zst
r-0287352cfa380ebdbac0ba9531a17e3afc95b523.zip
Diffstat (limited to 'skripti')
-rwxr-xr-xskripti/spotify_publish_saved.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/skripti/spotify_publish_saved.py b/skripti/spotify_publish_saved.py
new file mode 100755
index 0000000..dbd1083
--- /dev/null
+++ b/skripti/spotify_publish_saved.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+import spotipy
+from spotipy.oauth2 import SpotifyOAuth
+import json
+import sys
+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"
+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 = []
+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:
+ to_add.append(item["track"]["uri"])
+ 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)
+if len(publicized_uris) != 0:
+ sp.playlist_remove_all_occurrences_of_items(playlist, publicized_uris)
+json.dumps(saved_items)