genius Basics

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.

# Load needed libraries
library(genius)
library(dplyr)

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: 74 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 piece, g…
#>  3 DNA.            3 I got hustle though, ambition flow inside my DNAI was born…
#>  4 DNA.            4 I transform like this, perform like this, was Yeshua new w…
#>  5 DNA.            5 I don't contemplate, I meditate, then off your fucking head
#>  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 mill…
#>  9 DNA.            9 I got off, I got troublesome heart inside my DNAI just win…
#> 10 DNA.           10 Yeah, that's him again, the sound that engine in is like a…
#> # … with 64 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: 74 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 quart… Verse 1 Kendrick Lamar
#>  3     3 I got hustle though, ambition flow inside my DN… Verse 1 Kendrick Lamar
#>  4     4 I transform like this, perform like this, was Y… Verse 1 Kendrick Lamar
#>  5     5 I don't contemplate, I meditate, then off your … 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 my DN… Verse 1 Kendrick Lamar
#>  9     9 I got off, I got troublesome heart inside my DN… Verse 1 Kendrick Lamar
#> 10    10 Yeah, that's him again, the sound that engine i… Verse 1 Kendrick Lamar
#> # … with 64 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("album_name", "track_n", "track_url")

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

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, type = "album")
#> Joining, by = c("album_name", "track_n", "track_url")
#> Joining, by = c("album_name", "track_n", "track_url")
#> Joining, by = c("artist", "album")
#> # A tibble: 1,292 x 6
#>    artist  album track_n  line lyric                                 track_title
#>    <chr>   <chr>   <int> <int> <chr>                                 <chr>      
#>  1 J. Cole KOD         1     1 "Can someone please turn off my mind… Intro (KOD)
#>  2 J. Cole KOD         1     2 "My thoughts are racing all the time" Intro (KOD)
#>  3 J. Cole KOD         1     3 "There is no reason or no rhyme"      Intro (KOD)
#>  4 J. Cole KOD         1     4 "I'm trapped inside myself"           Intro (KOD)
#>  5 J. Cole KOD         1     5 "A newborn baby has two primary mode… Intro (KOD)
#>  6 J. Cole KOD         1     6 "Laughter, which says, \"I love this… Intro (KOD)
#>  7 J. Cole KOD         1     7 "Or crying, which says, \"This frigh… Intro (KOD)
#>  8 J. Cole KOD         1     8 "There are many ways to deal with th… Intro (KOD)
#>  9 J. Cole KOD         1     9 "Choose wisely"                       Intro (KOD)
#> 10 J. Cole KOD         1    10 "At the bottom of the hourglass"      Intro (KOD)
#> # … with 1,282 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 niggas    
#>  7 J. Cole Motiv8 Motiv8          7 All this shit I've seen done made my blood …
#>  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 Double Stu…
#> 10 J. Cole Motiv8 Motiv8         10 Please don't hit my phone if it ain't 'bout…
#> # … 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 4
#>    album_name track_title         track_n track_url                             
#>    <chr>      <chr>                 <int> <chr>                                 
#>  1 DAMN.      DUCKWORTH.               14 https://genius.com/Kendrick-lamar-duc…
#>  2 DAMN.      GOD.                     13 https://genius.com/Kendrick-lamar-god…
#>  3 DAMN.      FEAR.                    12 https://genius.com/Kendrick-lamar-fea…
#>  4 DAMN.      XXX. (Ft. U2)            11 https://genius.com/Kendrick-lamar-xxx…
#>  5 DAMN.      LOVE. (Ft. Zacari)       10 https://genius.com/Kendrick-lamar-lov…
#>  6 DAMN.      LUST.                     9 https://genius.com/Kendrick-lamar-lus…
#>  7 DAMN.      HUMBLE.                   8 https://genius.com/Kendrick-lamar-hum…
#>  8 DAMN.      PRIDE.                    7 https://genius.com/Kendrick-lamar-pri…
#>  9 DAMN.      LOYALTY. (Ft. Riha…       6 https://genius.com/Kendrick-lamar-loy…
#> 10 DAMN.      FEEL.                     5 https://genius.com/Kendrick-lamar-fee…
#> 11 DAMN.      ELEMENT.                  4 https://genius.com/Kendrick-lamar-ele…
#> 12 DAMN.      YAH.                      3 https://genius.com/Kendrick-lamar-yah…
#> 13 DAMN.      DNA.                      2 https://genius.com/Kendrick-lamar-dna…
#> 14 DAMN.      BLOOD.                    1 https://genius.com/Kendrick-lamar-blo…