jeffvli / sonixd

A full-featured Subsonic/Jellyfin compatible desktop music player
GNU General Public License v3.0
1.85k stars 74 forks source link

Jellyfin Scrobbling: Listening to a song records it 2x+ times #126

Closed BrennanAyers closed 2 years ago

BrennanAyers commented 2 years ago

Describe the bug With Scrobbling turned on, and listening to songs from a Jellyfin server, it appears to count each listen multiple times.

To Reproduce Steps to reproduce the behavior:

x. Turn on scrobbling

  1. Go to any song
  2. Click on said song to play it
  3. Wait long enough for it to count as a "play" (I swear I saw this logic somewhere, but can't remember)
  4. Navigate away and click back into the album to refresh the playcount (observe the n+1 from what it was before)
  5. Wait until the song gets to somewhere around 80%-90% finished
  6. Navigate away and click back into the album to refresh the playcount again (observe the n+2 from what it was before you played the song in the first place)
  7. If the song happens to be a single (only track on an album), when it's done playing it might replay and count as a 3rd play

Expected behavior After hitting the threshold of "played", the count would go up by 1

Screenshots (I've been meaning to get a dev version up and running so I could provide a bit more context, but) Here's the track I was playing, and about as I could get to when it flipped over to 2 plays image

Desktop (please complete the following information):

Additional context Single tracks on albums replaying automatically is a separate issue that I should probably put elsewhere.

jeffvli commented 2 years ago

Thanks for opening this.

I noticed there were additional issues the lastfm scrobbling on Jellyfin but didn't realize the play count was being recorded multiple times as well. I'll take a look at the scrobbling again to see what Jellyfin determines as a finished track.

jeffvli commented 2 years ago

Seems like Jellyfin marks the song as "Played" (adds 1 to the play count) when sending the /Sessions/Playing request. On the default Jellyfin web UI this request is sent as soon as a song is started, which means that if you quickly skip through songs with the Next track button, every song that is skipped will immediately add a play count to it.

I'm thinking it would be better to have it only when the song is completed (90% listened or past 4 minutes) which is consistent with the lastfm scrobble. Thoughts?

BrennanAyers commented 2 years ago

Yeah, that's kind of what I was expecting, that once you listened to at least most of the song it would count. Plenty of times where you're just flipping through and don't want it to go up. If Last.fm does 90%, I agree to stick with that!

maltechx commented 2 years ago

I just wanted to mention that I encountered a few issues that somehow relate to this one:

Also the Last.fm plugin marks a song as played after 100%, when its played in the web player. (Maybe there is an option to change that)

jeffvli commented 2 years ago

@maltechx

After ~4 minutes of playing a song the playback in Jellyfin is marked as stopped.

This is due to the crossfade player implementation and how the scrobbling was implemented for Subsonic-API servers. For Subsonic, a scrobble request is sent when the player reaches the scrobble condition (check the docs for the conditions).

In the case of Jellyfin, I replaced it with the stop playback request which the jellyfin lastfm plugin uses to determine whether or not to send "song completed" message to lastfm.

Stopping a song does not stop the reported playback time in Jellyfin. (The time counts up)

It should stop properly when in gapless mode (crossfade duration = 0), but there's a bug when crossfade is enabled. It's fixed in #127 and should go out with the next release though.

Also the Last.fm plugin marks a song as played after 100%, when its played in the web player. (Maybe there is an option to change that)

The plugin is checking the stop playback request that I mentioned earlier and checking at what time position the track was stopped at to determine whether or not to send the request. The actual play counts that Jellyfin server records is separate from the lastfm scrobble though.

https://github.com/jesseward/jellyfin-plugin-lastfm/blob/c2db0ec38291b13053aa59d502a3e292b00d644b/Jellyfin.Plugin.Lastfm/ServerEntryPoint.cs#L22-L27