mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
fix(play tracker): record local play count even if external scrobbling is disabled on the player (#6387)
This commit is contained in:
parent
2fecb718c0
commit
ff58ca5d1f
@ -363,22 +363,29 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
||||
case StateStopped:
|
||||
var loadedMF *model.MediaFile
|
||||
haveVerdict := false
|
||||
if !params.IgnoreScrobble && player.ScrobbleEnabled {
|
||||
if !params.IgnoreScrobble {
|
||||
mf, err := p.ds.MediaFile().GetWithParticipants(ctx, params.MediaId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
loadedMF = mf
|
||||
filtered = p.isFilteredOut(ctx, mf)
|
||||
haveVerdict = true
|
||||
trackDurationMs := int64(mf.Duration * 1000)
|
||||
threshold := min(trackDurationMs*50/100, 240_000)
|
||||
if params.PositionMs >= threshold {
|
||||
err = p.incPlay(ctx, mf, now)
|
||||
if err != nil {
|
||||
log.Warn(ctx, "Error updating play counts", "id", mf.ID, "track", mf.Title, "user", user.UserName, err)
|
||||
// If the track is not found, do not treat it as a fatal error.
|
||||
// Log it and move on so that the session can still be closed
|
||||
log.Warn(ctx, "Cannot find track for scrobbling", "id", params.MediaId, "user", user.UserName, err)
|
||||
} else {
|
||||
loadedMF = mf
|
||||
filtered = p.isFilteredOut(ctx, mf)
|
||||
haveVerdict = true
|
||||
trackDurationMs := int64(mf.Duration * 1000)
|
||||
threshold := min(trackDurationMs*50/100, 240_000)
|
||||
if params.PositionMs >= threshold {
|
||||
// To be consistent with Submit (/rest/scrobble?submission=true), play should be incremented even if
|
||||
// scrobbling is disabled
|
||||
err = p.incPlay(ctx, mf, now)
|
||||
if err != nil {
|
||||
log.Warn(ctx, "Error updating play counts", "id", mf.ID, "track", mf.Title, "user", user.UserName, err)
|
||||
}
|
||||
if player.ScrobbleEnabled {
|
||||
p.dispatchScrobble(ctx, mf, now, filtered)
|
||||
}
|
||||
}
|
||||
p.dispatchScrobble(ctx, mf, now, filtered)
|
||||
}
|
||||
}
|
||||
p.sessionsMu.Lock()
|
||||
|
||||
@ -315,12 +315,15 @@ var _ = Describe("PlayTracker", func() {
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("does not send track to agent if player is not enabled to send scrobbles", func() {
|
||||
It("does not send track to agent if player is not enabled to send scrobbles (but should still track internally)", func() {
|
||||
ctx = request.WithPlayer(ctx, model.Player{ScrobbleEnabled: false})
|
||||
|
||||
err := tracker.Submit(ctx, []Submission{{TrackID: "123", Timestamp: time.Now()}})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(track.PlayCount).To(Equal(int64(1)))
|
||||
Expect(album.PlayCount).To(Equal(int64(1)))
|
||||
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeFalse())
|
||||
})
|
||||
|
||||
@ -811,7 +814,8 @@ var _ = Describe("PlayTracker", func() {
|
||||
MediaId: "123", PositionMs: 90000, State: "stopped", PlaybackRate: 1.0, ClientId: defaultClientId,
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(track.PlayCount).To(Equal(int64(0)))
|
||||
Expect(track.PlayCount).To(Equal(int64(1)))
|
||||
Consistently(func() bool { return fake.ScrobbleCalled.Load() }).Should(BeFalse())
|
||||
})
|
||||
|
||||
It("scrobbles twice for two separate sessions of same song", func() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user