Repository navigation
Conversation
Spotify now sends `PUT /me/player/play` with `uris` to the device as a play command whose context uri is `spotify:webapi`, with the tracks inline. Only an absent uri played the inline tracks, so librespot tried to resolve `spotify:webapi`, got a 400, and failed the command. An empty uri or `spotify:webapi` now counts as absent. librespot published such plays under its own `spotify:web-api`, which autoplay then tried to resolve (400 again), so nothing followed the played tracks. Use Spotify's `spotify:webapi` instead and never resolve it, so autoplay starts from the current track. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
|
Independent confirmation from a second setup, in case it helps review. A stock librespot 0.8.0 device here (Gentoo, x86_64) refused every Two things the description doesn't have:
The device now runs a narrower backport of the same idea on 0.8.0: in the Play arm of I haven't run this branch itself. The device is in use tonight. When it's free I'll build 170fc26, check a Posted by Nexus, an AI agent (Claude) working with Ben, from his account. The runs above are mine, on his machine. |
A transfer played the tracks it carries only under `-` or an empty uri, so one under `spotify:webapi`, which librespot now publishes for tracks played by their uris, resolved its current track and dropped the rest. An empty uri, `-` and `spotify:webapi` are now one placeholder check, shared by Play, the transfer handler and `valid_resolve_uri`; Play now also takes `-` as no uri. Such a transfer continued under `spotify:unknown`, which autoplay then asked for, and was finished by hand: the queue was dropped, the tracks stayed unshuffled with shuffle on, no autoplay was queued, and the transfer failed when its current track wasn't among the tracks. It now continues under `spotify:webapi` and is finished like a transfer of a resolved context, with `finish_transfer` and the autoplay check. The context of tracks is built by `update_context_from_tracks` on `ConnectState`, so the autoplay tests run on a real `ConnectState` and catch a placeholder that would be resolved. The tests are named for what they check, and the absent uri is covered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
`finish_transfer` replaces a current track it can't find among the tracks, such as an autoplay or queued track. Finishing a transfer that brought its tracks before loading therefore played another track than the transferred one. Load first, as the resolved path does, then finish, queue autoplay and emit `set_queue` as after a resolve. A test drives a `SpircTask` with a real player through such a transfer. Ignore context updates while the current context is a placeholder: its tracks came with the play or transfer, and a resolve would replace them. Count the `spotify:web-api` and `spotify:unknown` of older librespot versions as placeholders too, so transfers from them play their tracks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
`finish_transfer` sets up the state from the context, which made the context's track at the index current: with shuffle on even while a queued track played, and the first track when the transferred one wasn't among them, as an autoplay track isn't. The player played the transferred track all the same, so the published state showed another. Put it back after setting up, also when that fails. With that, a transfer that brought its tracks is finished before loading again. A transferred track marked `autoplay.is_autoplay` now gets the autoplay provider, as librespot's own autoplay tracks have. `handle_transfer` checks the provider and `finish_transfer` the metadata, so a transfer during autoplay requested no autoplay context, then failed to finish for lack of it and dropped its queue. Keep such a transfer until autoplay resolves; without a context uri, from the current track. Clear the context resolver when installing the tracks of a play or transfer, as loading a new context uri does, so that a resolve still pending for the previous context can't replace them. Tests drive a `SpircTask` through each case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
Finishing a transfer made a track of the context stand for a transferred track it couldn't find, such as an autoplay track: the first one, or, with a queued track playing before the first one, that one too. The context then continued after it, so that track was passed over, and a shuffle left it out. Now no track of the context stands in: the context follows the transferred track from its first track, and the transferred track has no index in it, as a queued one has none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
A transfer brings its queue, but tracks queued before it stayed, so a transfer arriving while librespot still had a queue queued them twice. Drop them when the transfer starts. Finishing a transfer put the transferred track back only when its uri differed from the context's track set current, so a queued track that is in the context too became the context's occurrence. Compare the provider as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
Finishing a transfer during autoplay with shuffle on shuffled the default context, which also made it the active one again, so the transfer went back to its playlist instead of continuing with autoplay. Shuffle only the default context. A shuffle saved in the transferred context was restored from its start, so the transferred track and those before it were queued again. Resume the restored order after the transferred track. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
|
Another confirmation that this fixes it. Setup: librespot built from e8bac08 on Debian (x86_64), Before (built from 4a00590 on After rebuilding from this branch and restarting the device, the same requests play normally and the previously failing tracks play through to the end. Thanks for the fix! |
By 2026-11-17 Spotify sends a Web API play of track uris under spotify:webapi:<id> (seen: spotify:webapi:2aXd9suNTEFnjREEhPhIjP) as well as the bare spotify:webapi. Resolving it fails with a 400 just as the bare one did, so the play failed and the remote reported "Restriction violated". Any spotify:webapi: uri now counts as no context uri, so the tracks that come with it play. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp14ttrF9CMB9edxaNkR
Problem
Playing tracks through the Web API (
PUT /me/player/playwithuris, as Raycast and other remotes play a search result) fails on a librespot device with "Restriction violated". Spotify sends the device a play command whose context uri isspotify:webapi, with the tracks inline inpages. (Until recently the uri was absent: #1508, fixed by #1509.) Since 2026-11-17 it has also come with an id, as inspotify:webapi:2aXd9suNTEFnjREEhPhIjP. The play handler takes any uri as a context to resolve,context-resolve/v1/spotify:webapianswers 400, the command fails, and the Web API reports the failure to the caller:Because the failed context is then marked unavailable, retries fail at once (
tried loading unavailable context) for an hour, and on 0.8.0, which predates #1655, until a restart.A second bug followed such plays even while they worked: librespot published them under its own placeholder
spotify:web-api, and autoplay asked Spotify for tracks like that placeholder, which isn't a Spotify uri, instead of like the track that played.Transfers have the same gap. The transfer handler plays the tracks a transfer carries only under
-or an empty uri. Underspotify:webapi, which librespot itself publishes for these plays once they work, it resolves the uri instead: a 400 ondev, and with only the fixes above, a resolve of the current track that drops the rest. Where it did play a transfer's tracks, it published them asspotify:unknown(which autoplay then asked for), dropped the transfer's queue, left the tracks unshuffled with shuffle on, queued no autoplay, and failed the transfer when its current track wasn't among the tracks, as an autoplay track isn't. Transfers from older librespot devices carry itsspotify:web-apiorspotify:unknown, which are resolved too. And no transfer during autoplay was handled as one:handle_transferchecks the provider of the transferred track, which is never autoplay, whilefinish_transferchecks itsautoplay.is_autoplaymetadata, so finishing failed for lack of an autoplay context that was never requested, dropping the transferred queue.Change
PlayContextis chosen by a newTryFrom<&Context>inmodel.rs, next to theSkipToconversion: a placeholder uri counts as absent, so the inline tracks are played. The placeholder check,ConnectState::is_placeholder_uri(an empty uri,-,spotify:webapiwith or without:<id>, and thespotify:web-apiandspotify:unknownthat older librespot versions published), is shared by Play, the transfer handler andvalid_resolve_uri, so a transfer under any of them plays the tracks it carries too, and no placeholder is ever resolved. Play now also takes-as no uri.spotify:webapi(WEB_API_IDENTIFIER), whichvalid_resolve_urinever resolves, the way it already skips search contexts. Autoplay then falls back to the track playing when its request is queued: for a play of one or two tracks with nothing queued, the first one played. The context of the tracks is built by the newConnectState::update_context_from_tracks, which tests can reach.spotify:webapiinstead ofspotify:unknown, and is finished like a transfer of a resolved context:finish_transfer(queue, shuffle, current index by uri or uid; an error is logged as intry_finish), then the autoplay check and theset_queueevent that follow a resolve. A transfer during autoplay is kept until its autoplay context resolves, as one of a resolved context is; without a context uri, autoplay resolves from the current track.finish_transferkeeps the transferred track current. Setting up from the context makes the context's track at the index current: with shuffle on even when a queued track plays, and the first track when the transferred one isn't among them, as an autoplay track isn't. The player plays the transferred track all the same, so the published state showed another one, for any transfer. It is now put back afterwards, also when setting up fails, whenever its uri or provider differs, so a queued track that is in the context too stays the queued one. A track outside the context is no longer made to stand for one in it: the context follows it from its first track, which was passed over (also with shuffle on, and after a track queued before the first one), and it has no index in the context, as a queued track has none.autoplay.is_autoplaygets the autoplay provider, which librespot's own autoplay tracks have, sohandle_transferhandles it as autoplay. This also changes transfers of a resolved context during autoplay, whose autoplay branch never ran: they now resolve autoplay (withstation:stripped from the context uri, as that branch does) and are finished once it arrives.handle_initial_transferdrops the tracks queued before, as the transfer brings its own queue: kept, a transfer arriving while librespot still had a queue queued them twice.-or an empty uri has since Fix: Harden the transfer flow for unexpected data #1581.spotify:web-apinever matched an update'sspotify:webapi, so these were ignored anyway.Test
model.rstests coverspotify:webapiwith and without an id, an absent, empty or-uri, the olderspotify:web-apiandspotify:unknown, a real context uri, uris that only resemble the placeholder (spotify:webapiplaylist,spotify:playlist:webapi), which are still resolved, andspotify:webapiwithout pages.context_resolver.rschecks, on aConnectState, that autoplay resolves the current track after tracks played by their uris and after a transfer that brought its tracks. Reverting a fix fails its tests: droppingspotify:webapifrom the placeholder check fails thespotify:webapitests and both autoplay tests, dropping the id form fails thespotify:webapi:<id>case, dropping-fails the-case, and the oldspotify:web-apiorspotify:unknownfails the matching autoplay test.spirc.rstests drive aSpircTask, with a real player but no connection, throughspotify:webapitransfers: one whose current track isn't among its tracks loads that track, keeps it current, and has all its tracks next; a queued track stays current with shuffle on, with every track still to come; a track queued before the first one leaves that one next; a queued track that is in the context too stays the queued one; a transfer replaces a queue left from before; a shuffled transfer during autoplay continues with autoplay; a saved shuffle resumes after the transferred track; a transfer from autoplay is kept until its autoplay context resolves, then finishes with its track current and all the autoplay tracks next; and installing tracks drops a pending resolve. Each fails without its fix. Checked live with the first commit: Raycast plays a search result, and autoplay then queues similar tracks. The id form was checked live on 2026-11-17: a Raycast play that failed underspotify:webapi:<id>plays in a build with the last commit's change. The transfer changes are not checked live.#1867 adds the same
SpircTasktest fixture to atestsmodule at the end ofspirc.rs, and a Fixed line next to these in CHANGELOG.md; I'll rebase whichever merges later.cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspaceare clean, and there are changelog entries under Unreleased → Fixed.🤖 Generated with Claude Code
https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb