Skip to content

About

Self-hosted, token-protected SVG widgets for ListenBrainz profiles.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ListenBrainz Widget

Self-hosted, token-protected SVG widgets for ListenBrainz profiles.

This project generates responsive "now playing / recently played" cards that you can embed in GitHub READMEs and websites.

Repository: https://github.com/parthadhar/listenbrainz-widget

Live Demo

Now playing on lb.parthadhar.com — updates in real time:

Now Playing – PaulDr

Screenshots

Now playing – Strawberry
Strawberry player
Now playing – Dil Chahta Hai
Strawberry – classic art
Now playing – HiByMusic
HiByMusic player
Now playing – Poweramp
Poweramp player
Now playing – YouTube Music (fallback art)
YouTube Music – fallback tile
Recently played
Recently played state
Widget vs Spotify player comparison
Matching Spotify playback in real time

Highlights

  • Per-user token auth in URL path (/widget/:username/:token)
  • Internal-only token issuance and revocation via CLI scripts
  • Responsive SVG output for desktop/mobile embeds
  • Single-track hero card keeps a 320:445 aspect ratio and scales by width
  • Dark/light themes with selectable palettes
  • Layout variants: compact, default, wide
  • Animated equalizer + play-state ambience + full-card nebula/aurora background
  • Auto-detected player-specific styles with logos (spotify, apple-music, youtube-music, soundcloud, mood-eq, starlight)
  • Dynamic album-art color extraction for adaptive gradients
  • Stale-data indicator for inactive profiles
  • Multi-level album art fallback + cached generated fallback tiles

Quick Start

cd lb-widget
npm install
cp .env.example .env

# set TOKEN_ADMIN_SECRET in .env before generating tokens
npm run token:generate -- --user YOUR_USERNAME --note "primary token"

npm run dev

Or use the combined operations script:

./scripts/lb-widget.sh setup
./scripts/lb-widget.sh token-generate YOUR_USERNAME "github-readme" --unlimited
./scripts/lb-widget.sh dev

Use the generated token in URLs:

http://localhost:3100/widget/YOUR_USERNAME/YOUR_TOKEN?theme=dark&layout=default&palette=classic

URL Format

Widget image route:

GET /widget/:username/:token

JSON route:

GET /api/:username/now-playing/:token

Query params:

  • theme: dark | light | transparent | auto
  • layout: compact | default | wide
  • palette: classic | neon | minimal | glass
  • count: 1 to 5
  • refresh: soft (optional; when first cover is fallback, widget revalidates aggressively to pick real cover sooner)

Token-bound display flags (set during token generation, not URL):

  • show_playback_source: adds a source/device detail line in the card
  • show_external_links: adds origin link icon when available
  • show_hover_details: adds SVG <title> hover details

Preview route:

GET /preview

GitHub Embed Example

![Now Listening](https://YOUR_HOST/widget/YOUR_USERNAME/YOUR_TOKEN?theme=dark&layout=default&palette=classic)

Responsive HTML embed (maintains 320:445 ratio):

<img
	src="https://YOUR_HOST/widget/YOUR_USERNAME/YOUR_TOKEN?theme=dark&layout=default&palette=classic&count=1"
	alt="Now Playing"
	style="width:100%;max-width:420px;height:auto;aspect-ratio:320/445;display:block"
/>

Hero layout notes (count=1 + layout=default):

  • Header switches by state: Now playing in ... (active) or Recently played on ... (inactive)
  • Player selection order: media_player → music_service_name → mapped submission_client fallback
  • Fallback mapping: Web Scrobbler → Web, ListenBrainz Android → Android, strawberry → Ubuntu
  • Album art fills the full widget width in the bottom section
  • EQ and seek/progress bars align to the full art width in a dedicated control band above cover art

Cover-art loading behavior:

  • Server waits longer for first render cover fetch (COVER_FETCH_WAIT_MS, default 5000 ms)
  • Same album can reuse cached cover memory (user+album scoped)
  • If first render falls back to initials art, refresh=soft reduces cache time to refresh quickly

Internal Token Management

Generate token (internal shell only):

npm run token:generate -- --user YOUR_USERNAME --note "github-readme"

Generate unlimited token (no per-minute limit):

npm run token:generate -- --user YOUR_USERNAME --note "unlimited" --unlimited

Generate token with custom limit and expiry:

npm run token:generate -- --user YOUR_USERNAME --limit 180 --expires-days 30

# Token-level privacy options (cannot be changed via URL)
npm run token:generate -- --user YOUR_USERNAME --show-source --show-links --show-details

Revoke token:

npm run token:revoke -- --user YOUR_USERNAME --token YOUR_TOKEN

Rotate token (issue new + revoke old):

npm run token:rotate -- --user YOUR_USERNAME --old-token OLD_TOKEN_OR_HASH --note "rotation"

Generate signed short-lived URL:

npm run url:signed -- --route widget --user YOUR_USERNAME --token YOUR_TOKEN --ttl 900 --query "theme=dark&layout=wide&palette=neon"

Diagnostics endpoint:

GET /health/upstream

Notes:

  • Widget responses include ETag and support conditional requests via If-None-Match.
  • theme=auto resolves to light/dark using request color-scheme hints when available.
  • Player style/logo is inferred automatically from playback metadata.
  • LB_METADATA_AUTH_TOKEN (or LISTENBRAINZ_AUTH_TOKEN) enables metadata lookup for better cover-art fallback.

Token hashes are stored in data/tokens.json (gitignored by default).

When ACCEPT_TOKEN_HASH=true, both raw token and token hash can be used in URL.

Deployment

See full instructions:

Operations Script

Use scripts/lb-widget.sh as a single command surface for:

  • setup/install/run/dev/update/pull
  • token-generate/token-revoke/token-list
  • token-generate/token-revoke/token-list/token-rotate
  • docker-up/docker-down/docker-logs
  • health check + widget URL helper + signed URL helper

Examples:

./scripts/lb-widget.sh update
./scripts/lb-widget.sh token-list YOUR_USERNAME
./scripts/lb-widget.sh widget-url YOUR_USERNAME YOUR_TOKEN "theme=dark&layout=wide&palette=neon"
./scripts/lb-widget.sh signed-url widget YOUR_USERNAME YOUR_TOKEN 900 "theme=light&layout=compact&palette=minimal"

About

Self-hosted, token-protected SVG widgets for ListenBrainz profiles.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages