\data
contains json song dataget_data.py
allows for easy attraction of playlist data using Spotify for developers account (see below for more details)tinker.ipynb
takes json feature data from a playlist and converts to a pandas dataframe, draws feature histograms of said data
- you need a spotify CLIENT_ID & CLIENT_SECRET for this
- make a
credentials.py
file and input details, sample format below, you really just need the CLIENT_ID and CLIENT_SECRET - also input a username for the user you want to analyze
PORT_NUMBER = 8080
CLIENT_ID = 'YOUR_CLIENT_ID_HERE'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET_HERE'
REDIRECT_URI = 'http://localhost:8080'
SCOPE = 'user-library-read'
CACHE = '.spotipyoauthcache'
USERNAME = "YOUR_USERNAME_HERE"
- Create a Spotify for Developers account
- Create an app to get CLIENT_ID & CLIENT_SECRET (this we saved in the
credentials.py
file) - to get USERNAME go to Spotify Web Console and go to a user, click on the three dots button > Share > Copy Spotify URI
- run
get_data.py
to get user data into dataframes main(username, client_ID, client_secret)
returns two dataframes: one df with tracks data, one df with features of said tracks datamain2(username, client_ID, client_secret, print_to_file = False):
returns a text file or prints out all the tracks in the public playlists of a user in a semi-nicely formatted mannerget_playlist_content_from_id(playlistID, sp, playlistName = "")
just get the playlist track content from one playlistget_all_playlist_content(username, sp)
gets all the tracks in the public playlists of a user, returns a dfget_user_playlists(username, sp)
gets all playlists of a user, returns a dfget_all_track_features(tracks_df, sp)
gets all track features of a dataframe of tracks, returns a track_dfget_track_features(trackID, sp)
gets audio features for a single track, returns a features_df
- refer to
tinker.ipynb
- Spotify Web Console > Playlists > Get a Playlist's Tracks
- Share > Copy Spotify URI. From the URI grab the playlist ID (
spotify:user:username:playlist:playlist_id
) user_id
andplaylist_id
>items(track(album(name, href), href, id, name))
infields
.- under
OAuth Token
clickTRY IT
- song data in
songs.json
- Get Audio Features, navigate to Tracks > Get Audio Features for Several Tracks and enter the song ids
- copy and paste feature data in
features.json
- Spotipy Docs
- github code reference for spotipy usage in
get_data.py
- Code cleanup:
- add a package requirements file