diff --git a/core/agents/lastfm/agent.go b/core/agents/lastfm/agent.go index 783f0e686..fdc0a97b8 100644 --- a/core/agents/lastfm/agent.go +++ b/core/agents/lastfm/agent.go @@ -186,6 +186,10 @@ func (l *lastfmAgent) Scrobble(ctx context.Context, userId string, scrobbles []s // TODO Implement batch scrobbling for _, s := range scrobbles { + if s.Duration <= 30 { + log.Debug(ctx, "Skipping Last.fm scrobble for short song", "track", s.Title, "duration", s.Duration) + continue + } err = l.client.Scrobble(ctx, sk, ScrobbleInfo{ artist: s.Artist, track: s.Title, diff --git a/core/agents/lastfm/agent_test.go b/core/agents/lastfm/agent_test.go index 3b0d3b62f..c41548260 100644 --- a/core/agents/lastfm/agent_test.go +++ b/core/agents/lastfm/agent_test.go @@ -293,6 +293,17 @@ var _ = Describe("lastfmAgent", func() { Expect(sentParams.Get("mbid")).To(Equal(track.MbzTrackID)) Expect(sentParams.Get("timestamp")).To(Equal(strconv.FormatInt(ts.Unix(), 10))) }) + + It("skips songs with less than 31 seconds", func() { + track.Duration = 29 + scrobbles := []scrobbler.Scrobble{{MediaFile: *track, TimeStamp: time.Now()}} + httpClient.Res = http.Response{Body: ioutil.NopCloser(bytes.NewBufferString("{}")), StatusCode: 200} + + err := agent.Scrobble(ctx, "user-1", scrobbles) + + Expect(err).ToNot(HaveOccurred()) + Expect(httpClient.SavedRequest).To(BeNil()) + }) }) })