Each source playlist gets an ordinary private playlist, created with its
PlaylistCreated operation in one transaction even when nothing matched.
Matched entries follow in source order, at most 200 per transaction: the
playlist row, the item register, the existing PlaylistTrackAdded operation
and a receipt are written together, so fed_sync_ops serves as the outbox
and an interrupted batch leaves nothing behind. Locks are taken in a fixed
order (per-user advisory lock, import lease, playlist, fed-device identity,
registers). Registers are only inserted; an item the playlist has or had,
a removal committed to the journal but not yet applied, a repeat or a
receipt keep the publisher from adding it again. A deleted target pauses
publication until POST .../playlists/{pid}/recreate; POST .../resync
retries unmatched entries and appends new matches at the end.
Before each batch the outgoing Device Sync line is measured by serializing
the same parts the exchange sends. Tracks and new playlists are published
while the music snapshot stays within library_import_sync_budget (2 MiB)
and the whole line within 7 MiB; the rest waits as deferred_sync_limit.
Device Sync gets local helpers only: create_owned_playlist_tx is extracted
from the playlist handler, append_in_transaction takes an explicit
position, the two operations have in-transaction variants on
append_local_op, and applying a playlist item writes its register under an
atomic last-writer-wins condition and its playlist row in the same
transaction, so concurrent operations cannot make them diverge. The
protocol and its formats are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the Spotify adapter to the library import. The data export path parses
Playlist*.json and YourLibrary.json sent by the browser, tolerates missing
and unexpected keys, keeps the source order and repeats, and stores episodes,
audiobooks, local files and unreadable entries as unsupported instead of
dropping them. The bundled export fixture is synthetic and must be joined by
an anonymized real export before acceptance.
POST /api/imports/preview lists the playlists of an upload and marks those
already imported or similar to an earlier import; POST /api/imports stores
the selected playlists with every entry in one transaction and starts the
worker. Requests are JSON-only and limited to 32 MiB (413). Re-import is
detected per source playlist: a repeat is refused with 409, and a changed
playlist with the same title needs confirm_similar.
The Spotify Web API is optional and enabled by an administrator's client ID
(and redirect URI behind a proxy) in the settings. Sign-in uses PKCE with the
state, verifier and waiting import kept in the session; access tokens stay
only in an in-memory vault for at most 30 minutes. The worker fetches the
selected playlists one by one, honors Retry-After and backs off on server
errors. A missing or expired token parks the import as needs_reauth; signing
in again with the same account continues the same import and skips the
playlists already fetched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>