Repository navigation
fix(counter): count plays from every source - #564
Conversation
Since v0.40.3 a song played through native streaming sent no count: bbc4668 made the native track id equal the poll's id, and the poll counted only on a mismatch. Count in the driver tick from the playback snapshot instead, for every source, after 30 s of heard play. Radio counts one song per 150 s.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: LargeModGames/spotatui/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughGlobal song counting now uses playback snapshots instead of new-track detection in the Spotify playback poll. It counts qualifying track playback and radio listening intervals across supported sources. ChangesGlobal Song Counting
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Driver
participant App
participant PlayCounter
participant IoEvent
Driver->>PlayCounter: Pass app and current playback snapshot to tick
PlayCounter->>App: Check whether a decoded change is pending
PlayCounter->>IoEvent: Dispatch increment when a play count is due
Merge Risk: ⚪ Minimal · up to Global song counting now counts plays from playback progress across all sources instead of counting track changes in the Spotify poll. The only effect is on anonymous counter telemetry; playback itself is unaffected, and the change is gated by the existing opt-in setting. No blocking issues were found, so this is ready to merge. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
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. Comment |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Summary
The global song counter lost momentum because of a regression in v0.40.3. The only count was sent from the
me/playerpoll, when the API's track id differed fromlast_track_id. Native streaming wrote librespot's fullspotify:track:<id>URI there, so the first confirming poll always saw a mismatch and counted each track once, by accident. bbc4668 (#385) normalized those ids to base62, and since then a song played on the spotatui device itself sends no count. The chart's daily rate went from about 3,700 in July to about 1,450 in September, starting the week v0.40.3 shipped.This PR moves the counter off the Spotify poll into the driver tick, where it reads the same source-neutral playback snapshot as lyrics and cover art, so every source counts:
src/core/driver/play_count.rs(new): a song counts after 30 s of heard audio (half its length when shorter), for native Spotify, a remote Connect device, both queue slots, Local, Subsonic, Qobuz, YouTube and episodes. Internet radio counts one song per 150 s of heard audio.App::decoded_change_pendingholds the counter while a decoded source changes tracks, when the snapshot already names the next track but the sink still plays the last one.me/playerhandler is removed, so a remote-device track does not count twice.Stoppedarm and the unavailable-track halt now setnative_is_playing = Some(false). Before, the next poll copied the staleSome(true)back into the context, so the playbar showed a stopped player as playing.Testing
cargo fmt --all -- --check: cleancargo clippy -- -D warningsfor the default,all-sources, slim, headless (telemetry) and headless-streaming (telemetry,streaming) legs, plus radio-only and local-only builds: all passcargo test --no-default-features --features telemetry,tui: 1130 passed, includingratchet_counters_match_the_checked_in_baselinescargo test: 1469 passedplay_count.rscover the rules above, including a native track throughcurrent_playback_snapshotNot verified: live playback on any source, the macOS leg, and the
all-sourcestest leg locally. Theevents.rschanges anddecoded_change_pendinghave no unit test, because both need a real player or output device.Additional notes
test_attribute_totalmoves from 2063 to 2083 (the adoption direction).💬 Questions or want to chat with other contributors? Join the spotatui Discord.
Summary by CodeRabbit