About Me

  • Data Scientist at Trinity Health

    • Support clinical research projects

    • Support new data warehousing projects

  • Education:

    • Math, Statistics (Penn State)

    • Biostatistics (UM)

  • Raised in Pittsburgh, PA

  • Interests: Skiing, R, Beer, Music

Spotify API

  • HTTP-based RESTful API, with standard HTTP-Methods (GET, PUT, POST, DELETE)

  • Get metadata on artists, albums, songs

  • Allows interactions with Spotify users

    • Follow and unfollow artists and users
  • Create and manage playlists

  • Returns JSON

Basic Unauthenticated API Call

Install

options(unzip='internal') # If on Ubuntu 14.04+, openSUSE, ...
devtools::install_github('rweyant/spotifyr')
library(spotifyr)

Using Hadley's httr package:

  • Form URL in specific pattern (GET): https://api.spotify.com/v1/artists/{artist id}

e.g. https://api.spotify.com/v1/artists/4mTFQE6aiehScgvreB9llC

# Search Spotify's data for artists with names like "earth" and play drone (GET)
search_artist <- spotifyr::search('earth genre:drone',type = 'artist')

# Helper function to extract JSON elements into data.frame
summarized_artists <- spotifyr::simplify_result(search_artist$artists, type='artists')
summarized_artists[,c('name','id','genre','popularity','followers')]
   name                     id                        genre popularity followers
1 Earth 4mTFQE6aiehScgvreB9llC drone|drone metal|post-metal         35     15374

More data

top_tracks <- spotifyr::get_artist_toptracks(summarized_artists$id[1],'us')
summarized_tracks <- spotifyr::simplify_result(top_tracks$tracks,type='songs')
summarized_tracks[1:2,c('artists.name','name','popularity','duration_ms','album.name')]
  artists.name                                 name popularity duration_ms                              album.name
1        Earth     Omens And Portents 1: The Driver         29      547426 The Bees Made Honey In The Lion's Skull
2        Earth Torn by the Fox of the Crescent Moon         28      534297                    Primitive and Deadly

Future Plans

  • Test and improve stability across different operating systems

  • Work on the supporting the last 2 API endpoints for playlist management that still don't work

  • Improve helper functions to simplify returned JSON

  • Create a music recommender Shiny app integrating Gracenote, last.fm, and metal-archives data with embedded Spotify player and playlist creater

https://github.com/rweyant/spotifyr