spotui

A Spotify terminal client with playback controls, search, playlists and a Now Playing view.

  • Go
  • Bubble Tea
  • OAuth 2.0
  • Spotify API
spotui (interactive demo)

Now Playing

Playing God

Polyphia

Remember That You Will Die

1:47 / 3:26

▶ Playing

on Desktop (Computer) • vol 65%

shuffle • repeat

▶ Playing God

Polyphia

1:47 / 3:26

Desktop • vol 65% • shuffle • repeat

/ search • h/l panels • j/k move • enter play • space play/pause • n next • N prev • ,/. seek • +/- vol • s shuffle • r repeat • q quit

○ Click the screen or press i to use the keyboard.

Simulated in your browser, following the real app's layout and key bindings. There is no sound.

spotui.go

Responsive over a slow API

Volume, seek, shuffle, and repeat change on screen right away, and the request goes out once the key has been idle for 300ms. Each press gets a sequence number, so only the latest one is sent.

Reconciling with Spotify

Spotify can take a moment to report a change it has already accepted. While a change is pending, the local value wins over the fetched one, until Spotify catches up or five seconds pass. Without that, controls would flicker back to their old value.

internal/ui/update.go
// reconcileValue keeps our pending value until Spotify reports the same one
func reconcileValue[T comparable](p *pending, now time.Time, ours T, theirs *T) {
	if !p.active(now) {
		return
	}

	if *theirs == ours {
		p.confirm() // Spotify caught up
		return
	}

	*theirs = ours // not yet; keep ours
}

Login without a secret

Login uses the OAuth authorization code flow with PKCE. A short-lived server on 127.0.0.1 receives the redirect and checks its state value. The refresh token goes in the operating system's credential store, and access tokens are renewed a minute before they expire.

Polling politely

Playback is fetched every five seconds and progress is estimated in between, so the bar moves every second without a request. When Spotify rate-limits a request, the next sync waits for the Retry-After it sent.

One list, many types

Playlists, liked songs, recent plays, and search results share one generic list type that handles loading, errors, the cursor, and scrolling.

architecture

  1. Key press
  2. Local state changes
  3. Debounce (300ms)
  4. Spotify Web API
  5. Playback sync (5s)
  6. Reconcile

highlights

  • OAuth login using PKCE, with no client secret
  • Login tokens stored in the operating system's keyring
  • Debounced input and backoff that honors Spotify's rate limits
  • Vim-style keyboard controls