--- title: "genius Example with Jimi Hendrix and the Beatles" output: pdf_document: default html_notebook: default word_document: default --- I read the Medium post [Introducing geniusR](https://medium.com/@JosiahParry/introducing-geniusr-b0177ce7b4d7) a while ago and gave it a try. Since then this package has become the [genius](https://github.com/JosiahParry/genius) package, without the R. This package give access to the [genius](https://genius.com/) 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](https://github.com/JosiahParry/genius) package. Notice this is a different package then the package with a captial R, that became the genius package. 2. The [discogger](https://ewenme.github.io/discogger/) package can be installed from github. It can be used to download songs from the [discogs](https://www.discogs.com/) website. 3. The [spotifyr](https://www.rcharlie.com/spotifyr/) can be used to connect to the [Spotify](https://www.spotify.com/us/) API. ```{r} library(pacman) p_load(genius, tidyverse, tidytext, tm, wordcloud) ``` ```{r} Jimi_Are_You_Experienced <- genius_album(artist = "The Jimi Hendrix Experience", album = "Are You Experienced [US Version]") Jimi_Are_You_Experienced ``` ```{r} Jimi_songs <- Jimi_Are_You_Experienced %>% select(track_title) %>% group_by(track_title) %>% summarise(lines = n()) ``` ```{r} Jimi_songs2 <- Jimi_songs %>% select(track_title) Jimi_songs2 ``` ```{r, warning=FALSE} par(mfrow=c(3,4)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Are You Experienced?") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Fire") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Foxy Lady") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Hey Joe") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="I Don't Live Today") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Love or Confusion") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Manic Depression") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="May This Be Love") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Purple Haze") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="The Wind Cries Mary") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% filter(track_title=="Third Stone from the Sun") %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) Jimi_lyric <- Jimi_Are_You_Experienced %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) ``` ```{r} Jimi_lyric <- Jimi_Are_You_Experienced %>% select(lyric) %>% unnest_tokens(word, lyric) %>% count(word, sort = TRUE) %>% with(wordcloud(word, n)) ``` ```{r} third_stone <- genius_lyrics(artist = "The Jimi Hendrix Experience", song = "Third Stone From The Sun") third_stone ``` ```{r} The_Beatles_td <- genius_album(artist = "The Beatles", album = "Let It Be") The_Beatles_td The_Beatles_td %>% filter(track_n == 6) The_Beatles_Let_It_be <- genius_lyrics(artist = "The Beatles", song = "Let It Be") The_Beatles_Let_It_be The_Beatles_Let_It_be_td <- The_Beatles_Let_It_be %>% select(lyric, track_title) %>% unnest_tokens(word, lyric) The_Beatles_Let_It_be_td The_Beatles_Let_It_be_sentiments <- The_Beatles_Let_It_be_td %>% inner_join(get_sentiments("bing"), by = c(word = "word")) The_Beatles_Let_It_be_sentiments The_Beatles_Let_It_be_sentiments %>% count(sentiment, word) %>% ungroup() %>% mutate(n = ifelse(sentiment == "negative", -n, n)) %>% mutate(word = reorder(word, n)) %>% ggplot(aes(word, n, fill = sentiment)) + geom_bar(stat = "identity") + ylab("Contribution to sentiment") + coord_flip() The_Beatles_Let_It_be_dtm <- The_Beatles_Let_It_be_td %>% count(track_title, word) %>% cast_dtm(track_title, word, n) The_Beatles_Let_It_be_dtm Terms(The_Beatles_Let_It_be_dtm) tidy(The_Beatles_Let_It_be_dtm) ``` ```{r} # Example with 2 different artists and albums artist_albums <- tribble( ~artist, ~album, "The Beatles", "Let It Be", "The Jimi Hendrix Experience", "Are You Experienced [US Version]" ) artist_albums albums_td <- artist_albums %>% add_genius(artist, album) albums_td ```