Skip to content

fix(apple-music): show each playlist's real track count - #910

Merged
LargeModGames merged 3 commits into
LargeModGames:mainfrom
kapok-4o:fix/apple-music-playlist-counts
Oct 21, 2026
Merged

LargeModGames merged 3 commits into
LargeModGames:mainfrom
kapok-4o:fix/apple-music-playlist-counts

Conversation

@kapok-4o

@kapok-4o kapok-4o commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #891. With Apple Music as the source, every playlist in the GUI's Your Library panel, "All songs" included, said Playlist · 0 songs, because nothing ever asked Music for a count.

  • src/infra/apple_music/music.js: the playlists op returns count with each playlist (p.tracks.length, one Apple Event per playlist; the bulk music.playlists.tracks.length answers 0, so it cannot replace it). The first page also carries library, the library's own count. A count Music cannot read comes back as null.
  • src/infra/apple_music/mod.rs: parse_playlists puts count into track_count and returns the library count alongside the page. Both fields are optional, so an older helper's reply still parses.
  • src/infra/apple_music/dispatch.rs and src/core/app/apple_music.rs: the first page's library count fills the synthetic "All songs" row (set_apple_music_library_count).
  • A count Music cannot read is not shown as 0. PlaylistInfo.track_count stays a plain number shared by every source; instead the Apple Music state keeps the rows whose count is unknown (every page's null counts, and "All songs" until the library is sized), and SourcePlaylists.apple_music_uncounted lists them. playlistsFor in gui/src/libraryModel.ts gives those rows no count, so the panel shows Playlist instead of Playlist · 0 songs. gui/src/bindings/SourcePlaylists.ts is regenerated.
  • CHANGELOG.md: a line under Unreleased, Fixed.
  • Tests: apple_music_playlists_carry_their_track_counts (counts, an unreadable count, the library count only on the first page, an unreadable library), apple_music_all_songs_row_takes_the_library_count (unknown until sized, reset on reload), apple_music_rows_without_a_count_are_listed_as_uncounted (the GUI payload), and a playlistsFor case in gui/src/libraryModel.test.ts.

The terminal sidebar does not print Apple Music counts, so it looks the same as before.

Testing

macOS 27.2 (aarch64), on top of 837308b1:

  • Against the running Music app (17 playlists): every playlist came back with its count, the library with 1,582 tracks, and the whole playlists call took 0.79s.
  • cargo fmt --all --check: clean. cargo clippy --locked -- -D warnings on slim (telemetry,tui) and on the macOS CI feature set (with apple-music): clean.
  • cargo clippy --locked -- -D warnings also on the gui CI feature set and on telemetry alone: clean.
  • cargo test --locked: default plus apple-music 2225 passed, 8 ignored; slim 1721 passed; the gui CI feature set 1914 passed, 8 ignored, and the regenerated bindings are committed.
  • gui/: npm run lint, format:check, typecheck, test (525 passed) and build: clean.

Summary by CodeRabbit

  • Bug Fixes
    • Apple Music playlist track counts now display accurate values, including the “All songs” count.
    • Playlists with unavailable track counts no longer display an incorrect count of 0; their count is omitted instead.
    • Apple Music library counts now update correctly when available and remain blank when unavailable.

Music's playlist listing returned only ids and names, so every Apple Music
playlist, and the synthetic "All songs" row, reached the GUI with
track_count 0 and read "Playlist · 0 songs".

The playlists op now reads each listed playlist's count (one Apple Event,
about 8ms, per playlist) and sizes the library on the first page. A count
Music cannot read stays 0, as before.

Fixes LargeModGames#891
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 01de0d58-9a3f-47e9-844c-507e8b1cfb64
📥 Commits

Reviewing files that changed from the base of the PR and between 913e9a8 and f896358.

