mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-27 20:39:53 +01:00
feat(scrobbler): add per-user scrobble filter (#5964)
* feat(scrobbler): add scrobble_filter column to user * feat(scrobbler): validate scrobble filter criteria on user save * refactor(persistence): make smart playlist join helpers package-level * feat(scrobbler): add MediaFileRepository.MatchesCriteria * feat(scrobbler): filter external scrobbles with per-user criteria * feat(ui): add scrobble filter field to user form * fix(scrobbler): default scrobble_filter to empty string for existing users * refactor(scrobbler): also gate playback reports on the scrobble filter Playback reports carry the same track metadata to plugin scrobblers, so a filtered track leaked through that third dispatch path. Skip the filter evaluation entirely when no scrobbler is active. * refactor(persistence): move criteria join building into criteria_sql.go The join set a criteria needs was decided in criteria_sql.go but built in smart_playlist_repository.go, so both callers had to pair the two by hand. * refactor(persistence): unexport smartPlaylistCriteria methods The type never leaves the package, so the exported names advertised an API that callers outside persistence could never reach. Also disambiguates where/orderBy from squirrel's SelectBuilder methods of the same name. * fix(ui): cap the scrobble filter field width fullWidth stretched it across the whole page next to 256px inputs. Bounded at 40em, with two rows and a resize handle so JSON rules stay readable. * refactor(ui): move scrobble filter input in UserEdit component * feat(ui): add pt-BR translations for the scrobble filter * fix(scrobbler): take the filter verdict before incPlay incPlay mutates play counts and dates a filter can test on, so evaluating at dispatch time let one play decide differently on either side of the increment: a track could be scrobbled despite matching, or lose only its stopped report and strand presence plugins. Reject limit/offset too, rather than silently ignoring part of a rule copied from a smart playlist. * fix(scrobbler): filter the report from an expired session The expiry callback runs with a stub user carrying no filter, so evaluating there always returned false and leaked the track to plugin scrobblers. That is the normal path for clients that never send stopped, such as legacy Subsonic now-playing. Carry the last verdict on the session instead. * refactor(scrobbler): skip the now-playing enqueue instead of threading the verdict Queuing an entry only to drop it at dispatch also cancelled a pending announcement for the previous, unfiltered track, since the queue is keyed by player and a new entry replaces the old one. * fix(scrobbler): evaluate the filter regardless of active scrobblers The verdict is stored on the session and dispatched at expiry, so skipping evaluation when no scrobbler was active let a plugin enabled mid-session receive a filtered track. The empty-filter guard above already gives servers without scrobbling the same free path, so the shortcut only ever applied to users who had a filter set.
This commit is contained in:
parent
5b87a60b5d
commit
82fde00ecc
21 changed files with 590 additions and 112 deletions
|
|
@ -2,6 +2,7 @@ package scrobbler
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"maps"
|
||||
"slices"
|
||||
"sync"
|
||||
|
|
@ -11,6 +12,7 @@ import (
|
|||
"github.com/navidrome/navidrome/consts"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/model/criteria"
|
||||
"github.com/navidrome/navidrome/model/request"
|
||||
"github.com/navidrome/navidrome/server/events"
|
||||
"github.com/navidrome/navidrome/utils/cache"
|
||||
|
|
@ -43,6 +45,10 @@ type PlaybackSession struct {
|
|||
PositionMs int64
|
||||
PlaybackRate float64
|
||||
LastReport time.Time
|
||||
|
||||
// Verdict from the last report, for the expiry callback: its context carries only
|
||||
// a stub user, so it cannot evaluate the filter itself.
|
||||
filtered bool
|
||||
}
|
||||
|
||||
type Submission struct {
|
||||
|
|
@ -68,8 +74,9 @@ type nowPlayingEntry struct {
|
|||
}
|
||||
|
||||
type playbackReportEntry struct {
|
||||
ctx context.Context
|
||||
info PlaybackSession
|
||||
ctx context.Context
|
||||
info PlaybackSession
|
||||
filtered bool
|
||||
}
|
||||
|
||||
type PlayTracker interface {
|
||||
|
|
@ -145,7 +152,7 @@ func newPlayTracker(ds model.DataStore, broker events.Broker, pluginManager Plug
|
|||
log.Trace("Enqueueing PlaybackReport for expired session", "session", info)
|
||||
info.State = StateExpired
|
||||
info.LastReport = time.Now()
|
||||
p.enqueuePlaybackReport(ctx, info)
|
||||
p.enqueuePlaybackReport(ctx, info, info.filtered)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -273,6 +280,10 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
|
||||
now := time.Now()
|
||||
|
||||
// One verdict per report, reused by every dispatch below, so a filter reading
|
||||
// annotations cannot decide differently on either side of incPlay.
|
||||
var filtered bool
|
||||
|
||||
switch params.State {
|
||||
case StateStarting:
|
||||
// Clients may send starting/playing unordered; a late "starting" must not downgrade
|
||||
|
|
@ -285,8 +296,10 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filtered = p.isFilteredOut(ctx, mf)
|
||||
info := PlaybackSession{
|
||||
MediaFile: *mf,
|
||||
filtered: filtered,
|
||||
Start: now,
|
||||
UserId: user.ID,
|
||||
Username: user.UserName,
|
||||
|
|
@ -309,7 +322,7 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
if err != nil {
|
||||
log.Warn(ctx, "Error adding PlaybackSession to cache", "clientId", clientId, "mediaId", params.MediaId, "state", params.State, err)
|
||||
}
|
||||
p.enqueuePlaybackReport(ctx, info)
|
||||
p.enqueuePlaybackReport(ctx, info, filtered)
|
||||
|
||||
case StatePlaying, StatePaused:
|
||||
info, getErr := p.playMap.Get(clientId)
|
||||
|
|
@ -331,6 +344,8 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
info.PositionMs = params.PositionMs
|
||||
info.PlaybackRate = params.PlaybackRate
|
||||
info.LastReport = now
|
||||
filtered = p.isFilteredOut(ctx, &info.MediaFile)
|
||||
info.filtered = filtered
|
||||
ttl := 30 * time.Minute
|
||||
if params.State == StatePlaying {
|
||||
ttl = remainingTTL(info.MediaFile.Duration, params.PositionMs, params.PlaybackRate)
|
||||
|
|
@ -342,16 +357,19 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
if err != nil {
|
||||
log.Warn(ctx, "Error updating PlaybackSession in cache", "clientId", clientId, "mediaId", params.MediaId, "state", params.State, err)
|
||||
}
|
||||
p.enqueuePlaybackReport(ctx, info)
|
||||
p.enqueuePlaybackReport(ctx, info, filtered)
|
||||
|
||||
case StateStopped:
|
||||
var loadedMF *model.MediaFile
|
||||
haveVerdict := false
|
||||
if !params.IgnoreScrobble && player.ScrobbleEnabled {
|
||||
mf, err := p.ds.MediaFile(ctx).GetWithParticipants(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 {
|
||||
|
|
@ -359,7 +377,7 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
if err != nil {
|
||||
log.Warn(ctx, "Error updating play counts", "id", mf.ID, "track", mf.Title, "user", user.UserName, err)
|
||||
}
|
||||
p.dispatchScrobble(ctx, mf, now)
|
||||
p.dispatchScrobble(ctx, mf, now, filtered)
|
||||
}
|
||||
}
|
||||
p.sessionsMu.Lock()
|
||||
|
|
@ -397,7 +415,10 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
}
|
||||
stoppedInfo.MediaFile = *mf
|
||||
}
|
||||
p.enqueuePlaybackReport(ctx, stoppedInfo)
|
||||
if !haveVerdict {
|
||||
filtered = p.isFilteredOut(ctx, &stoppedInfo.MediaFile)
|
||||
}
|
||||
p.enqueuePlaybackReport(ctx, stoppedInfo, filtered)
|
||||
}
|
||||
|
||||
if conf.Server.EnableNowPlaying {
|
||||
|
|
@ -413,7 +434,9 @@ func (p *playTracker) ReportPlayback(ctx context.Context, params ReportPlaybackP
|
|||
// scrobbler plugins) returned by getActiveScrobblers; see dispatchNowPlaying.
|
||||
if player.ScrobbleEnabled &&
|
||||
(params.State == StateStarting || params.State == StatePlaying) {
|
||||
if info, err := p.playMap.Get(clientId); err == nil {
|
||||
if filtered {
|
||||
log.Debug(ctx, "Ignoring external NowPlaying update for filtered track", "mediaId", params.MediaId)
|
||||
} else if info, err := p.playMap.Get(clientId); err == nil {
|
||||
p.enqueueNowPlaying(ctx, clientId, user.ID, &info.MediaFile, int(params.PositionMs/1000))
|
||||
}
|
||||
}
|
||||
|
|
@ -452,6 +475,7 @@ func (p *playTracker) Submit(ctx context.Context, submissions []Submission) erro
|
|||
log.Error(ctx, "Cannot find track for scrobbling", "id", s.TrackID, "user", username, err)
|
||||
continue
|
||||
}
|
||||
filtered := p.isFilteredOut(ctx, mf)
|
||||
err = p.incPlay(ctx, mf, s.Timestamp)
|
||||
if err != nil {
|
||||
log.Error(ctx, "Error updating play counts", "id", mf.ID, "track", mf.Title, "user", username, err)
|
||||
|
|
@ -460,7 +484,7 @@ func (p *playTracker) Submit(ctx context.Context, submissions []Submission) erro
|
|||
event.With("song", mf.ID).With("album", mf.AlbumID).With("artist", mf.AlbumArtistID)
|
||||
log.Info(ctx, "Scrobbled", "title", mf.Title, "artist", mf.Artist, "user", username, "timestamp", s.Timestamp)
|
||||
if player.ScrobbleEnabled {
|
||||
p.dispatchScrobble(ctx, mf, s.Timestamp)
|
||||
p.dispatchScrobble(ctx, mf, s.Timestamp, filtered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -494,11 +518,36 @@ func (p *playTracker) incPlay(ctx context.Context, track *model.MediaFile, times
|
|||
})
|
||||
}
|
||||
|
||||
func (p *playTracker) dispatchScrobble(ctx context.Context, t *model.MediaFile, playTime time.Time) {
|
||||
// Take this verdict before incPlay mutates what a filter reads, and independently of
|
||||
// which scrobblers are active: it can be stored on a session and dispatched much later.
|
||||
// Any parse or query failure fails open, because filtering must not break scrobbling.
|
||||
func (p *playTracker) isFilteredOut(ctx context.Context, t *model.MediaFile) bool {
|
||||
u, _ := request.UserFrom(ctx)
|
||||
if u.ScrobbleFilter == "" {
|
||||
return false
|
||||
}
|
||||
var c criteria.Criteria
|
||||
if err := json.Unmarshal([]byte(u.ScrobbleFilter), &c); err != nil {
|
||||
log.Warn(ctx, "Invalid scrobble filter, ignoring", "user", u.UserName, err)
|
||||
return false
|
||||
}
|
||||
match, err := p.ds.MediaFile(ctx).MatchesCriteria(t.ID, c)
|
||||
if err != nil {
|
||||
log.Warn(ctx, "Error evaluating scrobble filter, ignoring", "user", u.UserName, "track", t.Title, err)
|
||||
return false
|
||||
}
|
||||
return match
|
||||
}
|
||||
|
||||
func (p *playTracker) dispatchScrobble(ctx context.Context, t *model.MediaFile, playTime time.Time, filtered bool) {
|
||||
if t.Artist == consts.UnknownArtist {
|
||||
log.Debug(ctx, "Ignoring external Scrobble for track with unknown artist", "track", t.Title, "artist", t.Artist)
|
||||
return
|
||||
}
|
||||
if filtered {
|
||||
log.Debug(ctx, "Ignoring external Scrobble for filtered track", "track", t.Title, "artist", t.Artist)
|
||||
return
|
||||
}
|
||||
|
||||
allScrobblers := p.getActiveScrobblers()
|
||||
u, _ := request.UserFrom(ctx)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/navidrome/navidrome/consts"
|
||||
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/model/criteria"
|
||||
"github.com/navidrome/navidrome/model/request"
|
||||
"github.com/navidrome/navidrome/server/events"
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
|
|
@ -46,6 +47,26 @@ func (m *mockPluginLoader) LoadScrobbler(name string) (Scrobbler, bool) {
|
|||
return s, ok
|
||||
}
|
||||
|
||||
// flipOnPlayRepo reports one filter verdict before the play is counted and another
|
||||
// after, reproducing a filter that reads annotations incPlay mutates.
|
||||
type flipOnPlayRepo struct {
|
||||
model.MediaFileRepository
|
||||
before, after bool
|
||||
played atomic.Bool
|
||||
}
|
||||
|
||||
func (r *flipOnPlayRepo) IncPlayCount(id string, ts time.Time) error {
|
||||
r.played.Store(true)
|
||||
return r.MediaFileRepository.IncPlayCount(id, ts)
|
||||
}
|
||||
|
||||
func (r *flipOnPlayRepo) MatchesCriteria(string, criteria.Criteria) (bool, error) {
|
||||
if r.played.Load() {
|
||||
return r.after, nil
|
||||
}
|
||||
return r.before, nil
|
||||
}
|
||||
|
||||
// slowMediaFileRepo widens the window between a report's session check and its
|
||||
// write, making check-then-write races reproducible.
|
||||
type slowMediaFileRepo struct {
|
||||
|
|
@ -320,6 +341,185 @@ var _ = Describe("PlayTracker", func() {
|
|||
})
|
||||
})
|
||||
|
||||
Describe("Scrobble filter", func() {
|
||||
var repo *tests.MockMediaFileRepo
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(ctx, model.User{ID: "u-1", UserName: "user-1",
|
||||
ScrobbleFilter: `{"all":[{"contains":{"title":"Track"}}]}`})
|
||||
repo = ds.MediaFile(ctx).(*tests.MockMediaFileRepo)
|
||||
})
|
||||
|
||||
It("does not send a matching track to the agent", func() {
|
||||
repo.MatchesCriteriaValue = true
|
||||
|
||||
err := tracker.Submit(ctx, []Submission{{TrackID: "123", Timestamp: time.Now()}})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("still increments play counts for a filtered track", func() {
|
||||
repo.MatchesCriteriaValue = true
|
||||
|
||||
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)))
|
||||
})
|
||||
|
||||
It("sends a non-matching track to the agent", func() {
|
||||
repo.MatchesCriteriaValue = false
|
||||
|
||||
err := tracker.Submit(ctx, []Submission{{TrackID: "123", Timestamp: time.Now()}})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("fails open when evaluation errors", func() {
|
||||
repo.MatchesCriteriaErr = errors.New("boom")
|
||||
|
||||
err := tracker.Submit(ctx, []Submission{{TrackID: "123", Timestamp: time.Now()}})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("fails open when the stored filter is not valid JSON", func() {
|
||||
ctx = request.WithUser(ctx, model.User{ID: "u-1", UserName: "user-1", ScrobbleFilter: `{broken`})
|
||||
repo.MatchesCriteriaValue = true
|
||||
|
||||
err := tracker.Submit(ctx, []Submission{{TrackID: "123", Timestamp: time.Now()}})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("does not send now-playing for a filtered track", func() {
|
||||
repo.MatchesCriteriaValue = true
|
||||
|
||||
err := tracker.ReportPlayback(ctx, ReportPlaybackParams{
|
||||
MediaId: "123", State: StateStarting, ClientId: "player-1", ClientName: "player"})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Consistently(func() bool { return fake.GetNowPlayingCalled() }).Should(BeFalse())
|
||||
})
|
||||
|
||||
It("does not send playback reports for a filtered track", func() {
|
||||
repo.MatchesCriteriaValue = true
|
||||
|
||||
err := tracker.ReportPlayback(ctx, ReportPlaybackParams{
|
||||
MediaId: "123", State: StateStarting, ClientId: "player-1", ClientName: "player"})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Consistently(func() bool { return fake.PlaybackReportCalled.Load() }).Should(BeFalse())
|
||||
})
|
||||
|
||||
It("sends playback reports for a non-matching track", func() {
|
||||
repo.MatchesCriteriaValue = false
|
||||
|
||||
err := tracker.ReportPlayback(ctx, ReportPlaybackParams{
|
||||
MediaId: "123", State: StateStarting, ClientId: "player-1", ClientName: "player"})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Eventually(func() bool { return fake.PlaybackReportCalled.Load() }).Should(BeTrue())
|
||||
})
|
||||
|
||||
It("evaluates the filter even when no scrobbler is active yet", func() {
|
||||
// The verdict is stored on the session and dispatched at expiry, by which
|
||||
// time a plugin scrobbler may have been enabled.
|
||||
tracker.builtinScrobblers = map[string]Scrobbler{}
|
||||
repo.MatchesCriteriaValue = true
|
||||
|
||||
err := tracker.ReportPlayback(ctx, ReportPlaybackParams{
|
||||
MediaId: "123", State: StatePlaying, ClientId: "player-12", ClientName: "player"})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
stored, getErr := tracker.playMap.Get("player-12")
|
||||
Expect(getErr).ToNot(HaveOccurred())
|
||||
Expect(stored.filtered).To(BeTrue())
|
||||
})
|
||||
|
||||
Context("when incPlay itself flips the filter", func() {
|
||||
// A filter on playCount or lastPlayed changes verdict the moment incPlay
|
||||
// commits, so the verdict has to be taken before it, not at dispatch time.
|
||||
var flip *flipOnPlayRepo
|
||||
|
||||
install := func(before, after bool) {
|
||||
flip = &flipOnPlayRepo{MediaFileRepository: ds.MediaFile(ctx), before: before, after: after}
|
||||
ds.(*tests.MockDataStore).MockedMediaFile = flip
|
||||
}
|
||||
|
||||
It("does not scrobble a track the filter matched before the play was counted", func() {
|
||||
install(true, false)
|
||||
|
||||
err := tracker.ReportPlayback(ctx, ReportPlaybackParams{
|
||||
MediaId: "123", State: StateStopped, PositionMs: 120_000, ClientId: "player-1", ClientName: "player"})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(flip.played.Load()).To(BeTrue(), "incPlay must still have run")
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeFalse())
|
||||
})
|
||||
|
||||
It("still sends the stopped report when the filter only starts matching after the play", func() {
|
||||
install(false, true)
|
||||
|
||||
err := tracker.ReportPlayback(ctx, ReportPlaybackParams{
|
||||
MediaId: "123", State: StateStopped, PositionMs: 120_000, ClientId: "player-1", ClientName: "player"})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(flip.played.Load()).To(BeTrue(), "incPlay must still have run")
|
||||
Eventually(func() bool { return fake.PlaybackReportCalled.Load() }).Should(BeTrue())
|
||||
})
|
||||
|
||||
It("does not report an expired session for a filtered track", func() {
|
||||
// The expiry callback runs with a stub user, so it cannot evaluate the
|
||||
// filter itself and must reuse the verdict stored on the session.
|
||||
info := PlaybackSession{
|
||||
MediaFile: track, Start: time.Now(), UserId: "u-1", Username: "user-1",
|
||||
PlayerId: "player-9", PlayerName: "test-player", State: StatePlaying, filtered: true,
|
||||
}
|
||||
_ = tracker.playMap.AddWithTTL("player-9", info, 10*time.Millisecond)
|
||||
|
||||
Consistently(func() bool { return fake.PlaybackReportCalled.Load() }).Should(BeFalse())
|
||||
})
|
||||
|
||||
It("still reports an expired session for a track that is not filtered", func() {
|
||||
info := PlaybackSession{
|
||||
MediaFile: track, Start: time.Now(), UserId: "u-1", Username: "user-1",
|
||||
PlayerId: "player-10", PlayerName: "test-player", State: StatePlaying, filtered: false,
|
||||
}
|
||||
_ = tracker.playMap.AddWithTTL("player-10", info, 10*time.Millisecond)
|
||||
|
||||
Eventually(func() bool { return fake.PlaybackReportCalled.Load() }).Should(BeTrue())
|
||||
})
|
||||
|
||||
It("stores the verdict on the session so expiry can reuse it", func() {
|
||||
repo.MatchesCriteriaValue = true
|
||||
|
||||
err := tracker.ReportPlayback(ctx, ReportPlaybackParams{
|
||||
MediaId: "123", State: StatePlaying, ClientId: "player-11", ClientName: "player"})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
stored, getErr := tracker.playMap.Get("player-11")
|
||||
Expect(getErr).ToNot(HaveOccurred())
|
||||
Expect(stored.filtered).To(BeTrue())
|
||||
})
|
||||
|
||||
It("does not scrobble a Submit whose filter matched before the play was counted", func() {
|
||||
install(true, false)
|
||||
|
||||
err := tracker.Submit(ctx, []Submission{{TrackID: "123", Timestamp: time.Now()}})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(flip.played.Load()).To(BeTrue(), "incPlay must still have run")
|
||||
Expect(fake.ScrobbleCalled.Load()).To(BeFalse())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ReportPlayback", func() {
|
||||
const defaultClientId = "client-1"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@ import (
|
|||
"github.com/navidrome/navidrome/log"
|
||||
)
|
||||
|
||||
func (p *playTracker) enqueuePlaybackReport(ctx context.Context, info PlaybackSession) {
|
||||
func (p *playTracker) enqueuePlaybackReport(ctx context.Context, info PlaybackSession, filtered bool) {
|
||||
p.prMu.Lock()
|
||||
defer p.prMu.Unlock()
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
p.prQueue = append(p.prQueue, playbackReportEntry{
|
||||
ctx: ctx,
|
||||
info: info,
|
||||
ctx: ctx,
|
||||
info: info,
|
||||
filtered: filtered,
|
||||
})
|
||||
p.sendPlaybackReportSignal()
|
||||
}
|
||||
|
|
@ -44,12 +45,16 @@ func (p *playTracker) playbackReportWorker() {
|
|||
|
||||
allScrobblers := p.getActiveScrobblers()
|
||||
for _, entry := range entries {
|
||||
p.dispatchPlaybackReport(entry.ctx, entry.info, allScrobblers)
|
||||
p.dispatchPlaybackReport(entry.ctx, entry.info, allScrobblers, entry.filtered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *playTracker) dispatchPlaybackReport(ctx context.Context, info PlaybackSession, allScrobblers map[string]Scrobbler) {
|
||||
func (p *playTracker) dispatchPlaybackReport(ctx context.Context, info PlaybackSession, allScrobblers map[string]Scrobbler, filtered bool) {
|
||||
if filtered {
|
||||
log.Debug(ctx, "Ignoring external PlaybackReport for filtered track", "track", info.MediaFile.Title, "state", info.State)
|
||||
return
|
||||
}
|
||||
for name, s := range allScrobblers {
|
||||
if !s.IsAuthorized(ctx, info.UserId) {
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue