Explain the service you intend to demonstrate and why someone would want to use it.
I intend to use spotify API to fetch data from the Spotify music catalog and analyze music from my favorite artists. It can be used to create playlists based on mood.
Walkthrough the steps for setting up the API both in R and on the service’s website
Step 1: Sign in Spotify for Developers on https://developer.spotify.com/. Then select Dashboard and create a new app
Step 2: Once the app the created, Client ID and Client Secret can be found within the app
Image via https://support.heateor.com/
Step 3: Prepare the R environment. Download R Wrapper for the Spotify API at https://cloud.r-project.org/web/packages/spotifyr/index.html.
Step 4: Use the following code to install the Development version of spotifyr and other necessary tools you need
devtools::install_github('charlie86/spotifyr')
library(devtools)
library(spotifyr)
library(tidyverse)
library(dplyr)Step 5: Copy and paste your unique Client ID and Client Secret from the app details
Sys.setenv(SPOTIFY_CLIENT_ID = ‘xxxxxxxxxxxxxxxxxxxxx’)
Sys.setenv(SPOTIFY_CLIENT_SECRET = ‘xxxxxxxxxxxxxxxxxxxxx’)
access_token <- get_spotify_access_token()
Step 6: After authentication, we can utilize spotifyr to find out information for your favorite artist.
Give a brief demonstration of at least one of the features or ‘calls’ to the API.
In the first example, I used the get_artist_audio_features feature to pull data for Taiwanese singer Cheer Chen. Then I sorted the data by key in order to find the most frequently used key in her songs.
library(spotifyr)
Cheer.Chen <- get_artist_audio_features('Cheer Chen')
library(dplyr)
library(purrr)
library(knitr)
Cheer.Chen %>%
count(key_mode, sort = TRUE) %>%
head(5) %>%
kable()| key_mode | n |
|---|---|
| F major | 32 |
| C major | 29 |
| G major | 26 |
| D# major | 20 |
| E major | 17 |
In the second example, I used the same feature to retrieve data for Christine and the Queens, a French singer-songwriter.
Valence is a measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. It is an attribute that Spotify computed based on a wide variety of inputs. Tracks with high valence sound more positive, while tracks with low valence sound more negative.
I listed the top 10 saddest song from Christine and the Queens.
cq <- get_artist_audio_features('Christine and the Queens')
library(dplyr)
library(purrr)
library(knitr)
cq %>%
arrange(valence) %>%
select(.data$track_name, .data$valence) %>%
head(10) %>%
kable() | track_name | valence |
|---|---|
| What’s-her-face | 0.0394 |
| What’s-her-face | 0.0394 |
| Machin-chose | 0.0534 |
| Machin-chose | 0.0534 |
| Nuit 17 à 52 | 0.0586 |
| Nuit 17 à 52 | 0.0612 |
| Night 52 | 0.0966 |
| Night 52 | 0.0966 |
| Night 52 | 0.1100 |
| Night 52 | 0.1100 |