Skip to content

ColinGamez/SpotiB0T

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽต SpotiB0T โ€” Spotify Playlist Manager & Automation Bot

A powerful, full-featured Spotify playlist manager with a stunning interactive CLI and automated bot for rule-based playlist management.

Node.js TypeScript License


โœจ Features

๐ŸŽง Playlist Management

  • List all playlists with track counts, visibility, and owner info
  • View tracks with paginated browsing (50 per page)
  • Create new playlists
  • Edit playlist name, description, and visibility
  • Clone any playlist (full deep copy)
  • Remove tracks interactively with multi-select
  • Shuffle playlists with smart artist separation
  • Merge multiple playlists into one (with dedup)
  • Delete (unfollow) playlists
  • Follow / Unfollow playlists by ID or URL

๐Ÿ” Search

  • Search the Spotify catalog and add results to any playlist
  • Quick search for fast lookups with popularity stars

๐Ÿ“Š Analytics

  • Playlist stats โ€” duration, popularity, top artists, decade breakdown, diversity metrics
  • Audio analysis โ€” danceability, energy, valence, acousticness, tempo, key distribution
  • Library overview โ€” total playlists, tracks, public/private split, largest playlists

๐Ÿ’พ Export & Backup

  • Export playlists to JSON or CSV
  • Import playlists from JSON files
  • Full backup of all playlists to a single timestamped file
  • Restore from backup โ€” recreates playlists and re-adds all tracks

โšก Automation (9 Rule Types)

Rule Description
โค๏ธ Add Liked Songs Auto-add recently liked songs to a playlist
๐Ÿ—‘๏ธ Remove Unplayed Remove tracks not played in X days
๐Ÿ”„ Sync Playlists Mirror or append from one playlist to another
๐Ÿ”ฎ Discover Clone Archive each week's Discover Weekly
๐Ÿงน Deduplicate Remove duplicate tracks (keep first or last)
๐Ÿ“Š Sort Playlist Sort by name, artist, date, popularity, or duration
๐Ÿ† Top Tracks Auto-fill your top tracks into a playlist
๐Ÿ”€ Auto-Shuffle Smart shuffle with artist separation
๐Ÿ’ก Recommendations Generate recs from a seed playlist

๐Ÿค– Bot Mode

  • Cron scheduling โ€” runs rules automatically (configurable schedule)
  • Dry-run mode โ€” preview changes without modifying Spotify
  • Run history โ€” every execution is logged and auditable

๐Ÿš€ Direct CLI Commands

Run commands without entering the interactive menu:

npm run dev -- list                  # List all playlists
npm run dev -- search "daft punk"    # Search tracks
npm run dev -- stats                 # Library overview
npm run dev -- backup                # Backup all playlists
npm run dev -- export <playlistId>   # Export a playlist to JSON

๐Ÿ“ฆ Quick Start

1. Prerequisites

2. Create a Spotify App

  1. Go to https://developer.spotify.com/dashboard
  2. Click Create App
  3. Set the Redirect URI to: http://localhost:8888/callback
  4. Note your Client ID and Client Secret

3. Install & Configure

git clone https://github.com/ColinGamez/SpotiB0T.git
cd SpotiB0T
npm install

# Copy the example env file and fill in your credentials
cp .env.example .env

Edit .env with your Spotify app credentials:

SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_CLIENT_SECRET=your_client_secret_here

4. Authenticate

npm run dev

On first launch the app opens your browser for Spotify login. After authorizing, tokens are stored securely in a local SQLite database and auto-refresh.

5. Use the CLI

The interactive menu is organized into clear sections:

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘   SpotiB0T  ยท  Playlist Manager & Bot     โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  Logged in as: YourName

โ”€โ”€โ”€ PLAYLISTS โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  List my playlists
  View playlist tracks
  Create new playlist
  Edit playlist details
  Clone a playlist
  Remove tracks
  Shuffle a playlist
  Merge playlists
  Delete a playlist
  Follow / Unfollow

โ”€โ”€โ”€ SEARCH โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Search & add tracks
  Quick search

โ”€โ”€โ”€ ANALYTICS โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Playlist stats
  Library overview

โ”€โ”€โ”€ EXPORT & BACKUP โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Export playlist (JSON/CSV)
  Import playlist
  Backup all playlists
  Restore from backup

โ”€โ”€โ”€ AUTOMATION โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  List rules
  Add rule
  Run a rule
  Toggle rule
  Delete rule
  View run history

  Logout

6. Run the Bot

# Run all enabled rules once
npm run dev -- --once

# Run in cron mode (stays alive, executes on schedule)
npm run dev -- --bot

# Dry-run mode
DRY_RUN=true npm run dev -- --once

๐Ÿ—๏ธ Project Structure

