https://github.com/farshed/genius-lyrics-api
A library for accessing song lyrics & album covers from genius.com 🎤 🎶
https://github.com/farshed/genius-lyrics-api
genius lyrics nodejs song-lyrics
Last synced: 8 months ago
JSON representation
A library for accessing song lyrics & album covers from genius.com 🎤 🎶
- Host: GitHub
- URL: https://github.com/farshed/genius-lyrics-api
- Owner: farshed
- License: mit
- Created: 2019-11-20T19:37:18.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-07T12:06:11.000Z (over 1 year ago)
- Last Synced: 2025-04-01T19:39:49.907Z (8 months ago)
- Topics: genius, lyrics, nodejs, song-lyrics
- Language: JavaScript
- Homepage:
- Size: 2.74 MB
- Stars: 238
- Watchers: 4
- Forks: 37
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# genius-lyrics-api [](https://www.npmjs.com/package/genius-lyrics-api)
A JavaScript package for non-browser environments that leverages [Genius API](https://genius.com/developers) to find (and scrape) song lyrics and album covers.
## Installation
Install with npm
```js
npm install --save genius-lyrics-api
```
Or install with Yarn
```js
yarn add genius-lyrics-api
```
## Usage
[Get the Genius Developer Access Token](https://genius.com/developers)
```js
import { getLyrics, getSong } from 'genius-lyrics-api';
```
```js
const options = {
apiKey: 'XXXXXXXXXXXXXXXXXXXXXXX',
title: 'Posthumous Forgiveness',
artist: 'Tame Impala',
optimizeQuery: true
};
getLyrics(options).then((lyrics) => console.log(lyrics));
getSong(options).then((song) =>
console.log(`${song.id} - ${song.title} - ${song.url} - ${song.albumArt} - ${song.lyrics}`)
);
```
## Types
```
type options {
title: string;
artist: string;
apiKey: string; // Genius developer access token
optimizeQuery?: boolean; // (optional, default: false) If true, perform some cleanup to maximize the chance of finding a match
authHeader?: boolean; // (optional, default: false) Whether to include auth header in the search request
}
```
🚨 If `title` or `artist` is unknown, pass an empty string.
```
type song {
id: number; // Genius song id
title: string; // Song title
url: string; // Genius webpage URL for the song
lyrics: string; // Song lyrics
albumArt: string; // URL of the album art image (jpg/png)
}
```
```
type searchResult {
id: number; // Genius song id
url: string; // Genius webpage URL for the song
title: string; // Song title
albumArt: string; // URL of the album art image (jpg/png)
}
```
## Methods
genius-lyrics-api exposes the following methods:
### `getLyrics(options | url)`
Accepts [options](#types) or the url to a Genius song.
Returns a promise that resolves to a string containing lyrics. Returns `null` if no lyrics are found.
### `getAlbumArt(options)`
Accepts an [options](#types) object.
Returns a promise that resolves to a url (string) to the song's album art. Returns `null` if no url is found.
### `getSong(options)`
Accepts an [options](#types) object.
Returns a promise that resolves to an object of type [song](#types). Returns `null` if song is not found.
### `searchSong(options)`
Accepts an [options](#types) object.
Returns a promise that resolves to an array of type [searchResult](#types). Returns `null` if no matches are found.
### `getSongById(id: (number | string), access_token: string)`
Accepts a valid Genius song ID. IDs can be found using the `searchSong` method.
Returns a promise that resolves to an object of type [song](#types).