jellyfin-plugin-lastfm icon indicating copy to clipboard operation
jellyfin-plugin-lastfm copied to clipboard

Scrobbles should happen earlier, not at the end of the song being played.

Open csaavedra opened this issue 1 year ago • 0 comments

There are several bugs with third party apps (like finamp) that cause this plugin to not scrobble tracks, and while checking those I realized one thing that this plugin does not do correctly, and fixing that could incidentally fix those problems. If I understand correctly, the plugin is using the stop event to decide whether to send a scrobble. This is not correct, as scrobbles should happen earlier, not when the track ends/stops playing.

The last.fm specification ( https://www.last.fm/api/scrobbling#when-is-a-scrobble-a-scrobble ) states that a track has to be scrobbled when:

  • The track must be longer than 30 seconds.
  • And the track has been played for at least half its duration, or for 4 minutes (whichever occurs earlier.)

The plugin should schedule a scrobble using a timeout when the track starts, using for the timeout MIN(track.length/2, 4*60). If the track is stopped at any point, cancel the timeout call if it has not happened yet (as this means that it has not played long enough to be submitted).

Doing it like this will prevent any problems with apps reporting stopping time wrongly, as it will be done independently of it.

(fwiw, I implemented a last.fm scrobbler over ten years ago, that's how I did it back then)

csaavedra avatar Jun 07 '23 15:06 csaavedra