Created
February 20, 2024 13:34
-
-
Save Temerold/b6e8dbeff266d9b098eba29857e3c67b to your computer and use it in GitHub Desktop.
Like all Spotify tracks in a playlisy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from spotipy import Spotify | |
from spotipy.oauth2 import SpotifyOAuth | |
from yaml import full_load | |
if __name__ == "__main__": | |
with open("config.yaml", "r") as file: | |
config = full_load(file) | |
client_id = config["client_id"] | |
client_secret = config["client_secret"] | |
auth_manager = SpotifyOAuth( | |
client_id=client_id, | |
client_secret=client_secret, | |
redirect_uri="https://www.youtube.com/watch?v=dQw4w9WgXcQ", | |
scope="user-library-modify", | |
) | |
sp = Spotify(auth_manager=auth_manager) | |
ids = [] | |
items = sp.playlist_items("0u6zj8pXplxLgD7HROa8hM") | |
while items: | |
for i, item in enumerate(items["items"]): | |
track = item["track"] | |
ids.append(track["id"]) | |
print(f"{i + 1 + items['offset']}: {track['id']}") | |
if items["next"]: | |
items = sp.next(items) | |
else: | |
items = None | |
ids = list(filter(lambda a: a is not None, ids)) | |
# Add tracks to the user's library | |
for id in ids: | |
try: | |
print(id) | |
sp.current_user_saved_tracks_add(tracks=[id]) | |
except: | |
print(f"Error liking item with id {id}") | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment