npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@execaman/lyricist

v2.0.2

Published

A lyric-fetcher that crawls the web, custom plugin support, no additional stuff required

Downloads

411

Readme

Import

// ES Modules
import { Lyricist } from "@execaman/lyricist";

// Common JS
const { Lyricist } = require("@execaman/lyricist");

Configure

const lyrics = new Lyricist({
  // An array of async scraper functions
  // Read the last section for more info
  plugins: [],

  // Whether to save last successful
  // fetch results. default is false
  saveLastResult: false
});

Usage

// Keep it short, around 30
// characters in length
const query = "calma remix";

// Number of attempts to make
// if Google doesn't have the lyric
const attempt = 3;

// Make a request
const result = await lyrics.fetch(query, attempt);
{
  song: { title: 'Calma', subtitle: 'Song by Farruko and Pedro Capó' },
  info: [
    { label: 'Album:', value: 'Calma' },
    { label: 'Artists:', value: 'Pedro Capó, Farruko' },
    { label: 'Released:', value: '2018' },
    {
      label: 'Awards:',
      value: 'Latin Grammy Award for Song of the Year, MORE'
    },
    { label: 'Genres:', value: 'Latin pop, Pop' }
  ],
  listen: [
    {
      source: 'Spotify',
      stream: 'https://open.spotify.com/track/7FRYMm2zVVB6lpNpDWxldE?autoplay=true'
    },
    {
      source: 'YouTube Music',
      stream: 'https://music.youtube.com/watch?v=7Eo7d5_5ktI&feature=gws_kp_track'
    },
    {
      source: 'Apple Music',
      stream: 'https://music.apple.com/in/album/calma-remix/1437920278?i=1437920364'
    },
    {
      source: 'JioSaavn',
      stream: 'https://www.jiosaavn.com/song/calma-remix/Flg8AQ1-RVc?autoplay=enabled'
    }
  ],
  lyrics: 'Cuatro abrazos y un café\n' +
    'Apenas me desperté\n' +
    'Y al mirarte recordé\n' +
    'Que ya todo lo encontré\n' +
    '\n' +
    'Tu mano en mi mano\n' +
    'De todo escapamos\n' +
    'Juntos ver el sol caer\n' +
    '\n' +
    "Vamos pa' la playa\n" +
    "Pa' curarte el alma\n" +
    'Cierra la pantalla\n' +
    'Abre la Medalla\n' +
    'Todo el mar Caribe\n' +
    'Viendo tu cintura\n' +
    'Tú le coqueteas\n' +
    'Tú eres buscabulla\n' +
    'Y me gusta\n' +
    '\n' +
    'Lento y contento, cara al viento\n' +
    'Lento y contento, cara al viento\n' +
    '\n' +
    "Pa' sentir la arena en los pies\n" +
    "Pa' que el sol nos pinte la piel\n" +
    "Pa' jugar como niños, darnos cariño\n" +
    'Como la primera vez que te miré\n' +
    'Yo supe que estaría a tus pies\n' +
    'Desde que se tocaron\n' +
    '\n' +
    'Calma, mi vida, con calma\n' +
    'Que nada hace falta si estamos juntitos bailando\n' +
    'Calma, mi vida, con calma\n' +
    'Que nada hace falta si estamos juntitos andando\n' +
    'Calma, mi vida, con calma\n' +
    'Que nada hace falta si estamos juntitos bailando',
  source: {
    name: 'google.com',
    url: 'https://www.google.com/search?q=calma%20remix%20lyrics'
  }
}

How it works

It fetches the SERP after appending " lyrics" to the query from Google, looks for any showcased lyrics and resolves it if available; else, tries to find a result on page that it has a supported plugin for.

This solves two major problems:

  • Spam or sending unwanted traffic to a specific site
  • And in turn, being timed out, rate-limited, or even blaclisted

Note: there is a 3s delay to prevent you from spamming Google, but other sites might require a higher delay (in case there are no lyrics on page); so make sure to not make any unnecessary requests.

What are plugins?

  • Plugins are async functions that scrape direct lyric-page URLs
  • They have two parameters, first: the URL, second: A random User-Agent string
  • The function name represents the hostname of the site
  • Underscore (_) in function names define the hostname of the site
  • Two underscores resemble a hyphen (-), while one resembles a dot (.)

So a function name like karaoke__lyrics_com would translate to karaoke-lyrics.com

Writing your own plugin

  • Use try-catch blocks, avoid throwing anything
  • Make sure to choose a site that has a good DOM structure
  • Avoid hostname conflicts (e.g. abc.com <=> abc.com.br)
  • Avoid sites that include content other than lyrics and yet appear on Google
  • Either return lyrics, or reject as soon as you realise the result could be invalid

Resources

References

Conclusion

With AI and modern frontend frameworks, sources would eventually become unscrapable. Therefore, I do not guarantee its functionality over time or if this package will be up-to-date. This is NOT an ethical way of obtaining lyrics anyway.