`Not Found (HTTP 404)` error when using `genius` package to get lyrics

348 Views Asked by At

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?

2

There are 2 best solutions below

1
On BEST ANSWER

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()
0
On

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!