Public
Full-text search across all your Spotify playlists
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Spotify Playlist Search

Full-text search across all your Spotify playlists. Search by track name, artist, album, or playlist name.

Setup

1. Create a Spotify App

  1. Go to the Spotify Developer Dashboard
  2. Click Create app
  3. Fill in any name/description
  4. Set the Redirect URI to:
    https://spotify-search.val.run/auth/callback
    
  5. Accept the terms and create
  6. Open the app settings and copy your Client ID and Client Secret

2. Add Environment Variables

šŸ‘‰ Add SPOTIFY_CLIENT_ID here: https://www.val.town/x/tod/spotify-playlist-search/environment-variables?key=SPOTIFY_CLIENT_ID

šŸ‘‰ Add SPOTIFY_CLIENT_SECRET here: https://www.val.town/x/tod/spotify-playlist-search/environment-variables?key=SPOTIFY_CLIENT_SECRET

3. Use It

  1. Visit spotify-search.val.run
  2. Click Connect Spotify and authorize
  3. Click Sync to fetch all your playlists
  4. Search across all your tracks!

How It Works

  • Spotify OAuth — Authorization Code flow with playlist-read-private and playlist-read-collaborative scopes
  • SQLite FTS5 — Full-text search index across track name, artist, album, and playlist name
  • Sync — Fetches all playlists and tracks from Spotify, indexes them in SQLite with BM25 ranking
  • Tokens — Refresh token stored in blob storage; access tokens auto-refresh when expired

Architecture

spotify.ts  → Spotify API client (OAuth, pagination, token refresh)
db.ts       → SQLite FTS5 schema + search with BM25 ranking
sync.ts     → Orchestration: fetch all playlists → fetch all tracks → reindex
main.ts     → Hono HTTP server (routes for auth, sync, search, UI)
index.html  → Search UI (dark Spotify-themed, debounced live search)