https://github.com/alenvelocity/ultra-lyrics
Genius Scraper and API Wraper
https://github.com/alenvelocity/ultra-lyrics
genius genius-api lyrics music
Last synced: about 1 year ago
JSON representation
Genius Scraper and API Wraper
- Host: GitHub
- URL: https://github.com/alenvelocity/ultra-lyrics
- Owner: AlenVelocity
- Created: 2021-08-08T11:57:30.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-09T15:18:26.000Z (almost 5 years ago)
- Last Synced: 2025-03-18T15:42:28.390Z (about 1 year ago)
- Topics: genius, genius-api, lyrics, music
- Language: TypeScript
- Homepage: https://alensaito1.github.io/ultra-lyrics/
- Size: 350 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ultra-Lyrics

Ultra-Lyrics is a package which fetches the [Genius](https://img.icons8.com/color/144/000000/music--v2.png) API and uses the data to scrap the lyrics from the actual website. Occasionally paired with [Spotifydl-Core](https://www.npmjs.com/package/spotifydl-core)
Read Docs Here: [Docs](https://alensaito1.github.io/ultra-lyrics/)
## Install
```
npm i ultra-lyrics
```
## Usage
> Note:
> To authenticate with a [Genius access token](https://docs.genius.com/#/authentication-h1), you need to add it to [`process.env`](https://nodejs.org/dist/latest-v14.x/docs/api/process.html#process_process_env) as an ENV Variable or usign [`dotenv`](https://www.npmjs.com/package/dotenv) wth the name as `GENIUS_ACCESS_TOKEN`
> Search for songs
```TS
import { search } from 'ultra-lyrics'
// const { search } = require('ultra-lyrics')
(async () => {
const { data, error } = await search('Blue Clapper')
if (error instanceof Error) console.error('An error occurred', error)
else console.log('Results', data)
})()
```
> Get Lyrics
```TS
import { search, getLyrics } from 'ultra-lyrics'
// const { search } = require('ultra-lyrics')
(async () => {
let { data: results, error } = await search('Precious Photographs')
if (error instanceof Error) console.error('An error occurred while searching', error)
else {
const { data, error } = await getLyrics(results[0]) // you can also pass the title too
if (error) console.error('An error occurred while fetching lyrics', error)
else console.log('Lyrics', data)
}
})()
```
> Get Song
```TS
import { getSong } from 'ultra-lyrics'
// const { search } = require('ultra-lyrics')
(async () => {
const { data, error } = await getSong('Dreaming Days')
if (error instanceof Error) console.error('An error occurred', error)
else console.log('Song', data)
})()
```
As of right now, ultra-lyrics exports 3 functions. All of them will return a Promise of the object of type [`UltraLyricsFunctionReturnType`](https://github.com/AlenSaito1/ultralife/blob/61f6e6f6d125b64d76bc81ad00a608760ab5ab72/src/Types.ts#L88). It has 2 Properties, `error` and `data`. The error property will contain an instance of the [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) class if there was an error. The data property will contain the data returned by the function IF NO ERROR OCCURED. This helps in avoidng the `"try-catch hell"`. Full Credits[Jeff Delaney](https://github.com/codediodeio) for this idea. Watch this video by [fireship](https://www.youtube.com/channel/UCsBjURrPoezykLs9EqgamOA) for more info: [Async Await try-catch hell](https://youtu.be/ITogH7lJTyE)
---