jellyfin / mopidy-jellyfin

Jellyfin Extension for Mopidy
https://jellyfin.org
Apache License 2.0
93 stars 16 forks source link

A "PlaybackStopEvent" should be fired on track changes #100

Open ilya-zlobintsev opened 3 years ago

ilya-zlobintsev commented 3 years ago

This is needed for last.fm scrobbling to work properly.

Here is a detailed description of the last.fm plugin behaviour: https://github.com/jesseward/jellyfin-plugin-lastfm/issues/27#issuecomment-744031810

ilya-zlobintsev commented 3 years ago

I'm sorry, but this doesn't seem to work for me. I'm using the latest version and scrobbling still doesn't work. Activity on the server dashboard when playing with mopidy looks like this: image When playing from the web (not sure why the entry is doubled): image

I'm running mopidy 3.1.1 if that makes any difference.

mcarlton00 commented 3 years ago

Looks like I need to adjust the stop playback command I'm sending. The server is reporting

Jellyfin.Server.Implementations.Events.Consumers.Session.PlaybackStopLogger: PlaybackStopped reported with null media info.

It must need to know the exact media item that it stopped. Which seems dumb, since obviously a client can only be playing one thing at a time. But whatever, shouldn't be a hard fix.

ilya-zlobintsev commented 3 years ago

@mcarlton00 I've tried the PR and it does properly show up in activity now, but scrobbling still doesn't work. Looking at the server logs it doesn't seem to report the playback duration properly: Playback stopped reported by app "Mopidy" "1.0.3" playing "Mirror Mirror". Stopped at "0" ms

mcarlton00 commented 3 years ago

Hmm, that's going to complicate this a fair bit. Looking at the web client, it actually sends 2 stop commands. The first one has a PositionTicks value, the second one has it set to 0.

The reason this is an issue here is because we have to hook into Mopidy's playback system, which means we have to workaround whatever they're doing. In this case, when we get the notification that a track has changed, mopidy provides a data payload of {'old_state': 'playing, 'new_state': 'playing'}. You may notice that this is a little lacking on vital information that we need for reporting. Pulling the item id is doable, if kinda messy. Playback ticks is going to be a bit of a trick and I'm not sure how to get that yet. It can be pulled during playback of a given item, but by the time we receive the track changed notification, we would be pulling the playback position of the next item, not the one that we're looking for. So right now I'm not sure how to pull that off.

ilya-zlobintsev commented 3 years ago

If anyone comes across this, you can use mopidy-scrobbler as a workaround.