⛔ Files ignored due to path filters: 1
  • gui/src/bindings/SourcePlaylists.ts is excluded by !gui/src/bindings/**
📒 Files selected for processing: 1
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes: 1
  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

Apple Music playlist responses now include track counts and optional first-page library metadata. Rust parsing and app state preserve unknown counts. The GUI displays unknown counts as omitted instead of 0, and updates the synthetic “All songs” row when a library count is available.

Changes: Apple Music playlist counts

Layer / File(s) Summary
Return and parse count metadata
src/infra/apple_music/music.js, src/infra/apple_music/mod.rs
The Music operation returns playlist counts and first-page library metadata. Rust parsing preserves unavailable counts and explicit library values.
Apply counts to Apple Music state
src/infra/apple_music/dispatch.rs, src/core/app/apple_music.rs, src/tui/ui/localization_tests.rs
Dispatch passes unknown playlist URIs and optional library counts into app state. The synthetic “All songs” row updates when a count is present. Reloads clear unknown-count markers.
Expose unknown counts in the GUI
src/gui/protocol.rs, gui/src/libraryModel.ts, gui/src/libraryModel.test.ts
The protocol exposes unknown Apple Music playlist URIs. The library model maps those rows to count: null.
Update fixtures and changelog
gui/e2e/fixtures.ts, gui/src/library.test.tsx, gui/src/libraryPanel.test.tsx, gui/src/mainLocalization.test.tsx, CHANGELOG.md
Fixtures include the new collection. Tests and the changelog reflect the count behavior.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant Music
  participant music_js
  participant RustParser
  participant Dispatch
  participant AppState
  participant GUI
  Music->>music_js: Read playlist counts
  music_js->>RustParser: Return counts and library metadata
  RustParser->>Dispatch: Provide PlaylistsPage
  Dispatch->>AppState: Store counts and unknown URIs
  AppState->>GUI: Expose playlist rows and unknown-count URIs
Loading
Merge Risk: ⚪ Minimal · up to f8963

No actionable merge-blocking issue is established for the Apple Music count update; it is ready for normal merge checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses the valid conventional-commit prefix fix, includes an appropriate scope, and concisely describes the Apple Music playlist count correction.
Linked Issues check Passed Issue #891 requires real Apple Music counts, correct parsing, and an unknown-count fallback in the GUI. music.js reads each playlist count and returns null when unavailable. parse_playlists pres…
Out of Scope Changes check Passed The JavaScript, Rust, GUI, fixture, test, and changelog changes support Issue #891. The added protocol field carries the Apple Music unknown-count state required by the GUI. Fixture updates support th…
Full details: Linked Issues check

Explanation

Issue #891 requires real Apple Music counts, correct parsing, and an unknown-count fallback in the GUI. music.js reads each playlist count and returns null when unavailable. parse_playlists preserves counts and the first-page library count. Apple Music state updates the synthetic “All songs” row and tracks unknown rows. playlistsFor maps unknown rows to count: null, so the GUI omits 0 songs. Focused Rust and GUI tests cover these cases. The PR also reports successful Music-based testing on macOS.

Full details: Out of Scope Changes check

Explanation

The JavaScript, Rust, GUI, fixture, test, and changelog changes support Issue #891. The added protocol field carries the Apple Music unknown-count state required by the GUI. Fixture updates support that field. No unrelated change is demonstrated.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-merge checks failed. Please resolve the failing checks before merging.

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.47368% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/app/apple_music.rs 24.0% 19 Missing ⚠️
src/infra/apple_music/dispatch.rs 0.0% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

A playlist whose count Music could not read, and "All songs" before the
library is sized, still carried track_count 0, which the GUI shows as
"Playlist · 0 songs".

The Apple Music state now keeps the rows whose count is unknown, and
SourcePlaylists.apple_music_uncounted lists them, so the panel shows
"Playlist" for those rows. PlaylistInfo.track_count stays a plain number
shared by every source.

@LargeModGames LargeModGames left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A count Music can't read still ends up as 0 songs: p.count.unwrap_or(0) turns the null back into the value #891 is about, and "All songs" keeps its 0 when library is null. Per step 3 of the issue, carry the unknown through to the page so the row shows just Playlist, either with an optional track_count or with an Apple Music rule in the GUI.

@kapok-4o

Copy link
Copy Markdown
Collaborator Author

Thanks! The follow-up commit 913e9a8 does this with an Apple Music rule, keeping track_count a plain number: parse_playlists reports each null count in uncounted, the Apple Music state keeps those rows (and "All songs" until the library is sized; a null library leaves it there), SourcePlaylists.apple_music_uncounted lists them, and playlistsFor in gui/src/libraryModel.ts gives them count: null, so the panel shows just Playlist. The unwrap_or(0) only fills the shared field's placeholder. Tests: apple_music_rows_without_a_count_are_listed_as_uncounted, apple_music_all_songs_row_takes_the_library_count, and the playlistsFor case in libraryModel.test.ts. Happy to switch to an optional track_count instead if you prefer that.

@LargeModGames
LargeModGames merged commit 4b57774 into LargeModGames:main Oct 21, 2026
32 checks passed
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.

GUI: Apple Music playlists show "0 songs" in Your Library

2 participants