Exploring Spotify Play History

Dan Gray

2021/06/23

Premable

As an avid music fan, I have a pretty good intuition for which music I listen to most (and when!) but it would be interesting to see if any obvious listening patterns stand out, and generally to know which artists, songs and genres accompany me (Part 2) over the course of several weeks.

As a initial exercise (Part 1), I wanted to play briefly with analyzing lyrics from my music collection - specifically to build a playlist inspired by (a person and…) the colour “Blue”.

Collecting the data

I’d setup a IFTTT (“If This Then That”) applet that keep a log of my recently played Spotify tracks and saved that to a Google Drive sheet. Retrieving the data can either by down using the googledrive, googlesheets or gogglesheets4 libraries, but one can simple download the sheet down as a .csv manually.

# load libraries
library(tidyverse)
library(genius)
library(stringr)
# download file and merge
spotify_plays <- read_csv("spotify_plays.csv", 
                          col_names = FALSE)

Part 1: Lyrics Extraction

Firstly we need to get a distinct list of artist-song pairs based on the entire listening history of >3000 plays.

One can then decide which artists can be pre-filtered out based on language - as these results are unlikely to be held in the Genius website.

# remove foreign language tracks
non_en <-c("Songhoy Blues")

spotify_plays %>% distinct(X2,X3) %>% 
  filter(!X2 %in% non_en) %>% 
  mutate(artist=X2,song=X3) %>% 
  select(-X2,-X3) -> spotify_distinct_en

head(spotify_distinct_en)
## # A tibble: 6 x 2
##   artist     song                                       
##   <chr>      <chr>                                      
## 1 Bosse      Schönste Zeit - Leise Landung Live         
## 2 Bosse      Dein Hurra                                 
## 3 Bombino    Iyat Ninhay / Jaguar (A Great Desert I Saw)
## 4 Pink Floyd Shine On You Crazy Diamond - Live          
## 5 Pink Floyd Astronomy Domine - Live                    
## 6 Pink Floyd What Do You Want From Me - Live

Quite a few of the songs are from compilation albums, or remastered releases, and thus these extra tags may impede the lyric search so they are replaced with blank strings to hopefully return the original song titles.

# clean to reflect original releases
spotify_distinct_en %>% 
  mutate(title=str_remove(spotify_distinct_en$song," - Live")) %>%
  select(-song) -> spotify_distinct_org

spotify_distinct_org %>% 
  mutate(song=str_remove(spotify_distinct_org$title," - 2011 Remaster")) %>%
  select(-title) -> spotify_distinct_alb

In total we are going to search through just over 500 tracks.

spotify_distinct_alb %>% count()
## # A tibble: 1 x 1
##       n
##   <int>
## 1   574

The filtered list of songs from the original albums is then passed to the add_genius() function which proceeds to build up the url’s which are then parsed to return a dataframe of rows containing artist, song, and lyrics (per line) for each record.

# retrieve all lyrics
spotify_distinct_alb %>%
  add_genius(artist, song, type = "lyrics")-> lyrics_all

We successfully retrieved lyrics for about half of our tracks.

lyrics_all %>% 
  distinct(song,artist) %>% 
  count()
## # A tibble: 1 x 1
##       n
##   <int>
## 1   232

We can use the grepl function to filter out lyrics which contain the following words.

# filter by the desired search words
lyrics_all %>% filter(grepl('blue|blues|Blue|Blues|blau|Blau', lyric)) -> plays_blue

# return artist and title
plays_blue %>% distinct(.,song,artist) -> tracks_blue

Exactly 48 lines match the above conditions…

