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

@bolajiolajide/now-playing

v1.0.0

Published

A simple package to get the current playing song from a streaming platform.

Downloads

20

Readme

Now Playing

Collaborative effort with @lilpolymath to create a library that can be used to display the currently playing song from a user's streaming platform.

This library is built to be generic to work with multiple providers and storage mechanisms.

Installation

To install the package, use your preferred package manager:

# npm
npm install @BolajiOlajide/now-playing

# yarn
yarn add @BolajiOlajide/now-playing

Usage

import { NowPlaying, Providers, type IStorer } from '@BolajiOlajide/now-playing'

let myCustomStorer: IStorer

const np = new NowPlaying(Providers.SPOTIFY, {
  useCache: false, // (optional) default is true
  cacheDuration: 30000, // (optional) in milliseconds
  streamerArgs: {
    clientId: 'foo',
    clientSecret: 'bar',
    refreshToken: 'baz',
  },
  storer: myCustomStorer, // (optional) custom storage implementation
})

Storage

We default to inmemory storage for saving information gotten via the API, (e.g Access tokens, Song data e.t.c). However you can pass in your own custom storage object, provided it satisfies the IStorer interface.

interface IStorer {
  set<T>(key: string, value: T, duration: number): void
  get<T>(key: string): T | undefined
  delete(key: string): boolean
  has(key: string): boolean
  clear(): void
  pruneExpiredEntries(): void
}

Providers

Spotify

You need three things.

  1. Spotify Client ID
  2. Spotify Client Secret
  3. Spotify Refresh Token

To get your Spotify Client ID and sercet, follow these steps:

  1. Log in to your Spotify Dashboard.
  2. Create a new app by clicking on the "Create an App" button. You can name your app whatever you like.
  3. After creating the app, you will see the details page for your app. Here, you can find your client ID and client secret.

You'll need these credentials to generate a refresh token for Spotify.

Spotify's access token expires every hour, so you will need a refresh token to obtain a new one automatically. To get your refresh token, refer to the following articles for a detailed guide:

Make sure to include the following scopes: "user-read-currently-playing" and "user-read-recently-played" when setting up the authorization process.

Contributing

We welcome contributions from the community! To contribute:

  • Fork the repository.
  • Create a new branch with a descriptive name.
  • Make your changes and commit them with a descriptive message.
  • Push your changes to your forked repository.
  • Open a pull request to the main repository.