src/
โ”œโ”€โ”€ auth/                    # OAuth 2.0 authentication
โ”‚   โ”œโ”€โ”€ oauth.ts             # Authorization Code Flow with PKCE-ready server
โ”‚   โ”œโ”€โ”€ tokenStore.ts        # Token persistence (SQLite)
โ”‚   โ”œโ”€โ”€ login.ts             # Standalone login script
โ”‚   โ””โ”€โ”€ index.ts             # Barrel export
โ”œโ”€โ”€ spotify/                 # Spotify Web API layer
โ”‚   โ”œโ”€โ”€ apiClient.ts         # Axios client with retry, rate-limit, token refresh
โ”‚   โ”œโ”€โ”€ playlistService.ts   # 20+ playlist/library operations
โ”‚   โ”œโ”€โ”€ types.ts             # TypeScript interfaces for Spotify objects
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ rules/                   # Automation engine
โ”‚   โ”œโ”€โ”€ types.ts             # Rule type definitions (9 types)
โ”‚   โ”œโ”€โ”€ ruleStore.ts         # Rule CRUD (SQLite)
โ”‚   โ”œโ”€โ”€ ruleExecutor.ts      # Rule dispatch & execution handlers
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ bot/                     # Scheduled runner
โ”‚   โ”œโ”€โ”€ runner.ts            # Cron-based automation + run-once mode
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ commands/                # CLI command handlers
โ”‚   โ”œโ”€โ”€ playlistCommands.ts  # 10 playlist operations
โ”‚   โ”œโ”€โ”€ searchCommands.ts    # Search & quick search
โ”‚   โ”œโ”€โ”€ statsCommands.ts     # Playlist stats & library overview
โ”‚   โ”œโ”€โ”€ exportCommands.ts    # Export, import, backup, restore
โ”‚   โ”œโ”€โ”€ ruleCommands.ts      # Rule wizard, toggle, run, delete, history
โ”‚   โ””โ”€โ”€ index.ts             # Barrel export
โ”œโ”€โ”€ utils/                   # Shared utilities
โ”‚   โ”œโ”€โ”€ config.ts            # Validated environment config
โ”‚   โ”œโ”€โ”€ db.ts                # SQLite database (better-sqlite3)
โ”‚   โ”œโ”€โ”€ logger.ts            # Winston logging (console + file)
โ”‚   โ”œโ”€โ”€ format.ts            # CLI formatting helpers (tables, bars, stars)
โ”‚   โ”œโ”€โ”€ spinner.ts           # ora spinner wrapper
โ”‚   โ””โ”€โ”€ sleep.ts             # Async delay helper
โ”œโ”€โ”€ cli.ts                   # Interactive CLI (inquirer menus)
โ””โ”€โ”€ index.ts                 # Entry point โ€” CLI / Bot / Direct command router

โš™๏ธ Configuration

All config lives in .env:

Variable Description Default
SPOTIFY_CLIENT_ID Your Spotify app Client ID required
SPOTIFY_CLIENT_SECRET Your Spotify app Client Secret required
SPOTIFY_REDIRECT_URI OAuth callback URL http://localhost:8888/callback
DRY_RUN Preview mode โ€” no Spotify writes false
LOG_LEVEL Logging verbosity (debug / info / warn / error) info
DB_PATH SQLite database file path ./data/spotify-bot.db
CRON_SCHEDULE Bot execution schedule (cron syntax) 0 * * * * (hourly)

๐Ÿ“– Example Rule Setups

Add liked songs from the last week

  1. CLI โ†’ Add rule โ†’ Add liked songs
  2. Select target playlist, set days: 7
  3. Run it manually or let the bot handle it on schedule

Keep Playlist B in sync with Playlist A

  1. CLI โ†’ Add rule โ†’ Sync playlists
  2. Source: Playlist A โ†’ Target: Playlist B โ†’ Mode: Mirror
  3. Enable the bot: npm run dev -- --bot

Archive Discover Weekly every Monday

  1. CLI โ†’ Add rule โ†’ Clone Discover Weekly
  2. Set CRON_SCHEDULE=0 9 * * 1 in .env
  3. Run: npm run dev -- --bot

Auto-generate a "My Top Tracks" playlist

  1. CLI โ†’ Add rule โ†’ Top tracks
  2. Select time range and target playlist
  3. The bot updates it on every run

๐Ÿ›ก๏ธ Safety & Robustness

  • Dry-run mode โ€” preview all changes before committing
  • Duplicate detection โ€” tracks already in a playlist are never re-added
  • Rate-limit handling โ€” automatic exponential backoff on Spotify 429s (capped at 10 retries)
  • Retry logic โ€” handles 401, 5xx, and network errors with exponential backoff
  • Token auto-refresh โ€” never worry about expired tokens
  • Graceful shutdown โ€” SIGINT handler cleanly closes the database
  • Audit trail โ€” every rule run is logged with status, summary, and timestamp
  • Error recovery โ€” corrupted rule configs are handled gracefully (fallback defaults)

๐Ÿ”ง Scripts

Command Description
npm run dev Start interactive CLI (with ts-node)
npm run dev -- --bot Start cron-based bot
npm run dev -- --once Run all rules once and exit
npm run dev -- list List playlists (direct)
npm run dev -- search "query" Search tracks (direct)
npm run dev -- stats Library overview (direct)
npm run dev -- backup Backup all playlists (direct)
npm run dev -- export <id> Export playlist (direct)
npm run build Compile TypeScript to dist/
npm start Run compiled JS from dist/
npm run lint Run ESLint

๐Ÿงฐ Tech Stack

Component Technology
Runtime Node.js 20+ / TypeScript 5.9
API Spotify Web API (Authorization Code Flow)
Database SQLite via better-sqlite3
CLI Inquirer.js + Chalk + ora spinners
Scheduling node-cron
HTTP Axios with retry interceptors
Logging Winston (console + file)
Linting ESLint 9 (flat config) + typescript-eslint

๐Ÿ“„ License

MIT

About

a Spotify playlist bot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors