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

discography

v1.0.8

Published

Multiple clients to get artists' discographies

Downloads

3

Readme

This is a module that can uses multiple providers and their API, like WikiPedia, MusicBrainz and Genius in order to retrieve discographical information and songs lyrics.

Usage

Import the provider you need and call the available methods:

Typescript

import { MusicBrainz, Discography, Track, showResult } from 'discography';

const client = new MusicBrainz();
const result = await client.getArtistDiscography('Rancid', ['Live', 'Compilation', 'Single']);
const discography = result as Discography;
const { artist, releaseGroups } = discography;

Javascript

const { Genius, showResult } = require('discography');
const geniusClient = new Genius();
geniusClient.getLyrics('Rancid', 'Nihilsm')
	.then(showResult)
	.catch(console.error);

Providers

Wikipedia

API and HTML parsing are both used to ge the required information.

searchDiscography(artist: string, options: WikiPageOptions)

This method extracts basic info about the page, the artist's MusicBrainz ID (if present), and a list of all studio albums. Here is it an example of what you get when you search The Offspring:

{
    message: 'OK',
    data: {
    pageDetails: {
        pageid: 8426694,
        title: 'The Offspring discography',
        touched: '2021-05-15T21:56:52Z'
    },
    albums: {
        'The_Offspring_(album)': { title: 'The Offspring', released: 'June 15, 1989' },
        'Ignition_(The_Offspring_album)': { title: 'Ignition', released: 'October 16, 1992' },
        'Smash_(The_Offspring_album)': { title: 'Smash', released: 'April 8, 1994' },
        ...
        'Days_Go_By_(The_Offspring_album)': { title: 'Days Go By', released: 'June 26, 2012' },
        'Let_the_Bad_Times_Roll': { title: 'Let the Bad Times Roll', released: 'April 16, 2021' }
    },
    musicBrainzUrl: '//musicbrainz.org/artist/23a03e33-a603-404e-bcbf-2c00159d7067'
    }
}

You can pass the following options as second parameter:

  • saveHtml: boolean: to save the HTML page in the current working directory
  • summary: boolean: to get the page's summary with .

searchTracks(albumTitle: string, options?: WikiPageOptions)

This method lists all the songs of a particular album, converting the songs durations into seconds. Ideally you should execute searchDiscography, take a key of the resulting object (that is the final part the album Wiki page) and pass it to this method. Here is it an example of what you get when you search Smash_(The_Offspring_album).

{
  message: 'OK',
  data: {
    pageDetails: {
      pageid: 172936,
      title: 'Smash (The Offspring album)',
      touched: '2021-05-15T21:56:34Z',
      summary: ''
    },
    tracks: [
      { num: 1, title: 'Time to Relax (Intro)', length: 25 },
      ...
      { num: 13, title: 'Not the One', length: 174 },
      { num: 14, title: 'Smash', length: 642 }
    ]
  }
}

MusicBrainz

It allows to freely get all the discography details of an artist/band. The fundamental thing to know is the structure of the entities:

  • An artist has many release groups (albums, compilations, live, etc)
  • every release groups may have multiple releases of that album (differing for publishing date, country, etc)
  • every release has many recordings (the tracks of an album)

getArtistDiscography(artist: string, filterSecondaryTypes: string[])

Retrieves the artist details and all the albums. The second parameter allows to filter out those items that have the listed secondary types in their secondaryTypes array. Here is it a possible response if you search for Rancid discography:

{
  artist: {
    id: '24f8d8a5-269b-475c-a1cb-792990b0b2ee',
    name: 'Rancid',
    country: undefined,
    lifeSpan: { begin: '1991', ended: null },
    tags: [ 'punk', 'ska punk', 'punk rock' ],
    type: 'Group'
  },
  releaseGroups: [
    {
      id: '642238f2-24b6-3a0b-bfa7-9c0b4731989d',
      title: 'Rancid',
      primaryType: 'Album',
      releaseDate: '1993-05-10',
      secondaryTypes: []
    },
    ...
    {
      id: '03a80bc2-716f-4ea9-907d-7c8b9b7fb1cd',
      title: 'Trouble Maker',
      primaryType: 'Album',
      releaseDate: '2017-06-09',
      secondaryTypes: []
    }
  ]
}

getArtist(name: string)

Retrieve the artist details (just a person). Here is it a possible response if you search for Bon Scott discography:

{
	id: '0d212894-db54-4cc1-9ded-3cac50183a1d'
	type: 'Person',
	name: 'Bon Scott',
	country: 'GB',
	lifeSpan: {
		begin: '1946-07-09',
		ended: '1980-02-19- [Usage](#usage)
	- [Typescript](#typescript)
	- [Javascript](#javascript)
- [Providers](#providers)
	- [Wikipedia](#wikipedia)
		- [`searchDiscography(artist: string, options: WikiPageOptions)`](#searchdiscographyartist-string-options-wikipageoptions)
		- [`searchTracks(albumTitle: string, options?: WikiPageOptions)`](#searchtracksalbumtitle-string-options-wikipageoptions)
	- [MusicBrainz](#musicbrainz)
		- [`getArtistDiscography(artist: string, filterSecondaryTypes: string[])`](#getartistdiscographyartist-string-filtersecondarytypes-string)
		- [`getArtist(name: string)`](#getartistname-string)
		- [`getTracksByReleaseGroup(releaseGroup: string)`](#gettracksbyreleasegroupreleasegroup-string)
	- [Genius](#genius)
		- [`getLyrics(artistName: string, songName: string)`](#getlyricsartistname-string-songname-string)
	- [Discarded providers](#discarded-providers)
- [Terms of use](#terms-of-use)
- [Resources](#resources)',
	},
	tags: [
		{
			count: 1,
			name: "rock"
		}
	]
}

getTracksByReleaseGroup(releaseGroup: string)

it allows to retrieve the tracks of a particular album. This method automatically selects the oldest release of an album and retrieves its tracks. Here is it the response if you search for the release group 37c2647f-8e58-3839-a6b6-374c9ee88b1d:

    [
      {
        id: 'bfd6a742-7f73-399d-956b-3617c4bc1f02',
        length: 123440,
        title: 'Nihilism',
        position: 1
      },
      {
        id: '897a2f83-da32-3165-acc5-876662594588',
        length: 173280,
        title: 'Radio',
        position: 2
      },
      //...
    ]

Genius

It allows to retrieve the lyrics of a particular song, given its title an the artist. If you don't provide an access token, it scrapes the search page results.

getLyrics(artistName: string, songName: string)

This is the only method present inside the class. If you execute getLyrics('Rancid', 'Nihilism'), you'll obtain something like that:

    {
      id: 1702216,
      artistId: 30419,
      title: 'Nihilism',
      lyrics: 'Come into the union district\n' +
        'Drive down on Sharmon Palms\n' +
        'White ghettos paint a picture\n' +
        'Broken homes and broken bones\n' +
        '\n' +
        //...
    }

Discarded providers

Before landing to the final solution, different API were tested:

Terms of use

  • Wikipedia: it recommends to serially do requests and to use a meaningful user agent.
  • MusicBrainz one request per second and a meaningful user agent.
  • Genius: no particular limitations exposed in their web site.

Resources