genius-lyrics-api
A package that provides a convenient wrapper around Genius API for searching and scraping song lyrics.
It doesn't use any native node dependencies and thus, can be used with any frontend frameworks/lib.
Installation
Install with npm
npm install --save genius-lyrics-api
Or install with Yarn
yarn add genius-lyrics-api
Usage
import { getLyrics } from 'genius-lyrics-api';
const options = {
apiKey: 'XXXXXXXXXXXXXXXXXXXXXXX',
title: 'Blinding Lights',
artist: 'The Weeknd',
optimizeQuery: true
};
getLyrics(options).then(lyrics => console.log(lyrics));
:warning: If you're using this in a frontend web app and testing on localhost, you might get a CORS block error. To bypass this, you need to disable Same-Origin Policy in your browser. Follow the instructions here.
Methods
genius-lyrics-api exposes the following methods:
getLyrics(options)
Automatically get the lyrics from genius.com using the title
& artist
fields.
Returns a promise that resolves to a string containing lyrics. Throws an error if lyrics are not found.
Arguments
const options = {
apiKey: string,
title: string,
artist: string,
optimizeQuery: boolean
};
All properties in the options
object are required except optimizeQuery
. If either of the title
or artist
is unknown, pass an empty string as its value.
searchLyrics(options)
Search lyrics from genius.com using the title
& artist
fields.
Returns a promise that resolves to an array of search results. Throws an error if no matches are found.
Receives the same arguments as getLyrics
.
getLyricsFromPath(path: string)
Get the lyrics of a song using the path
property present in the search results of searchLyrics
method.
Returns a promise that resolves to a string containing lyrics.