0

I create a dataset that contains all the original songs of Beatles. And I want to get the lyrics of all the songs using genius package. I use the following code to get lyrics but throw an error.

map(beatles_songs$song, ~ genius_lyrics("The Beatles", ., "simple"))
Error in read_xml.response(x$response, ..., as_html = as_html) : 
  Not Found (HTTP 404).
In addition: Warning message:
In request_GET(session, url) : Not Found (HTTP 404).

I think maybe this is because the names of songs in the list don't match the songs in genius.com, but I don't know how to check it. So what should I do to get lyrics of all the songs at the same time?

juby
  • 132
  • 1
  • 5

2 Answers2

0

The purrr package has a number functions that handle warnings and errors. I'd suggest something like the following, inspired by this example:

genius_lyrics_s <- safely(genius::genius_lyrics)

beatles_songs <- tibble(song = c("Mr. Moonlight", "She Loves You", "Under my Thumb", "Octopus's Garden"))
map(beatles_songs$song, ~ genius_lyrics_s("The Beatles", ., "simple")) %>% 
map("result") %>%
  compact()
David Klotz
  • 2,401
  • 1
  • 7
  • 16
  • This definitely will work but the desired way to do the above would be to use the `add_genius()` function – thus__ Sep 24 '19 at 12:22
0

In your case the best way to get song results would be to use add_genius().

beatles %>%
  add_genius("The Beatles", song)

The genius package has the functions possible_lyrics() and possible_album() for just this reason. Try that out next time!

thus__
  • 460
  • 3
  • 16