Skip songs with less than 31 seconds, as per Last.fm specification

See https://www.last.fm/api/scrobbling#when-is-a-scrobble-a-scrobble
This commit is contained in:
Deluan 2021-06-23 21:08:01 -04:00
parent 5040f6fd97
commit 0cbb0acad3
2 changed files with 15 additions and 0 deletions

View File

@ -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,

View File

@ -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())
})
})
})