connect: publish context-less sessions with an empty context, as official clients do - #1769
Open
joel-trumper wants to merge 1 commit into
Open
joel-trumper wants to merge 1 commit into
joel-trumper wants to merge 1 commit into
Conversation
…cial clients do A list of tracks without a context is kept under a placeholder context: spotify:web-api for a Web API play with uris, spotify:unknown for such a session transferred in from another device. Published as is, an official client taking over the session tries to resolve the placeholder, fails, and drops the transfer without an error, so the session cannot be moved to the Spotify desktop client. Official clients publish such a session with an empty context_uri and context_url, and empty context_uri/entity_uri track metadata. Do the same in the published copy of the player state only; librespot's own state keeps the placeholder, which its context handling relies on. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TEwfiUtH64EfC6qzuvjRhz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When librespot plays a list of tracks without a context (a Web API
PUT /me/player/playwithuris), the session cannot be transferred to the official Spotify desktop client. The transfer request is accepted (the Web API returns 204, and picking the desktop client in a phone's device menu shows no error), but the desktop client never takes over and playback stays on librespot. librespot itself receives nothing during the attempt.Transfers from librespot to the desktop client work normally when the session has a real context (a playlist, an album,
spotify:user:<id>:collection). Transfers between librespot instances work in both cases.Cause
load_context_from_tracksstores such a list under the placeholder contextspotify:web-api(context_urlcontext://spotify:web-api), and librespot publishes that in itsPutStateRequest:context_uri,context_url, and thecontext_uri/entity_urimetadata of the current, next and previous tracks.Capturing the cluster state the desktop client (1.2.92.147, Linux) publishes for the same Web API
urisplay shows it leaves all of these empty. A client taking over a session resolves the context it is given, andspotify:web-apidoes not resolve, so it drops the transfer.The same happens with a context-less session that was transferred to librespot from an official client:
transfer.rsstores it underspotify:unknown(while the tracks' metadata still sayspotify:web-api), and it cannot be transferred back.Fix
In
ConnectState::send_state, when the context is one of these placeholders (spotify:web-api,spotify:unknown), publish a copy of the player state withcontext_uri/context_urlcleared and the placeholder values in the tracks'context_uri/entity_urimetadata cleared. Only the published copy changes: librespot's own state keeps the placeholder, which the context handling relies on.The comment on
load_context_from_trackssays the placeholder keeps official clients' players from freezing. With this change the desktop client's now-playing bar still shows the track, artist and a running progress bar while librespot plays a bare list. I have only checked the Linux desktop client.Testing
On Debian 13, librespot built from
dev(939dc5e) plus this change, with the pipe backend:urisplay of two tracks on librespot, then Web API transfer to the desktop client: before, nothing happens; after, the desktop client takes over at the same position (0:21 into the track) and plays.urisplay with an offset, then repeated transfers librespot → desktop → librespot → desktop, paused: before, the transfer back to the desktop client is ignored; after, every step works.spotify:user:<id>:collectioncontexts: unchanged, transfer works before and after.urissession: unchanged, works.cargo fmt --all --checkandcargo clippyare clean.The investigation, the fix and this description were done by Claude Code working on my setup, where the patched librespot now runs all my speakers.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TEwfiUtH64EfC6qzuvjRhz