lyrics.ovh API

Author

J. Farmer

Introduction

This API finds the lyrics for a song based on the song’s artist and title. Someone could use this API to get the lyrics to a song in R. They may want to analyze the lyrics of an individual song or analyze an artist’s writing style.

Example of Code/ Setting Up

After loading in the necessary packages, the base URL needs to be defined for the API endpoint. After this, we need to create two variables, one with artist and one with title. The user can put in any artist, and then put in any song that artist wrote. It is important to note that for any title/ artist that are more than one word, “%20” needs to be put in those spaces. For my example, I chose The Beatles hit song, Hey Jude. That would look like “The%20Beatles” “Hey%20Jude”.

lyrics_endpoint <- "https://api.lyrics.ovh/v1/"

artist <- "The%20Beatles"
title <- "Hey%20Jude"

The Output

After this, the full URL needs to be built, this means artist and title need to be included in the URL. We can use the GET function to request the API and make sure that the status code is 200. If the status code is not 200, there may need to be some troubleshooting and debugging. Lastly, we can print the result. The output for this will be the complete lyrics to whatever song was put into the API earlier in the code.

lyrics_url <- paste0(lyrics_endpoint, artist, "/", title)

l_response <- GET(lyrics_url)

if (status_code(l_response) == 200) {
  lyrics_data <- content(l_response, "parsed")
    print(lyrics_data$lyrics)
} else {
  print(paste("Error:", status_code(l_response)))}
[1] "Hey Jude, don't make it bad.\r\nTake a sad song and make it better.\r\nRemember to let her into your heart,\r\nThen you can start to make it better.\r\nHey Jude, don't be afraid.\n\nYou were made to go out and get her.\n\nThe minute you let her under your skin,\n\nThen you begin to make it better.\n\n\n\nAnd anytime you feel the pain, hey Jude, refrain,\n\nDon't carry the world upon your shoulders.\n\nFor well you know that it's a fool who plays it cool\n\nBy making his world a little colder.\n\n\n\nHey Jude, don't let me down.\n\nYou have found her, now go and get her.\n\nRemember to let her into your heart,\n\nThen you can start to make it better.\n\n\n\nSo let it out and let it in, hey Jude, begin,\n\nYou're waiting for someone to perform with.\n\nAnd don't you know that it's just you, hey Jude, you'll do,\n\nThe movement you need is on your shoulder.\n\n\n\nHey Jude, don't make it bad.\n\nTake a sad song and make it better.\n\nRemember to let her under your skin,\n\nThen you'll begin to make it\n\nBetter better better better better better, oh.\n\n\n\nNa na na nananana, nananana, hey Jude..."

Wrapping Up

Above this you will see the lyrics to my example, Hey Jude. I tried this API for over ten different artists, and it worked every time. This is an efficient way to get song lyrics into R so they can be analyzed.