jesseward / jellyfin-plugin-lastfm

LastFM plugin for the Jellyfin media system. Fork of the Emby Last.FM plug-in
178 stars 11 forks source link

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

Open csaavedra opened 1 year ago

csaavedra commented 1 year ago

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 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)