STATIPY

STATIPY

- 3 mins

What is STATIPY?

Adds the Stats to your Spotify experience, Statipy will gather the information of your very own spotify playlists and enables you to run data analysis with jupyter notebook.


Contents

  1. Installation
  2. Spotify Developer
  3. Spotipy Documentation
  4. Running STATIPY

Visualizing the data gathered by Spotify user, allows us to make inferences on what user can do to improve Spotify experience based on data saved.

i. Installation:

import SPOTIPY pip install spotipy

Incase any errors occur after pip install - try forcing the upgrade from the github repo -

pip install git+https://github.com/plamere/spotipy.git –upgrade Check out: spotipy on github or https://spotipy.readthedocs.io

Once you have the environment variables set, run the Statipy app from your command line..

python Statipy.py [username] (Be careful not to push out keys or publish them up on github!)

Sign in to SPOTIFY (if you download the desktop app, theres more automagic things to perform - like grabbing device id and playing music remotely through command line) Sign up to get credentials: https://developer.spotify.com/

Make a Spotify developer account on the developer dashboard. If you dont have a Spotify account yet, make one. If Spotify is logged in on your Spotify desktop app it uses that sign in info. Make an app and register to get key Give a brief description on Spotify, the developer dashboard gives you your app usage and traffic. ** IMPORTANT ** save your client id key and secret key on your computer to a file that will not be exposed on github or in the interwebs

Spotify api has a limit of 50, Ive reached my cap a couple of times, but resets the next day. A good thing to keep in mind, if you reach your daily limit, you get a connection error that the token has expired. You can check back on the developer page to see if you have reached the limit - in which case you can try the next day, or if you just need to update your permissions list it would be a quick way to find out.

Sign in with your developer credentials on the command line or add it to a file and import it to your .py file, (in this example, the statipy_analyzer.py - already imports from config.py). If you save it to a file, make sure you don’t include this in any uploads or on Github pushes otherwise you would be exposing your keys.

HideYourKeysHideYourWifi

… Get auth You need to set your Spotify API credentials. You can do this by setting environment variables like so:

> export SPOTIPY_CLIENT_ID='your-spotify-client-id'
> export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
> export SPOTIPY_REDIRECT_URI='your-app-redirect-url'
> IMPORTANT: SPOTIPY_REDIRECT_URI='https://mxnkpl.com/'

just dont forget the “ / “ after url, allows spotify to redirect api request. When you run Statipy, it saves your developer credentials entered in CLI into a username variable, (if you run statipy_analyzer.py [username] by pulling this project on github, it will use username configuration that you have set up in config.py)

and the scope variable is defined when it runs this part of the code:

Asks for permission to get current users playlists:

> scope = "user-read-private user-read-email user-library-read playlist-read-private playlist-read-> collaborative" ### Spotipy function that keeps you authorized saved into token variable:

> token = util.prompt_for_user_token(username, scope)

Command line / IDE should now retrieve current users data.

Playlists - Name and Total tracks Tracks - Song Info from each playlist Artist - Artist Info from each track Album - Album Info from each track Running statipy_analyzer.py python statipy_analyzer.py [username]

Statipy analyzer will run in any package that contains:

init.py

and

config.py

in its folder.

As step 5 states: you must create your own config.py file to run locally with same export syntax for CLI. Spotify object Data available on spotify api:

Track popularity explicit followers Album popularity release_date album_art Artist popularity followers genre Audio Analysis

of current users saved, public, private and followed playlists.

The objective is to analyze the frequency of objects and find patterns in the saved data that could be used to improve playlist content and Spotify user experience.

Statipy Project on Github

Maximo Nakpil

Maximo Nakpil

Full-Stack Web Dev Exploring Data and Design Disciplines

comments powered by Disqus
rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora