genius Basics

Josiah Parry

2019-02-28

genius

genius enables quick and easy download of song lyrics. The intent behind the package is to be able to perform text based analyses on songs in a tidy[text] format. Song lyrics come from Genius (formerly Rap Genius), the most widely accessible platform for lyrics.

The functions in this package enable easy access of individual song lyrics, album tracklists, and lyrics to whole albums.

Individual songs genius_lyrics()

Getting lyrics to a single song is pretty easy. Let’s get in our ELEMENT. and checkout DNA.. But first, note that the genius_lyrics() function takes two arguments, artist and song. Be sure to spell the name of the artist and the song correctly, but don’t worry about capitalization.

First, let’s set up our working environment.

genius_lyrics() returns only the barebones. Utilizing dplyr we can also create a new variable with the line number to help in future tidytext analysis. This will be covered in a later vignette / post.

DNA <- genius_lyrics(artist = "Kendrick Lamar", song = "DNA.")
DNA
## # A tibble: 71 x 3
##    track_title  line lyric                                                 
##    <chr>       <int> <chr>                                                 
##  1 DNA.            1 I got, I got, I got, I got—                           
##  2 DNA.            2 Loyalty, got royalty inside my DNACocaine quarter pie…
##  3 DNA.            3 I got hustle though, ambition flow inside my DNAI was…
##  4 DNA.            4 I transform like this, perform like this, was Yeshua …
##  5 DNA.            5 I don't contemplate, I meditate, then off your fuckin…
##  6 DNA.            6 This that put-the-kids-to-bed                         
##  7 DNA.            7 This that I got, I got, I got, I got—                 
##  8 DNA.            8 Realness, I just kill shit 'cause it's in my DNAI got…
##  9 DNA.            9 I got off, I got troublesome heart inside my DNAI jus…
## 10 DNA.           10 Yeah, that's him again, the sound that engine in is l…
## # … with 61 more rows

This function also enables you to get verse level information. This tends to me more popular in hip-hop where songs may have multiple feature artists (thanks to @natebarr64 for the help!). genius_lyrics() has an argument called info. It defaults to "title". If you provide the argument info = "features" two new columns appear, "verse" and "vocalist".

genius_lyrics(artist = "Kendrick Lamar", song = "DNA.", info = "features")
## # A tibble: 71 x 4
##     line lyric                                       element element_artist
##    <int> <chr>                                       <chr>   <chr>         
##  1     1 I got, I got, I got, I got—                 Verse 1 Kendrick Lamar
##  2     2 Loyalty, got royalty inside my DNACocaine … Verse 1 Kendrick Lamar
##  3     3 I got hustle though, ambition flow inside … Verse 1 Kendrick Lamar
##  4     4 I transform like this, perform like this, … Verse 1 Kendrick Lamar
##  5     5 I don't contemplate, I meditate, then off … Verse 1 Kendrick Lamar
##  6     6 This that put-the-kids-to-bed               Verse 1 Kendrick Lamar
##  7     7 This that I got, I got, I got, I got—       Verse 1 Kendrick Lamar
##  8     8 Realness, I just kill shit 'cause it's in … Verse 1 Kendrick Lamar
##  9     9 I got off, I got troublesome heart inside … Verse 1 Kendrick Lamar
## 10    10 Yeah, that's him again, the sound that eng… Verse 1 Kendrick Lamar
## # … with 61 more rows

Albums

More often than not you will want to get the lyrics for an entire album. This is done easily with genius_album(). Just provide the artist and album name.

DAMN <- genius_album(artist = "Kendrick Lamar", album = "DAMN.")
## Joining, by = c("track_title", "track_n", "track_url")
head(DAMN)
## # A tibble: 6 x 4
##   track_title track_n  line lyric                               
##   <chr>         <int> <int> <chr>                               
## 1 BLOOD.            1     1 Is it wickedness?                   
## 2 BLOOD.            1     2 Is it weakness?                     
## 3 BLOOD.            1     3 You decide                          
## 4 BLOOD.            1     4 Are we gonna live or die?           
## 5 BLOOD.            1     5 So I was takin' a walk the other day
## 6 BLOOD.            1     6 And I seen a woman—a blind woman

Bam. Easy peasy. Now you have a sweet data frame ready for a tidy text analysis!

Multiple albums or songs

Being able to create a dataframe with multiple artists and albums is extremely useful for tidytext analysis. Instead of having to iterate over your data, add_genius() is here to assist you.

Pipe a dataframe with a column for the album artists and album/track information. The argument type is used to indicate if the dataframe contains songs or albums

# Example with 2 different artists and albums
artist_albums <- tribble(
 ~artist, ~album,
 "J. Cole", "KOD",
 "Sampha", "Process"
)


artist_albums %>%
 add_genius(artist, album)
## Joining, by = c("track_title", "track_n", "track_url")
## Joining, by = c("track_title", "track_n", "track_url")
## Joining, by = c("artist", "album")
## # A tibble: 1,320 x 6
##    artist  album track_title track_n  line lyric                           
##    <chr>   <chr> <chr>         <int> <int> <chr>                           
##  1 J. Cole KOD   Intro (KOD)       1     1 Can someone please turn off my …
##  2 J. Cole KOD   Intro (KOD)       1     2 My thoughts are racing all the …
##  3 J. Cole KOD   Intro (KOD)       1     3 There is no reason or no rhyme  
##  4 J. Cole KOD   Intro (KOD)       1     4 I'm trapped inside myself       
##  5 J. Cole KOD   Intro (KOD)       1     5 A newborn baby has two primary …
##  6 J. Cole KOD   Intro (KOD)       1     6 "Laughter, which says, \"I love…
##  7 J. Cole KOD   Intro (KOD)       1     7 "Or crying, which says, \"This …
##  8 J. Cole KOD   Intro (KOD)       1     8 There are many ways to deal wit…
##  9 J. Cole KOD   Intro (KOD)       1     9 Choose wisely                   
## 10 J. Cole KOD   Intro (KOD)       1    10 At the bottom of the hourglass  
## # … with 1,310 more rows
# Example with 2 different artists and songs
artist_songs <- tribble(
 ~artist, ~track,
 "J. Cole", "Motiv8",
 "Andrew Bird", "Anonanimal"
)

artist_songs %>%
 add_genius(artist, track, type = "lyrics")
## Joining, by = c("artist", "track")
## # A tibble: 102 x 5
##    artist  track  track_title  line lyric                                  
##    <chr>   <chr>  <chr>       <int> <chr>                                  
##  1 J. Cole Motiv8 Motiv8          1 You really wanna know who Superman is? 
##  2 J. Cole Motiv8 Motiv8          2 Watch this, pow!                       
##  3 J. Cole Motiv8 Motiv8          3 I like him                             
##  4 J. Cole Motiv8 Motiv8          4 I think he's pretty cool               
##  5 J. Cole Motiv8 Motiv8          5 He's my idol                           
##  6 J. Cole Motiv8 Motiv8          6 I can't have no sympathy for fuck nigg…
##  7 J. Cole Motiv8 Motiv8          7 All this shit I've seen done made my b…
##  8 J. Cole Motiv8 Motiv8          8 Spill promethazine inside a double cup 
##  9 J. Cole Motiv8 Motiv8          9 Double up my cream, now that's a Doubl…
## 10 J. Cole Motiv8 Motiv8         10 Please don't hit my phone if it ain't …
## # … with 92 more rows

Tracklists

I often only know an album name and none of the track titles or I only know the position in the tracklist. For this reason, I created a tool to provide an album tracklist. This function, genius_tracklist() takes the arguments artist and album. Simple enough, right?

Let’s get the tracklist for the original release of DAMN.. However, real Kendrick fans know that the album was intended to be listened to in chronological and reverse order—as is on the collector’s release.

damn_tracks <- genius_tracklist(artist = "Kendrick Lamar", album = "DAMN.")

# Collector's reverse order
damn_tracks %>% 
  arrange(-track_n)
## # A tibble: 14 x 3
##    track_title           track_n track_url                                 
##    <chr>                   <int> <chr>                                     
##  1 DUCKWORTH.                 14 https://genius.com/Kendrick-lamar-duckwor…
##  2 GOD.                       13 https://genius.com/Kendrick-lamar-god-lyr…
##  3 FEAR.                      12 https://genius.com/Kendrick-lamar-fear-ly…
##  4 XXX. (Ft. U2)              11 https://genius.com/Kendrick-lamar-xxx-lyr…
##  5 LOVE. (Ft. Zacari)         10 https://genius.com/Kendrick-lamar-love-ly…
##  6 LUST.                       9 https://genius.com/Kendrick-lamar-lust-ly…
##  7 HUMBLE.                     8 https://genius.com/Kendrick-lamar-humble-…
##  8 PRIDE.                      7 https://genius.com/Kendrick-lamar-pride-l…
##  9 LOYALTY. (Ft. Rihann…       6 https://genius.com/Kendrick-lamar-loyalty…
## 10 FEEL.                       5 https://genius.com/Kendrick-lamar-feel-ly…
## 11 ELEMENT.                    4 https://genius.com/Kendrick-lamar-element…
## 12 YAH.                        3 https://genius.com/Kendrick-lamar-yah-lyr…
## 13 DNA.                        2 https://genius.com/Kendrick-lamar-dna-lyr…
## 14 BLOOD.                      1 https://genius.com/Kendrick-lamar-blood-l…