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

@claygregory/spotify-matcher

v0.0.10

Published

Matches tracks to their associated Spotify ID

Downloads

16

Readme

Spotify Matcher

This is a JavaScript module for matching artist/album/track information (such as from your music library) to Spotify IDs. Tossed together on short order, it's not pretty and robustness is questionable. As such, the audience is primarily myself, currently in a personal data pipeline enriching last.fm scrobbles from a variety of sources (Pandora, iTunes, and Spotify).

As the input is expected to be from a variety of sources, each with differing tagging practices, matching is a bit beyond hitting the Spotify search endpoint and taking the top hit. The search endpoint is pretty sensitive to extraneous terms, so this module attempts to trim excess tokens from fields pre-query, casting a wide net and scoring/filtering search results client-side for best-match. In addition, we can't expect every track to be within the Spotify catalog, so scoring thresholds determine when it's acceptable to fail, rejecting the existence of a match.

Installation

npm install --save @claygregory/spotify-matcher

Usage Example

const SpotifyMatcher = require('@claygregory/spotify-matcher');

const spotify = new SpotifyMatcher();
spotify.matchTrack({
  artist: 'The Naked and Famous',
  album: 'Simple Forms',
  track: 'Backslide'
}).then(match => {
  console.log(match);
});

The match object will contain artist, album, and track information, based on internal scoring. One or more of the fields may not be provided, if a suitable match was not found. A complete match object takes the form:

{
  "artist": [
    {
      "id": "0oeUpvxWsC8bWS6SnpU8b9", "name": "The Naked And Famous"
    }
  ],
  "album": {
    "id": "0m9VQlYqaZTktKzkbGPsve", "name": "Simple Forms", "album_type": "album"
  },
  "track": {
    "id": "0CDJU9tQfysl3TS2yEwbxx",
    "name": "Backslide",
    "disc_number": 1,
    "track_number": 6,
    "explicit": false,
    "popularity": 39
  },
  "score": {
    "artist": 0.999, "album": 0.9983, "track": 0.9916, "composite": 0.9961
  }
}

Scores are based on the Jaro-Winkler similarity between the Spotify field name, and a processed version of provided field information that attempts to address common tagging mismatch concerns.

Access Token and Options

The module operates with relatively sane defaults, and does not require a Spotify access token for small match jobs. However, a Spotify OAuth2 token may be provided, for a higher rate limit from Spotify.

const spotify = new SpotifyMatcher(access_token, options);

The access_token is either a string, or a function to provide the token per-request (for example, to handle refreshing as needed on long-running match jobs). This library does not provide any OAuth access flow handling, that's on you.

The options object supports the following configuration(s), defaults as below:

{
  cache_requests: true,  // Internally cache API responses for lifetime of instance?
  market: 'US',          // Spotify market (to avoid tracks not available to you)
  rate_limit_ms: 200,    // API rate limit
  score_threshold: {     // per field edit-distances to accept as match
    album: 0.65,
    artist: 0.90,
    track: 0.70,
    composite: 0.80
  },
  score_weights: {       // weight of each field when computing composite score
    album: 0.75,
    artist: 1,
    track: 1
  }
}

Performance Testing

A test file of sample inputs and expected responses is provided in test-performance/tests.tsv, especially with regard to potential fail cases. Running npm run perf will process this file and provide performance results. Additions to this file welcome (US market IDs, please)!

License

See the included LICENSE for rights and limitations under the terms of the MIT license.