-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathposter_maker.py
26 lines (20 loc) · 916 Bytes
/
poster_maker.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
import pickle
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
CLIENT_ID = "70a9fb89662f4dac8d07321b259eaad7"
CLIENT_SECRET = "4d6710460d764fbbb8d8753dc094d131"
# Initialize the Spotify client
client_credentials_manager = SpotifyClientCredentials(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
# Loading data
music = pickle.load(open('./data/song_data.pkl', 'rb'))
# Getting the song album cover URL using Spotify API
def get_song_album_cover_url(song_name):
search_query = f"track:{song_name}"
results = sp.search(q=search_query, type="track")
if results and results["tracks"]["items"]:
track = results["tracks"]["items"][0]
album_cover_url = track["album"]["images"][0]["url"]
return album_cover_url
else:
return "https://i.postimg.cc/0QNxYz4V/social.png"