The geniusr
package is designed to help you retrieve data from Genius. Most of this data falls into one of two camps:
Both of these areas will be introduced momentarily, once API authentication is dealt with.
geniusr
data retrieval is typically done by making authenticated requests to the Genius API. This necessitates a few common steps:
GENIUS_API_TOKEN
environment variable by explicitly calling the genius_token()
function, or when prompted by other functionsOnce you have set the GENIUS_API_TOKEN
environment variable, it will be active for the rest of the session and automatically called (via genius_token()
) when using geniusr
functions to request data.
The first family of data retrieval functions help with accessing data from various types of Genius Resources, explored in turn below.
Functions for requesting data on songs hosted on Genius take the form get_song_xxx()
. For example, get_song()
returns details about the song itself, as well as user annotations that are attached to it, as a list.
Let’s get details about the track Sing About Me, I’m Dying of Thirst by Kendrick Lamar.
get_song(song_id = 90479)
#> <Genius api.genius.com/songs/90479>
#> List of 38
#> $ annotation_count : int 97
#> $ api_path : chr "/songs/90479"
#> $ apple_music_id : chr "624345722"
#> $ apple_music_player_url : chr "https://genius.com/songs/90479/apple_music_player"
#> $ description :List of 1
#> $ embed_content : chr "<div id='rg_embed_link_90479' class='rg_embed_link' data-song-id='90479'>Read <a href='https://genius.com/Kendr"| __truncated__
#> $ fact_track :List of 5
#> $ featured_video : logi FALSE
#> $ full_title : chr "Sing About Me, I'm Dying of Thirst by Kendrick Lamar"
#> $ header_image_thumbnail_url : chr "https://images.genius.com/f3db37bb8953d6e671d8bb532da2e855.220x220x1.jpg"
#> $ header_image_url : chr "https://images.genius.com/f3db37bb8953d6e671d8bb532da2e855.220x220x1.jpg"
#> $ id : int 90479
#> $ lyrics_owner_id : int 121065
#> $ lyrics_state : chr "complete"
#> $ path : chr "/Kendrick-lamar-sing-about-me-im-dying-of-thirst-lyrics"
#> $ pyongs_count : int 128
#> $ recording_location : chr "TDE Red Room, Carson, CA"
#> $ release_date : chr "2012-10-22"
#> $ song_art_image_thumbnail_url: chr "https://images.genius.com/f3db37bb8953d6e671d8bb532da2e855.220x220x1.jpg"
#> $ song_art_image_url : chr "https://images.genius.com/f3db37bb8953d6e671d8bb532da2e855.220x220x1.jpg"
#> $ stats :List of 9
#> $ title : chr "Sing About Me, I’m Dying of Thirst"
#> $ title_with_featured : chr "Sing About Me, I'm Dying of Thirst"
#> $ url : chr "https://genius.com/Kendrick-lamar-sing-about-me-im-dying-of-thirst-lyrics"
#> $ current_user_metadata :List of 5
#> $ album :List of 7
#> $ custom_performances :List of 7
#> $ description_annotation :List of 15
#> $ featured_artists : list()
#> $ lyrics_marked_complete_by : NULL
#> $ media :List of 3
#> $ primary_artist :List of 9
#> $ producer_artists :List of 2
#> $ song_relationships :List of 10
#> $ verified_annotations_by :List of 1
#> $ verified_contributors :List of 1
#> $ verified_lyrics_by : list()
#> $ writer_artists :List of 6
Functions for requesting data on an artist (i.e. the creator of one or more songs hosted on Genius) take the form get_artist_xxx()
. For example, get_artist()
returns details about the artist as a list.
For example, here’s some more info about the artist Kendrick Lamar.
get_artist(artist_id = 1421)
#> <Genius api.genius.com/artists/1421>
#> List of 19
#> $ alternate_names :List of 5
#> $ api_path : chr "/artists/1421"
#> $ description :List of 1
#> $ facebook_name : chr "kendricklamar"
#> $ followers_count : int 23770
#> $ header_image_url : chr "https://images.genius.com/f3a1149475f2406582e3531041680a3c.1000x800x1.jpg"
#> $ id : int 1421
#> $ image_url : chr "https://images.genius.com/25d8a9c93ab97e9e6d5d1d9d36e64a53.1000x1000x1.jpg"
#> $ instagram_name : chr "kendricklamar"
#> $ is_meme_verified : logi TRUE
#> $ is_verified : logi TRUE
#> $ name : chr "Kendrick Lamar"
#> $ translation_artist : logi FALSE
#> $ twitter_name : chr "kendricklamar"
#> $ url : chr "https://genius.com/artists/Kendrick-lamar"
#> $ current_user_metadata :List of 3
#> $ iq : int 39088
#> $ description_annotation:List of 15
#> $ user :List of 11
Functions for requesting data on an album take the form get_album_xxx()
. For example, get_album()
returns details about the artist as a list.
We can get data on the album Good Kid, M.A.A.D City by Kendrick Lamar.
get_album(album_id = 491200)
#> <Genius api.genius.com/albums/491200>
#> List of 20
#> $ api_path : chr "/albums/491200"
#> $ comment_count : int 0
#> $ cover_art_url : chr "https://images.genius.com/1efc5de2af228d2e49d91bd0dac4dc49.1000x1000x1.jpg"
#> $ custom_header_image_url: NULL
#> $ full_title : chr "good kid, m.A.A.d city (Deluxe Version) by Kendrick Lamar"
#> $ header_image_url : chr "https://images.genius.com/1efc5de2af228d2e49d91bd0dac4dc49.1000x1000x1.jpg"
#> $ id : int 491200
#> $ lock_state : chr "editable"
#> $ name : chr "good kid, m.A.A.d city (Deluxe Version)"
#> $ pyongs_count : int 6
#> $ release_date : chr "2012-10-22"
#> $ release_date_components:List of 3
#> $ url : chr "https://genius.com/albums/Kendrick-lamar/Good-kid-m-a-a-d-city-deluxe-version"
#> $ current_user_metadata :List of 3
#> $ song_pageviews : int 38743553
#> $ artist :List of 9
#> $ cover_arts :List of 1
#> $ description_annotation :List of 15
#> $ performance_groups : list()
#> $ song_performances :List of 24
Functions for searching all content hosted on Genius take the form search_xxx()
. For example, search_genius()
returns documents matching a search term(s) as a list.
We can look for documents that match the search term “Compton”.
There are also tools to be found in geniusr
that help with Genius lyrics retrieval. These functions take the form…you guessed it…get_lyrics_xxx()
. For example, get_lyrics_id()
finds song lyrics for a given song id.
To complete the look, let’s get song lyrics for Sing About Me, I’m Dying of Thirst.
get_lyrics_id(song_id = 90479)
#> # A tibble: 244 x 6
#> line section_name section_artist song_name artist_name song_id
#> <chr> <chr> <chr> <chr> <chr> <dbl>
#> 1 When the l… Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 2 To settle … Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 3 Promise th… Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 4 Promise th… Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 5 I said whe… Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 6 To settle … Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 7 Promise th… Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 8 Promise th… Chorus Kendrick Lamar Sing About … Kendrick L… 90479
#> 9 I woke up … Verse 1 Kendrick Lamar Sing About … Kendrick L… 90479
#> 10 In case I'… Verse 1 Kendrick Lamar Sing About … Kendrick L… 90479
#> # … with 234 more rows