[PR #681] [MERGED] fix(spotify): unbreak Game Mode playlist source on Development Mode apps #4727

Closed
opened 2026-10-22 04:10:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/681
Author: @Romuromylus
Created: 5/11/2026
Status: ✅ Merged
Merged: 5/11/2026
Merged by: @Romuromylus

Base: main ← Head: fix/spotify-dev-mode-playlist-support


📝 Commits (4)

  • 1a04d7e fix(spotify/game): use /playlists/{id}/items instead of deprecated /tracks
  • bd27a0a fix(spotify/game): map /playlists/{id}/items "item" wrapper alongside .track
  • a8a66cd fix(spotify/playlists): resolve real track counts; label followed playlists
  • 1c56b78 fix(spotify/playlists): log /me failures, tri-state owned to avoid mislabel

📊 Changes

4 files changed (+121 additions, -33 deletions)

View changed files

📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+23 -8)
📝 packages/client/src/components/game/GameSetupWizard.tsx (+23 -8)
📝 packages/server/src/routes/spotify-auth.routes.ts (+50 -9)
📝 packages/server/src/services/spotify/game-spotify-music.service.ts (+25 -8)

📄 Description

Linked issue

Closes #680

Why this change

After Spotify's 2026-03 Web API migration, Game Mode's playlist source is completely broken for every Spotify Developer app in Development Mode (i.e. anyone who hasn't been granted Extended Quota Mode — which now requires 250k+ MAUs and so excludes essentially all self-hosted / hobby installs). Two distinct breaks:

  1. Playback path — server hits /playlists/{id}/tracks (deprecated). Spotify 403s every call, even for playlists the connected user owns. Scene music never plays from any playlist.
  2. Selection path — dropdown reads playlist.tracks.total from /me/playlists, but Spotify strips the tracks field entirely from those items under Dev Mode. Every playlist renders as Playlist Name (0), leaving users unable to tell which playlist has content and which is empty — or even that the data is unreliable.

The end-to-end effect: a user on a fresh Spotify dev app sees a dropdown of (0) playlists, picks one anyway, and gets a generic failure toast. There is no diagnostic visible to the user — the actual cause (Spotify policy) is invisible.

What changed

Server (packages/server/src/services/spotify/game-spotify-music.service.ts)

  • Switched fetchSpotifyTrackIndex from /playlists/{id}/tracks to /playlists/{id}/items. The replacement endpoint is the supported one and serves content for playlists owned by the connected user under Development Mode.
  • Coalesced the mapper to accept both response shapes: /me/tracks wraps each track under .track, while /playlists/{id}/items wraps the playable under .item (because an item may be a podcast episode). Mapping unchanged downstream.
  • On 403 from a non-liked source, surface a clearer message so the user understands the limitation: "Spotify only allows reading playlists owned by the connected account; followed or editorial playlists are blocked for Development Mode apps."

Server (packages/server/src/routes/spotify-auth.routes.ts)

  • /playlists now resolves real track counts for self-owned playlists by calling /playlists/{id}/items?limit=1 in parallel and using the returned total. The previous code read tracks.total from /me/playlists, which Dev Mode strips, so every entry was 0.
  • Returns trackCount: number | null and a new owned: boolean so the client can render usable counts and label unusable playlists.

Client (packages/client/src/components/chat/ChatSettingsDrawer.tsx, packages/client/src/components/game/GameSetupWizard.tsx)

  • Updated the type for /spotify/playlists to trackCount: number | null and owned: boolean.
  • Dropdown suffix renders:
    • Background (75) — owned, real count known
    • Custom Mix — owned, count unknown for any reason (no misleading (0))
    • Fantasy vibes (followed — unavailable) — followed playlist, picking it will fail

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Verified end-to-end on a live EasyPanel deployment running this branch's commits:

  • Self-owned playlist ("Background", 75 tracks): drop down rendered Background (75); scene-music shortlist returned 75 indexed tracks; sample candidate names (Peace Sign, Hijo de la Luna - Epic Orchestral Version, Hero of Our Time, Count the Teeth, Guren no Yumiya) matched the actual playlist; track played through the SDK device.
  • Self-owned empty playlist ("JQBX :: Queue", 0 tracks): rendered JQBX :: Queue (0); correctly identified as empty by the server.
  • Followed playlist ("Fantasy vibes", owned by another user): rendered Fantasy vibes (followed — unavailable); if explicitly selected and a scene triggered, the new clearer 403 message surfaces ("Spotify denied access to this playlist's contents...") instead of a generic failure.
  • Liked Songs source (control): still works unchanged — /me/tracks path uses the existing .track wrapper which the coalesced mapper still handles.
  • "Any Spotify" source (control): still works unchanged — /search path is untouched by this PR.

Manual verification to perform locally before merge:

  • Manually verify on a Dev Mode Spotify app: playlist dropdown shows real counts for self-owned playlists and (followed — unavailable) for followed ones.
  • Manually verify scene playback from a self-owned playlist with the in-app Web Playback SDK device registered (i.e. mini player toggled on).
  • Manually verify Liked Songs source still produces a non-empty shortlist.
  • Manually verify that on an Extended Quota Mode app (if accessible) the existing behavior still holds — tracks.total if Spotify provides it, otherwise the new /items lookup fills it in.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

N/A — the visible change is the dropdown suffix; no layout or theming changes. (The before-state, Background (0), is documented in #680 with a screenshot.)

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of Spotify playlists with unavailable or missing track count information
    • Playlist selection now displays clearer availability indicators: owned playlists omit track count when unavailable, while followed playlists clearly show "(followed — unavailable)" status
    • Enhanced reliability of Spotify track count retrieval and playlist indexing through optimized data fetching

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/681 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/11/2026 **Status:** ✅ Merged **Merged:** 5/11/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/spotify-dev-mode-playlist-support` --- ### 📝 Commits (4) - [`1a04d7e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1a04d7e209d48a141840fee3523be6f168b74017) fix(spotify/game): use /playlists/{id}/items instead of deprecated /tracks - [`bd27a0a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bd27a0af27ae2ce9755a69e7ebfcd44d900b82db) fix(spotify/game): map /playlists/{id}/items "item" wrapper alongside .track - [`a8a66cd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a8a66cdcb382953d99eda53080ef704021aa9d5d) fix(spotify/playlists): resolve real track counts; label followed playlists - [`1c56b78`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c56b78af9cf17f9370cc95148cde35492903fc8) fix(spotify/playlists): log /me failures, tri-state owned to avoid mislabel ### 📊 Changes **4 files changed** (+121 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+23 -8) 📝 `packages/client/src/components/game/GameSetupWizard.tsx` (+23 -8) 📝 `packages/server/src/routes/spotify-auth.routes.ts` (+50 -9) 📝 `packages/server/src/services/spotify/game-spotify-music.service.ts` (+25 -8) </details> ### 📄 Description ## Linked issue Closes #680 ## Why this change After Spotify's 2026-03 Web API migration, Game Mode's `playlist` source is completely broken for every Spotify Developer app in Development Mode (i.e. anyone who hasn't been granted Extended Quota Mode — which now requires 250k+ MAUs and so excludes essentially all self-hosted / hobby installs). Two distinct breaks: 1. **Playback path** — server hits `/playlists/{id}/tracks` (deprecated). Spotify 403s every call, even for playlists the connected user owns. Scene music never plays from any playlist. 2. **Selection path** — dropdown reads `playlist.tracks.total` from `/me/playlists`, but Spotify strips the `tracks` field entirely from those items under Dev Mode. Every playlist renders as `Playlist Name (0)`, leaving users unable to tell which playlist has content and which is empty — or even that the data is unreliable. The end-to-end effect: a user on a fresh Spotify dev app sees a dropdown of `(0)` playlists, picks one anyway, and gets a generic failure toast. There is no diagnostic visible to the user — the actual cause (Spotify policy) is invisible. ## What changed Server (`packages/server/src/services/spotify/game-spotify-music.service.ts`) - Switched `fetchSpotifyTrackIndex` from `/playlists/{id}/tracks` to `/playlists/{id}/items`. The replacement endpoint is the supported one and serves content for playlists owned by the connected user under Development Mode. - Coalesced the mapper to accept both response shapes: `/me/tracks` wraps each track under `.track`, while `/playlists/{id}/items` wraps the playable under `.item` (because an item may be a podcast episode). Mapping unchanged downstream. - On 403 from a non-`liked` source, surface a clearer message so the user understands the limitation: \"Spotify only allows reading playlists owned by the connected account; followed or editorial playlists are blocked for Development Mode apps.\" Server (`packages/server/src/routes/spotify-auth.routes.ts`) - `/playlists` now resolves real track counts for self-owned playlists by calling `/playlists/{id}/items?limit=1` in parallel and using the returned `total`. The previous code read `tracks.total` from `/me/playlists`, which Dev Mode strips, so every entry was 0. - Returns `trackCount: number | null` and a new `owned: boolean` so the client can render usable counts and label unusable playlists. Client (`packages/client/src/components/chat/ChatSettingsDrawer.tsx`, `packages/client/src/components/game/GameSetupWizard.tsx`) - Updated the type for `/spotify/playlists` to `trackCount: number | null` and `owned: boolean`. - Dropdown suffix renders: - `Background (75)` — owned, real count known - `Custom Mix` — owned, count unknown for any reason (no misleading `(0)`) - `Fantasy vibes (followed — unavailable)` — followed playlist, picking it will fail ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Verified end-to-end on a live EasyPanel deployment running this branch's commits: - **Self-owned playlist** (\"Background\", 75 tracks): drop down rendered `Background (75)`; scene-music shortlist returned 75 indexed tracks; sample candidate names (Peace Sign, Hijo de la Luna - Epic Orchestral Version, Hero of Our Time, Count the Teeth, Guren no Yumiya) matched the actual playlist; track played through the SDK device. - **Self-owned empty playlist** (\"JQBX :: Queue\", 0 tracks): rendered `JQBX :: Queue (0)`; correctly identified as empty by the server. - **Followed playlist** (\"Fantasy vibes\", owned by another user): rendered `Fantasy vibes (followed — unavailable)`; if explicitly selected and a scene triggered, the new clearer 403 message surfaces (\"Spotify denied access to this playlist's contents...\") instead of a generic failure. - **Liked Songs source** (control): still works unchanged — `/me/tracks` path uses the existing `.track` wrapper which the coalesced mapper still handles. - **\"Any Spotify\" source** (control): still works unchanged — `/search` path is untouched by this PR. Manual verification to perform locally before merge: - Manually verify on a Dev Mode Spotify app: playlist dropdown shows real counts for self-owned playlists and `(followed — unavailable)` for followed ones. - Manually verify scene playback from a self-owned playlist with the in-app Web Playback SDK device registered (i.e. mini player toggled on). - Manually verify Liked Songs source still produces a non-empty shortlist. - Manually verify that on an Extended Quota Mode app (if accessible) the existing behavior still holds — `tracks.total` if Spotify provides it, otherwise the new `/items` lookup fills it in. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) N/A — the visible change is the dropdown suffix; no layout or theming changes. (The before-state, `Background (0)`, is documented in #680 with a screenshot.) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of Spotify playlists with unavailable or missing track count information * Playlist selection now displays clearer availability indicators: owned playlists omit track count when unavailable, while followed playlists clearly show "(followed — unavailable)" status * Enhanced reliability of Spotify track count retrieval and playlist indexing through optimized data fetching [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/681) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:09 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4727
No description provided.