formattable:: format_table(plays_blue[,2:6])
artist song track_title line lyric
Bosse Sophie Sophie 15 Du lgst mir das Blaue vom Himmel
Bosse Sophie Sophie 32 Du lgst mir das Blaue vom Himmel
Bosse Overkill Overkill 7 Die Tage blau, so schn leer
Angus & Julia Stone Cellar Door Cellar Door 30 I wanna look up, so I can see the blue sky
Angus & Julia Stone Cellar Door Cellar Door 31 See the blue in your eyes
PeterLicht Marketing Marketing 4 Die noch blau sind
Element Of Crime Delmenhorst Delmenhorst 10 Und die sind immer grn und blau
Stephen Stills Sit Yourself Down Sit Yourself Down 9 Never gonna get rid of these blues
Stephen Stills Sit Yourself Down Sit Yourself Down 29 I’m never gettin rid of these blues
Taj Mahal Leaving Trunk Leaving Trunk 2 I ain’t see no blues, whiskey made me sloppy drunk
Taj Mahal Leaving Trunk Leaving Trunk 3 I ain’t never seen no whiskey, the blues made me sloppy drunk
Taj Mahal Leaving Trunk Leaving Trunk 9 The blues are mushed up into three different ways
Taj Mahal Leaving Trunk Leaving Trunk 11 I woke up this mornin’ with the blues three different ways
Taj Mahal Leaving Trunk Leaving Trunk 14 You know I’m a man who love to sing the blues
Taj Mahal Leaving Trunk Leaving Trunk 16 Well you know I’m the man, I’m the man oh yes and I love to sing the blues
Taj Mahal Leaving Trunk Leaving Trunk 19 I ain’t see no blues or whiskey made me sloppy drunk
Taj Mahal Leaving Trunk Leaving Trunk 20 I ain’t never seen no whiskey, the blues made me sloppy drunk
Robert Johnson Walkin’ Blues Walkin<U+0092> Blues 2 Know ’bout ’at I got these, old walking blues
Robert Johnson Walkin’ Blues Walkin<U+0092> Blues 4 But you know ’bout ’at I, got these old walking blues
Robert Johnson Walkin’ Blues Walkin<U+0092> Blues 13 Well, some people tell me that the worried blues ain’t bad
Robert Johnson Walkin’ Blues Walkin<U+0092> Blues 15 People tell me that these old worried old blues ain’t bad
Dave Matthews Band Big Eyed Fish Big Eyed Fish 10 He turned red and blue, purple, colorful indeed
Stephen Stills Nothin’ to Do but Today Nothin<U+0092> to Do But Today 16 I am a blues man, I know when to leave
Little Feat A Apolitical Blues A Apolitical Blues 7 I’ve got the apolitical blues
Little Feat A Apolitical Blues A Apolitical Blues 8 And that’s the meanest blues of all
Little Feat A Apolitical Blues A Apolitical Blues 9 Apolitical blues
Little Feat A Apolitical Blues A Apolitical Blues 10 And that’s the meanest blues of all
Gerry Cinnamon Fickle McSelfish Fickle McSelfish 12 Won’t you come and take my blues away
Gerry Cinnamon Fickle McSelfish Fickle McSelfish 25 Won’t you come and take my blues away
Bosse Insel Insel 4 Skorbut und blaue Zehen
Buddy Guy DJ Play My Blues DJ Play My Blues 2 I wonder why you don’t play much blues anymore
Buddy Guy DJ Play My Blues DJ Play My Blues 4 I keep wondering why you don’t play much blues anymore
Buddy Guy DJ Play My Blues DJ Play My Blues 8 Even though I know that bluesman now he’s gone
Taj Mahal Lonely Avenue Lonely Avenue 7 Now I feel so sad and blue
Taj Mahal Lonely Avenue Lonely Avenue 18 And I feel so sad and blue
Neil Young Walk Like a Giant Walk Like a Giant 37 When I’m seeing your blue eyes shining
Peter Frampton Baby, I Love Your Way Baby, I Love Your Way 22 Brown and gray, blue besides
Keb’ Mo’ Love In Vain Love in Vain 19 You know the blue light it was my blue
Angus & Julia Stone Yellow Brick Road Yellow Brick Road 14 That skinny dipping girl made the blue bird sing
Keb’ Mo’ Muddy Water Muddy Water 6 They got the blues in Mississippi
Keb’ Mo’ Muddy Water Muddy Water 16 Ready for the blues tonight
Keb’ Mo’ Muddy Water Muddy Water 34 I’m ready for the blues tonight
Keb’ Mo’ Muddy Water Muddy Water 42 I’m ready for the blues tonight
Keb’ Mo’ Muddy Water Muddy Water 47 Ready for the blues tonight
Keb’ Mo’ Muddy Water Muddy Water 52 Ready for the blues tonight
Keb’ Mo’ Muddy Water Muddy Water 57 Ready for the blues tonight
Keb’ Mo’ Your Love Your love 19 You know the blue light it was my blue
Keb’ Mo’ I See Love I See Love 29 But all I ever got was the blues

Consisting of the following artist-track pairs.

formattable:: format_table(tracks_blue[,2:3])
artist song
Bosse Sophie
Bosse Overkill
Angus & Julia Stone Cellar Door
PeterLicht Marketing
Element Of Crime Delmenhorst
Stephen Stills Sit Yourself Down
Taj Mahal Leaving Trunk
Robert Johnson Walkin’ Blues
Dave Matthews Band Big Eyed Fish
Stephen Stills Nothin’ to Do but Today
Little Feat A Apolitical Blues
Gerry Cinnamon Fickle McSelfish
Bosse Insel
Buddy Guy DJ Play My Blues
Taj Mahal Lonely Avenue
Neil Young Walk Like a Giant
Peter Frampton Baby, I Love Your Way
Keb’ Mo’ Love In Vain
Angus & Julia Stone Yellow Brick Road
Keb’ Mo’ Muddy Water
Keb’ Mo’ Your Love
Keb’ Mo’ I See Love

Part 2: Play History and Artist, Genre and Song Analysis

Coming soon……