songs

Author

Prof. Eric A. Suess

I read the Medium post Introducing geniusR a while ago and gave it a try. Since then this package has become the genius package, without the R. This package give access to the genius website so we can load song lyrics into R. This package does not require an API key.

Alternatively: There are other packages that could be used to download song lyrics and other packages to download other information about songs. But they all seem to require registering to obtain an API keys.

  1. The geniusr package is an alternative to the genius package. Notice this is a different package then the package with a captial R, that became the genius package.
  2. The discogger package can be installed from github. It can be used to download songs from the discogs website.
  3. The spotifyr can be used to connect to the Spotify API.
library(pacman)

p_load(geniusr, tidyverse, tidytext, tm, wordcloud)
genius_token()
[1] "d_hruICKZd3N5bgmDkksbf371JW4EAeR1Km4P_u6GEtRB3P-Kr17jdImS2W-Efzz"

How many times does Kanye West say Good Morning in his song Good Morning?

get_lyrics_search(artist_name = "Kanye West",
                  song_title = "Good Morning") %>% 
  # get lyric bigrams
  unnest_tokens(bigram, line, token = "ngrams", n = 2) %>%
  # look for good morning
  filter(bigram == "good morning") %>% 
  # count bigram frequency
  nrow()
[1] 18

Lets download the lyrics for the Jimi Hendrix song Purple Haze from Genius.

Jimi_Purple_Haze <- get_lyrics_search(artist_name = 
                               "The Jimi Hendrix Experience", 
                               song_title = "Purple Haze")
Jimi_Purple_Haze
# A tibble: 23 × 5
   line                        section_name section_artist song_name artist_name
   <chr>                       <chr>        <chr>          <chr>     <chr>      
 1 Purple haze all in my brain Verse 1      The Jimi Hend… Purple H… The Jimi H…
 2 Lately things, they don't … Verse 1      The Jimi Hend… Purple H… The Jimi H…
 3 Acting funny, but I don't … Verse 1      The Jimi Hend… Purple H… The Jimi H…
 4 'Scuse me while I kiss the… Verse 1      The Jimi Hend… Purple H… The Jimi H…
 5 Purple haze all around      Verse 2      The Jimi Hend… Purple H… The Jimi H…
 6 Don't know if I'm coming u… Verse 2      The Jimi Hend… Purple H… The Jimi H…
 7 Am I happy or in misery?    Verse 2      The Jimi Hend… Purple H… The Jimi H…
 8 Whatever it is, that girl … Verse 2      The Jimi Hend… Purple H… The Jimi H…
 9 Help me! Help me!           Verse 2      The Jimi Hend… Purple H… The Jimi H…
10 Ah no, no                   Verse 2      The Jimi Hend… Purple H… The Jimi H…
# ℹ 13 more rows

Search Genius for Jim Hendrix songs.

search_artist(search_term = "Jimi Hendrix")
# A tibble: 1 × 3
  artist_id artist_name                 artist_url                              
      <int> <chr>                       <chr>                                   
1    634985 The Jimi Hendrix Experience https://genius.com/artists/The-jimi-hen…
Jimi <- search_genius(search_term = "Jimi Hendrix")
Jimi
<Genius api.genius.com/search?q=Jimi Hendrix>
List of 10
 $ :List of 24
 $ :List of 24
 $ :List of 24
 $ :List of 24
 $ :List of 24
 $ :List of 24
 $ :List of 24
 $ :List of 24
 $ :List of 24
 $ :List of 24
get_song_df(song_id = 65315)
# A tibble: 1 × 13
  song_id song_name   song_lyrics_url       song_art_image_url song_release_date
    <int> <chr>       <chr>                 <chr>              <chr>            
1   65315 Purple Haze https://genius.com/T… https://images.ge… 1967-05-12       
# ℹ 8 more variables: song_pageviews <int>, song_annotation_count <int>,
#   artist_id <int>, artist_name <chr>, artist_url <chr>, album_id <int>,
#   album_name <chr>, album_url <chr>
Jimi_songs <- get_album_tracklist_search(artist_name = "Jimi Hendrix",
album_name = "Are You Experienced [US Version]")

