jmshrv / finamp

A Jellyfin music client for mobile
Mozilla Public License 2.0
1.88k stars 124 forks source link

Play Count scrobbling to JF when online again? #194

Open GlassedSilver opened 2 years ago

GlassedSilver commented 2 years ago

Heya!

I really appreciate that this app has an offline mode, but beyond JF not really providing a very good music experience yet (it's way too simplistic in many ways) I do believe that a good Android companion like this could even things out and make JF at least a worthwhile backend. :D

It would be cool to see play counts getting scrobbled to the server when you're connected to the server again. If I play music on the road, or elsewhere I would love for those plays to be ingressed into my library, because eventually we might see JF get smart playlist support and then having all my plays properly logged would make for a good dataset to create rules upon.

I certainly don't want to depend on third-party services for that. It's cool to be able to scrobble to last.fm and similar services with Android reliably these days, but it doesn't replace having proper personal statistics in my opinion.

Sadly pretty much every personal music solution that is libre puts play counts and their syncing on the back burner.

Thoughts?

jmshrv commented 2 years ago

I swear there was another issue for syncing the played songs when back online, but I can't find it. I'll look into implementing this for 0.7 :)

Chaphasilor commented 8 months ago

We could use the playback history along with this API endpoint to mark an item as played. It also accepts a date-time for when the item was actually played.
The endpoint would need to be called for each song played, and the data wouldn't end up in Playback Reporting, only in Jellyfin's internal PlayCount. Not sure if that's worth it?

Fale commented 3 months ago

The url of the API documentation changed. From what I read on the API doc page, it seems to me that it is present at least in the latest Jellyfin version. Is this correct?

Chaphasilor commented 3 months ago

Functionality-wise nothing has changee, so the play count in Jellyfin might be correct, but it won't be part of thr playback history or activity.

Theoretically you could even do this with an external script for now, the offline playback data is already being tracked by Finamp if the server can't be reached (even across restarts).

Implementing a function to upload this to the server one-by-one also shouldn't be too hard, just a simple loop that calls the endpoint for each offline play.
Could be either fired manually through a button in the settings or on the playback history screen, or automatically whenever (successfully)/existing offline mode.

It's important for Finamp to keep track of what still needs to be submitted to prevent submitting a play twice.

GlassedSilver commented 3 months ago

This would probably best be handled if JF server keeps track of the last known play time and amount of clients and then only updates the difference.

Chaphasilor commented 3 months ago

@GlassedSilver I'm not really sure what you mean. Could you please elaborate?

GlassedSilver commented 3 months ago

@GlassedSilver I'm not really sure what you mean. Could you please elaborate?

By amount of clients I meant play count per a given device.

Say your Finamp client syncs a new track, you play it 10 times, and before it had a play count of 9 on the server side. VERY simple play sync functions COULD possibly interpret this as ONE play (old=9, new=10).

A sensible approach is to store the last known sync amount per track per device and whenever you display the play count a SUM of all those is displayed in the UI. JF and Finamp would exchange play count values separately for client and "all-others" whereas all-others is never synced TO the server, just FROM the server to calculate client-side the amount of total plays. (e.g. for smart playlists and such, although I'd argue those should probably be long-term a JF native feature since I'd love to have dynamic smart playlists on ALL of my devices, but that's another can of worms)

There's more edge cases to catch, but making sure you keep all play counts separate means no single client can wipe or hamper the integrity of the total play count beyond its own weight in that SUM.

PS: I am aware that I am going beyond the scope of this repo with this concept, I'm just thinking aloud. Maybe if some client(s) dev(s) are/is open to the idea of "modular" play counts it could make for someone at JF considering this. PPS: If that's already how play counts work JF-side I said nothing lol.

Chaphasilor commented 3 months ago

Haha yes we can only increase the play count but not set it to a specific value. And Finamp already stores the last-known play count for offline use, but doesn't add any offline plays yet (since those are discarded anyway at the moment).