forked from vedanthv/MusicHealsTheSoul
-
Notifications
You must be signed in to change notification settings - Fork 1
/
embed.py
41 lines (23 loc) · 993 Bytes
/
embed.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
34
35
import json
import time
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import random
client_id = '8be5f0367b7a4b54b730b33faa7c1b2c'
client_secret = '0bc78da67fa44fe985c2586aa74d7e1d'
client_credentials_manager = SpotifyClientCredentials(client_id, client_secret)
sp = spotipy.Spotify(client_credentials_manager =client_credentials_manager)
#func to extract all track ids
def get_track_ids(playlist_id):
music_id_list = []
playlist = sp.playlist(playlist_id)
for item in playlist['tracks']['items']:
music_track = item['track']
music_id_list.append(music_track['id'])
return music_id_list
#get the ids for all songs
playlist_id = input('Enter the playlist id')
track_ids = get_track_ids(playlist_id)
random.shuffle(track_ids)
embed = '<iframe src="https://open.spotify.com/embed/track/{}" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>'.format(track_ids[0])
print(embed)