Jimi_songs
# A tibble: 11 × 3
   song_number song_title               song_lyrics_url                         
         <dbl> <chr>                    <chr>                                   
 1           1 Purple Haze              https://genius.com/The-jimi-hendrix-exp…
 2           2 Manic Depression         https://genius.com/The-jimi-hendrix-exp…
 3           3 Hey Joe                  https://genius.com/The-jimi-hendrix-exp…
 4           4 Love or Confusion        https://genius.com/The-jimi-hendrix-exp…
 5           5 May This Be Love         https://genius.com/The-jimi-hendrix-exp…
 6           6 I Don't Live Today       https://genius.com/The-jimi-hendrix-exp…
 7           7 The Wind Cries Mary      https://genius.com/The-jimi-hendrix-exp…
 8           8 Fire                     https://genius.com/The-jimi-hendrix-exp…
 9           9 Third Stone from the Sun https://genius.com/The-jimi-hendrix-exp…
10          10 Foxey Lady               https://genius.com/The-jimi-hendrix-exp…
11          11 Are You Experienced?     https://genius.com/The-jimi-hendrix-exp…
Jimi_lyrics <- rbind(
                   get_lyrics_search(artist_name = 
                               "The Jimi Hendrix Experience", 
                               song_title = "Purple Haze"),
                   get_lyrics_search(artist_name = 
                               "The Jimi Hendrix Experience", 
                               song_title = "Manic Depression"),
                   get_lyrics_search(artist_name = 
                               "The Jimi Hendrix Experience", 
                               song_title = "Hey Joe")
                   )
Jimi_lyrics
# A tibble: 78 × 5
   line                        section_name section_artist song_name artist_name
   <chr>                       <chr>        <chr>          <chr>     <chr>      
 1 Purple haze all in my brain Verse 1      The Jimi Hend… Purple H… The Jimi H…
 2 Lately things, they don't … Verse 1      The Jimi Hend… Purple H… The Jimi H…
 3 Acting funny, but I don't … Verse 1      The Jimi Hend… Purple H… The Jimi H…
 4 'Scuse me while I kiss the… Verse 1      The Jimi Hend… Purple H… The Jimi H…
 5 Purple haze all around      Verse 2      The Jimi Hend… Purple H… The Jimi H…
 6 Don't know if I'm coming u… Verse 2      The Jimi Hend… Purple H… The Jimi H…
 7 Am I happy or in misery?    Verse 2      The Jimi Hend… Purple H… The Jimi H…
 8 Whatever it is, that girl … Verse 2      The Jimi Hend… Purple H… The Jimi H…
 9 Help me! Help me!           Verse 2      The Jimi Hend… Purple H… The Jimi H…
10 Ah no, no                   Verse 2      The Jimi Hend… Purple H… The Jimi H…
# ℹ 68 more rows
Jimi_lyrics2 <- Jimi_lyrics %>% 
  select(line, song_name)
Jimi_lyrics2
# A tibble: 78 × 2
   line                                        song_name  
   <chr>                                       <chr>      
 1 Purple haze all in my brain                 Purple Haze
 2 Lately things, they don't seem the same     Purple Haze
 3 Acting funny, but I don't know why          Purple Haze
 4 'Scuse me while I kiss the sky              Purple Haze
 5 Purple haze all around                      Purple Haze
 6 Don't know if I'm coming up or down         Purple Haze
 7 Am I happy or in misery?                    Purple Haze
 8 Whatever it is, that girl put a spell on me Purple Haze
 9 Help me! Help me!                           Purple Haze
10 Ah no, no                                   Purple Haze
# ℹ 68 more rows
par(mfrow=c(1,3))

Jimi_lyrics2 %>% filter(song_name == "Purple Haze") %>% 
  select(line) %>%
  unnest_tokens(word, line) %>%
  count(word, sort = TRUE) %>%
  with(wordcloud(word, n))

Jimi_lyrics2 %>% filter(song_name == "Manic Depression") %>% 
  select(line) %>%
  unnest_tokens(word, line) %>%
  count(word, sort = TRUE) %>%
  with(wordcloud(word, n))

Jimi_lyrics2 %>% filter(song_name == "Hey Joe") %>% 
  select(line) %>%
  unnest_tokens(word, line) %>%
  count(word, sort = TRUE) %>%
  with(wordcloud(word, n))