/ultra-lyrics

Genius Scraper and API Wraper

Primary LanguageTypeScript

Ultra-Lyrics

ultra

Ultra-Lyrics is a package which fetches the Genius API and uses the data to scrap the lyrics from the actual website. Occasionally paired with Spotifydl-Core

Read Docs Here: Docs

Install

npm i ultra-lyrics

Usage

Note: To authenticate with a Genius access token, you need to add it to process.env as an ENV Variable or usign dotenv wth the name as GENIUS_ACCESS_TOKEN

Search for songs

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

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

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. It has 2 Properties, error and data. The error property will contain an instance of the 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 CreditsJeff Delaney for this idea. Watch this video by fireship for more info: Async Await try-catch hell