-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotify_tests.py
More file actions
39 lines (33 loc) · 1.11 KB
/
spotify_tests.py
File metadata and controls
39 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# url = "https://example.org/callback"
#
#
# # -----------------this code to log in to the spotify
#
from pprint import pprint
Client_ID = YOUR Client_ID
Client_Secret = YOUR CLIENT Client_Secret
import spotipy
from spotipy.oauth2 import SpotifyOAuth
sp = spotipy.Spotify(
auth_manager=SpotifyOAuth(
scope="playlist-modify-private",
redirect_uri="https://example.com",
client_id=Client_ID,
client_secret=Client_Secret,
)
)
user_id = sp.current_user()["id"]
class Spotify_tasks:
def __init__(self):
self.song_uris = []
def create_playlist(self, final_song_list, song_year):
for song in final_song_list:
result = sp.search(song)['tracks']['items'][0]['uri']
try:
self.song_uris.append(result)
except IndexError:
print(f"{song} doesn't exist in Spotify. Skipped.")
print(self.song_uris)
playlist = sp.user_playlist_create(user=user_id, name=f"{song_year} Time_Capsule", public=False)
print(playlist)
sp.playlist_add_items(playlist_id=playlist["id"], items=self.song_uris)