Rob Weyant bio photo

Rob Weyant

Data Scientist at Powerley

Twitter LinkedIn Instagram Github Last.fm

Musixmatch is a website that has lots of data on musicians, their album, songs and lyrics. They’ve created an API, which anyone can use to collect data, such as lyrics, genres, album and track metadata, and much more. The goal of this API wrapper is to facilitate using the API in R, and collecting data in a convenient fashion

Installation

devtools::install_github('rweyant/musixmatch')

Basic Usage

First, you need to get an API Key.

library(musixmatch)

# Set API key in a place all the functions have access to
set_apikey(YOUR_APIKEY)

Get basic data

Search for specific artists

Here you can find basic information about artists that match the search term. If you specify simplify=FALSE the result is the full XML document parsed.

# Return list of full XML result in a list
result <- search_artist(q_artist = 'slayer',simplify=FALSE)

Otherwise, a simplified data.frame is returned.

# Return data.frame of most useful fields to identify artist
head(search_artist('slayer'))
Error in xmlToDataFrame(nodes = getNodeSet(xml, "//artist/artist_id"), : error in evaluating the argument 'nodes' in selecting a method for function 'xmlToDataFrame': Error: Please install xml2 package

Get Artist Discography

This function identifies artists using the artist_id returned from the previous function. It returns all the albums (sometimes multiple versions of an album) musixmatch has listed for an artist. You can similarly get the full XML document as a list using the simplify=FALSE option.

head(get_artist_albums(2683))
Error in xmlToDataFrame(nodes = getNodeSet(xml, "//album/album_id"), stringsAsFactors = FALSE): error in evaluating the argument 'nodes' in selecting a method for function 'xmlToDataFrame': Error: Please install xml2 package

Next Steps

Currently supports all methods for the musixmatch API (e.g. track.lyrics.get, album.tracks.get, artist.related..get). Not all methods have a simplify option yet, but these options are being actively developed. Check the GitHub for updates.

More Resources