Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rapgenius-js

kenshiro-o160.1.2

A client that queries the RapGenius (www.rapgenius.com) website

rap, rock, rapgenius, client, lyrics, music

readme

RapGenius-JS Build Status

rapgenius-js is a simple client that enables you to query RapGenius(www.rapgenius.com) and retrieve information about rap and rock artists and songs.

Rationale

This project was created because RapGenius do currently not support a node.js API.

Installation

$ npm install rapgenius-js

Usage

The API is very simple to use and currently enables you to perform the following:

Model objects

Artist

Artist
  - name: String
  - link: String
  - popularSongs: Array (of String)
  - songs: Array (of String)

Song

Song
  - name: String
  - artists: String
  - link: String

Lyrics

Verses
  - id: int
  - content: String
  - explanation: String

Section
  - name: String
  - content: String
  - verses: Array (of Verses)

Lyrics
  - songId: int
  - songTitle: String
  - mainArtist: String
  - featuringArtists: Array (of String)
  - producingArtists: Array (of String)
  - sections: Array (of Section)

Search for an artist:

var rapgeniusClient = require("rapgenius-js");

rapgeniusClient.searchArtist("GZA", "rap", function(err, artist){
  if(err){
    console.log("Error: " + err);
  }else{
    console.log("Rap artist found [name=%s, link=%s, popular-songs=%d]",
                artist.name, artist.link, artist.popularSongs.length);

  }
});

//Example for a rock artist
rapgeniusClient.searchArtist("Bruce Springsteen", "rock", function(err, artist){
  if(err){
    console.log("Error: " + err);
  }else{
    console.log("Rap artist found [name=%s, link=%s, popular-songs=%d]",
                artist.name, artist.link, artist.popularSongs.length);

  }
});

Search for a song:

var rapgeniusClient = require("rapgenius-js");

rapgeniusClient.searchSong("Liquid Swords", "rap", function(err, songs){
  if(err){
    console.log("Error: " + err);
  }else{
    console.log("Songs that matched the search query were found" +
                "[songs-found=%d, first-song-name=%s", songs.length, songs[0].name);
  }
});

Search for the lyrics of a song along with their meaning:

var rapgeniusClient = require("rapgenius-js");

var lyricsSearchCb = function(err, lyricsAndExplanations){
    if(err){
      console.log("Error: " + err);
    }else{
      //Printing lyrics with section names
      var lyrics = lyricsAndExplanations.lyrics;
      var explanations = lyricsAndExplanations.explanations;
      console.log("Found lyrics for song [title=%s, main-artist=%s, featuring-artists=%s, producing-artists=%s]",
        lyrics.songTitle, lyrics.mainArtist, lyrics.featuringArtists, lyrics.producingArtists);
      console.log("**** LYRICS *****\n%s", lyrics.getFullLyrics(true));

      //Now we can embed the explanations within the verses
      lyrics.addExplanations(explanations);
      var firstVerses = lyrics.sections[0].verses[0];
      console.log("\nVerses:\n %s \n\n *** This means ***\n%s", firstVerses.content, firstVerses.explanation);
    }
};

var searchCallback = function(err, songs){
  if(err){
    console.log("Error: " + err);
  }else{
    if(songs.length > 0){
      //We have some songs
      rapgeniusClient.searchLyricsAndExplanations(songs[0].link, "rap", lyricsSearchCb);
    }
  }
};

rapgeniusClient.searchSong("Liquid Swords", "rap", searchCallback);

Additional features

I will work on the following features when I get the time:

  • Refactor code base
  • Improve performance

Licence

MIT (Make It Tremendous)

changelog

0.1.2 / 2014-06-28

  • Fixed tests that were broken with new updated HTML code of RapGenius.

0.1.1 / 2014-04-12

  • Added examples in folder
  • Fixed bugs

0.1.0 / 2014-02-02

  • Non backwards compatible changes introduced:
  • you can now search rock and rap artists, songs, and annotations by passing the type parameter
  • Also performed some refactoring

0.0.7 / 2013-12-26

  • Adding extra fields to RapLyrics model object:
  • songTitle
  • mainArtist
  • featuringArtists
  • producingArtists

0.0.5 / 2013-01-27

  • Refactored RapLyrics model object
  • Added new feature to retrieve lyrics and their meaning

0.0.4 / 2013-01-27

  • Renaming main .js file from "genuisClient.js" to "geniusClient.js"

0.0.3 / 2013-01-26

  • Integrating with Travis and fixing all bugs that come with it...

    0.0.2 / 2013-01-25

  • Release with more bug fixes
  • Also added unit tests

0.0.1 / 2013-01-18

  • Initial release