-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
33 lines (25 loc) · 1.2 KB
/
main.py
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
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
#Authentication - without user
client_credentials_manager = SpotifyClientCredentials(client_id="8cb4ee46a6c7477498a9ca31f46f7b75", client_secret="255000706af94f97bc63a1a20fbee9af")
sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager)
playlist_link = "https://open.spotify.com/playlist/2F4jRlatHnYTWyHj5RMjW8?si=7ce4fbf11de44179"
playlist_URI = playlist_link.split("/")[-1].split("?")[0]
track_uris = [x["track"]["uri"] for x in sp.playlist_tracks(playlist_URI)["items"]]
for track in sp.playlist_tracks(playlist_URI)["items"]:
#URI
track_uri = track["track"]["uri"]
#Track name
track_name = track["track"]["name"]
#Main Artist
artist_uri = track["track"]["artists"][0]["uri"]
artist_info = sp.artist(artist_uri)
#Name, popularity, genre
artist_name = track["track"]["artists"][0]["name"]
artist_pop = artist_info["popularity"]
artist_genres = artist_info["genres"]
#Album
album = track["track"]["album"]["name"]
#Popularity of the track
track_pop = track["track"]["popularity"]
print(track_name, artist_name)