Skip to content

feat: scrobble playback for ListenBrainz/Last.fm integration (#1)#82

Merged
klay2000 merged 1 commit into
mainfrom
issue-1
Jun 15, 2026
Merged

feat: scrobble playback for ListenBrainz/Last.fm integration (#1)#82
klay2000 merged 1 commit into
mainfrom
issue-1

Conversation

@klay2000

Copy link
Copy Markdown
Owner

Summary

  • Closes Add ListenBrainz Integration #1 — "Add ListenBrainz Integration"
  • Gonic already supports forwarding scrobbles to Last.fm/ListenBrainz (configured server-side in Gonic's admin settings), but only if the Subsonic client calls the standard /rest/scrobble endpoint. This client never did. This PR adds that call.
  • Adds scrobble(id, { submission, time }) to src/lib/api/subsonic.js, following the existing request()/buildUrl() pattern. Best-effort — errors are swallowed and never interrupt playback.
  • Adds a pure helper shouldSubmitScrobble(elapsedSeconds, durationSeconds) to src/lib/stores/playerLogic.js implementing the standard Last.fm/ListenBrainz threshold: a track counts as "played" once it's been listened to for 4 minutes OR 50% of its duration, whichever comes first.
  • Wires both into PlayerBar.svelte:
    • On track change: fires a "now playing" scrobble (submission=false) and resets a per-track scrobbled flag.
    • In onTimeUpdate: once shouldSubmitScrobble returns true and the track hasn't been scrobbled yet, fires the final scrobble (submission=true) and sets the flag so it only fires once per track.

Test plan

  • npm test passes (53/53, including 5 new tests for shouldSubmitScrobble covering the 4-minute cap, 50% threshold, and unknown-duration cases)
  • npm run build passes
  • Needs verification against a real Gonic instance (not possible in this sandbox — no server credentials): play a track and confirm
    • Gonic's scrobble logs show both a "now playing" and a final scrobble request
    • If Last.fm/ListenBrainz forwarding is configured in Gonic's admin settings, the track shows up as "now playing" on ListenBrainz, then gets scrobbled after the threshold

🤖 Generated with Claude Code

Gonic can forward scrobbles to Last.fm/ListenBrainz, but only if the
client calls the standard /rest/scrobble endpoint. Add scrobble() to
the Subsonic API client and wire PlayerBar to call it: a "now playing"
scrobble (submission=false) when a track starts, and a final scrobble
(submission=true) once the track has played 4 minutes or 50% of its
duration, whichever comes first. Both are fire-and-forget and never
block playback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@klay2000 klay2000 merged commit 5bf02a4 into main Jun 15, 2026
1 check passed
@klay2000 klay2000 deleted the issue-1 branch June 15, 2026 22:13
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.

Add ListenBrainz Integration

1 participant