Started out as a Spotify music recommendation app
NEW: Added features from music-generator 🎹
Content:
Streaming history can be retrieved from the Spotify profile as JSON, or through the spotipy functions current_user_recently_played or current_user_saved_tracks
with open("recently_played_20210306.json","r") as f:
results = json.load(f)
tracks = []
for idx, item in enumerate(results['items']):
track = item['track']
tracks.append([idx, track['artists'][0]['name'], track['name']])
trackDict = {"id":[], "artist":[],"name":[]}
for idx, item in enumerate(results['items']):
track = item['track']
trackDict["id"].append(idx)
trackDict["artist"].append(track['artists'][0]['name'])
trackDict["name"].append(track['name'])
import pandas as pd
trackDf = pd.DataFrame.from_dict(trackDict)
Analysis of features to produce a polar plot
import spotifyAPI
from secret import clientId,clientSecret
token = spotifyAPI.get_token(clientId,clientSecret)
lucy_id = spotifyAPI.get_track_id2('Lucy in the Sky', token, artist = 'The Beatles')
url = "https://open.spotify.com/track/"+lucy_id
import webbrowser
webbrowser.open(url)
import pandas as pd
lucy_features = spotifyAPI.get_features(lucy_id,token)
df = pd.DataFrame(lucy_features, index=[0])
df_features = df.loc[: ,['acousticness', 'danceability', 'energy', 'instrumentalness', 'liveness', 'speechiness', 'valence']]
spotifyAPI.feature_plot(df_features)
json_response = spotifyAPI.get_track_reco(lucy_id,token)
uris =[]
for i in json_response['tracks']:
uris.append(i)
print(f"\"{i['name']}\" by {i['artists'][0]['name']}")
This notebook leverages the Spotipy module to access the Spotify API:
https://spotipy.readthedocs.io/