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 🙏

© 2026 – Pkg Stats / Ryan Hefner

the-playlist-bot

v0.1.2

Published

A bot that curates a playlist on Spotify based on tracks from a given subreddit.

Downloads

3

Readme

The Playlist Bot

A bot that curates a playlist on Spotify based on tracks from a given subreddit.

👉👉👉 LIVE DEMO: Link to the "SENSATIONAL CHEESECAKE" Spotify playlist.

The demo uses tracks from /r/HipHopHeads. It's deployed as a Google Cloud App Engine app with cron jobs routinely updating the playlist.

Getting Started

Installation

Run the following command in your console of choice:

npm i the-playlist-bot

The following peer dependencies are required:

npm i snoowrap spotify-web-api-node

Usage

const { Playlist, SubredditListing } = require("the-playlist-bot");

// Described in the next section...
const CONFIG  = { /* ... */ },
      BUCKETS = { /* ... */ };

const p = new Playlist(CONFIG, BUCKETS);

p.getTracksFromSubreddit({ filter: "[FRESH]",               // Uses posts that contain the given string. 
                           sort: SubredditListing.SORT.TOP, // SORT also has HOT and NEW.
                           time: SubredditListing.TIME.DAY, // TIME also has HOUR, WEEK, MONTH, YEAR, and ALL.
                           limit: 1})                       // Set the number of tracks to return (at most).                  
 .then(tracks => p.pushToBucket(0, ...tracks)) 
 // Tracks are objects representing results. They have an "image" (link to album cover) and a "uri" (spotify URI) property. 
 // p.pushToBucket(n, ...tracks) adds the tracks to the given bucket. Check the next section for details.

 .then(() => p.update());
 // Replaces the old tracks with the new ones.

The right credentials

You can get the right credentials by creating an app for:

  1. Spotify
  2. Reddit

The CONFIG object should look like this:

{
    REDDIT: {
        USER_AGENT:    "<platform>:<app ID>:<version string> (by /u/<reddit username>)",
        CLIENT_ID:     "14 char long id",
        CLIENT_SECRET: "27 char long secret",
        REFRESH_TOKEN: "your refresh token",
        SUB:           "subredditname"
    },
    SPOTIFY: {      
        PLAYLIST_ID:   "22 char long playlist id",
        CLIENT_ID:     "32 char long client id",
        CLIENT_SECRET: "a 32 char long secret",
        ACCESS_TOKEN:  "your access token",
        REFRESH_TOKEN: "another refresh token"
    }
}

The playlist is an array of "buckets". Buckets are parts of the playlist that define their own track positions and contain their own Spotify URIs. This allows you to fetch tracks from Reddit in a customized way and add those tracks to a customized portion of the playlist.

Buckets are FIFO, meaning that new tracks are added to the top while the oldest tracks are removed.

For example, you can get new posts and add those to a bucket that only affects the first, second, and fourth track in the playlist. BUCKETS could look like this:

[ 
    [
        [0, 2], [4,5]
    ],
    [
        [3,4]
    ]
]

The resulting playlist will look like this:

  1. 1st track from first bucket
  2. 2nd track from first bucket
  3. 1st track from second bucket
  4. 3rd track from first bucket

Playlist objects can be serialized. Calling JSON.stringify on a playlist object returns a JSON that can be used as the BUCKETS argument.