Skip to content

Streaming integrations: Apple Music links, 30s previews, playlist export - #2

Merged
robrien20 merged 5 commits into
mainfrom
streaming-integrations
May 5, 2026
Merged

robrien20 merged 5 commits into
mainfrom
streaming-integrations

Conversation

@robrien20

Copy link
Copy Markdown
Owner

Summary

Three independent surfaces, each gated separately so partial setup is fine.

1. Apple Music links

  • Candidate cards + tracklist rows now render an Apple Music link wherever the ACR result included apple_id. Pure UI — the data was already flowing through.

2. 30-second in-browser previews (no auth, no signups)

  • Apple: backend GET /api/preview?service=apple&id=<song_id> → iTunes Search lookup, returns { preview_url, artwork_url, … }. Cached on disk per song-id for 24h.
  • Spotify: official open.spotify.com/embed/track/<id> iframe widget — Spotify allows their embed to play 30s clips with no auth.
  • UI: a small ▶ button next to each candidate's links. One shared player; clicking another preview tears the previous one down. Main set audio pauses when a preview plays, and previews tear down if the user resumes the main audio.

3. Playlist export (single-user OAuth)

  • Spotify (Authorization Code with PKCE — no client secret). Operator registers a Spotify app, sets SPOTIFY_CLIENT_ID. Tokens persist in ~/.setplot/spotify_token.json (0600). Track resolution: existing spotify_id from ACR → ISRC search → title+artist search with artist-substring sanity check. Adds tracks in batches of 100 (Spotify's hard limit).
  • Apple Music (MusicKit JS, gated on a paid Apple Developer membership). Backend signs an ES256 developer JWT in-process from a .p8 key (APPLE_MUSIC_TEAM_ID/KEY_ID/KEY_PATH). Sign-in and POST /v1/me/library/playlists happen entirely in the browser via MusicKit JS — the backend's involvement ends at the JWT. Same resolution chain (catalog filter[isrc] → text search).
  • Both export buttons self-disable: the /api/sets/{id} response gains a services: { spotify, apple } capability flag. No env, no buttons.

Architecture & decision log

Full design recorded in docs/superpowers/specs/2026-05-04-streaming-integrations-design.md.

Test plan

  • pytest — 99 passed (78 prior + 21 new).
  • iTunes Search lookup verified end-to-end against a real song id (Apple previewUrl returned, no auth).
  • Spotify auth redirect URL constructed correctly (asserted PKCE params present); 503 path verified when SPOTIFY_CLIENT_ID unset.
  • Apple developer JWT verified: ES256 header, claims (iss/iat/exp), and signature roundtrip with a freshly generated EC P-256 key.
  • Spotify export end-to-end with API stubbed: ACR-id and ISRC resolution paths; playlist creation and add-tracks called as expected.
  • Token store: 0600 perms confirmed; expiry math verified.
  • Manual: connect a real Spotify account, export a small set, verify playlist appears.
  • Manual (when Apple Developer key available): sign in with Apple ID, export a small set, verify library playlist appears.

Out of scope (deferred)

  • Multi-user identity inside SetPlot (this is single-user; SETPLOT_TOKEN_DIR override exists for tests).
  • In-browser full-track playback (Web Playback SDK / MusicKit JS playback).
  • Tidal, YouTube Music, Deezer.

Robert O'Brien and others added 5 commits May 4, 2026 13:20
The previous selector required a video track, so audio-only URLs (SoundCloud,
Bandcamp, etc.) silently failed. Adds /ba/b fallbacks so yt-dlp picks the
best audio when no video stream exists.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…gest

Steps after ingest (peaks, bpm, key, fingerprint) had no data dependency on
each other but ran serially. Fan them out across a ThreadPoolExecutor; the
status.json read-modify-write is the only shared mutable state, so a single
lock around update_step is sufficient. Real-world wins come from overlapping
the network-bound fingerprint scan and subprocess-bound peaks step with the
CPU-bound bpm/key passes.

On the viewer side, the library form now navigates to /set.html as soon as
the SSE stream emits a set_id (immediately after ingest), rather than blocking
on the full pipeline. The set page already polled status.json and reloaded
artifacts as they appeared; added a peaks case so wavesurfer rebuilds with
real peaks once that step finishes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… export)

Personal-but-deployable single-user OAuth design. Apple Music links and 30s
previews need no auth. Spotify export uses PKCE with loopback redirect; Apple
Music export is gated on operator providing a Developer .p8 key.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…t export

Three independent surfaces (any can be enabled separately):

* Apple Music links — render alongside Spotify/YouTube on candidate cards
  and tracklist rows. The apple_id was already flowing through ACR; we just
  weren't displaying it.

* 30s in-browser previews (no auth) — Apple via the iTunes Search lookup
  endpoint (cached on disk for 24h), Spotify via the open.spotify.com/embed
  iframe widget. Inline ▶ buttons on each candidate; main set audio pauses
  when a preview plays, and a preview tears down when the user resumes.

* Playlist export — single-user OAuth model, tokens stored in ~/.setplot/
  with 0600 perms.
  - Spotify: Authorization Code with PKCE (no client secret), server-side
    token exchange and refresh. Track resolution prefers ACR's spotify_id,
    falls back to ISRC search, then to title+artist with artist-substring
    sanity check. Adds tracks in batches of 100 (Spotify's hard limit).
  - Apple Music: developer JWT (ES256) signed in-process with a .p8 key,
    served at /api/apple/dev-token. The browser uses MusicKit JS for sign-in
    and library writes; the backend's involvement ends at the JWT.
  Both endpoints self-disable when their credentials aren't configured —
  the viewer reads a `services` capability flag and hides the buttons.

New deps: cryptography (for ES256 signing).

Configuration is documented in README.md and lives entirely in env vars,
nothing on disk that gets committed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@robrien20
robrien20 merged commit ba62cbc into main May 5, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant