BLeeEZ / amperfy

Amperfy is an iOS app to play songs from an Ampache or Subsonic server
GNU General Public License v3.0
405 stars 35 forks source link

Scrobbling randomly doesn’t work/scrobbling logic doesn’t take into account if server received it #226

Open el-tiuri opened 4 months ago

el-tiuri commented 4 months ago

Reporting playback to my Subsonic (Navidrome) server randomly doesn’t work; oftentimes the songs at the beginning of a queue or album won’t scrobble, then most of those after will.

I feel like adding a check to see if the server has received the message and resending it if necessary would solve this. I tried diving into the code a while ago to fix scrobling logic (see here: https://github.com/BLeeEZ/amperfy/issues/106#issuecomment-1633119213), but I didn’t end up finding the time to brush up on my skills to resolve this.

I do think that a fix for this would also solve the previous issue;

BLeeEZ commented 3 months ago

Scribble cache is already implemented. When server is not reachable the scrobble gets saved. All cached scrobbles get uploaded when the server is reachable. I reworked the scrobble behaviour in e4e864c8d69f764d37c6ec7eafa883934cbc214d and f427673b6f979badf6ed53074bac3bd3f1ecc67a.

el-tiuri commented 3 months ago

This is fantastic! Are the scrobbles timestamped for the moment they were originally played as described here? That’s the last thing stopping me from using Amperfy full time. I’d test it out myself, but the update isn’t available yet on TestFlight.

Either way, thanks for the improvements!

BLeeEZ commented 3 months ago

Scrobble cache is already available in v1.2.0. Only the NowPlaying feature is new and can be tested in upcoming v.1.2.1.

BLeeEZ commented 1 month ago

This feature can be tested in the newest beta v1.2.1 (2): https://github.com/BLeeEZ/amperfy/issues/25

BLeeEZ commented 1 month ago

Please provide your comments in the feature threads to keep the beta thread as clean as possible.

I just discovered that the first track in a queue never seems to scrobble. Everything beyond that seems to work fine (as does replaying the first track), but after trying multiple times the first song played never seems to go through.

Another scrobbling related one: all songs played when offline still get timestamped at the time you go online, rather than when they were played. I thought this was fixed, but apparently not? Or is this the expected behaviour?

It’s a bit of a shame, because if you listen to a couple of albums when offline and then go online they’ll all be reported as being played on the exact same time.

el-tiuri commented 1 month ago

Apologies, I posted it there because you linked it here! My bad!

BLeeEZ commented 1 month ago

I tested Ampache and Subsonic regarding your description. I can't reproduce this behaviour. All songs are scribbled, the first one too. Cached scrobbles are transmitted with the timestamp when the song was played.

el-tiuri commented 1 month ago

Turns out my Navidrome server was set to the wrong time zone, leading scrobbles to be timestamped after the time the server was set to - which caused Navidrome to scrobble them at the time they were sent. For some reason this never was an issue for the other app I use (Substreamer), and now that I’ve corrected it on my end Amperfy seems to work as expected as well! I’ll continue testing to see if I encounter anything else.

Thanks for your help, and apologies for my mistake.

el-tiuri commented 1 month ago

For some reason, I’m still experiencing this when songs were played in offline mode, while it does work when offline mode is disabled but there’s no connection to the server.

el-tiuri commented 1 week ago

I’m still experiencing issues with songs being scrobbled when going online, rather than when they were played. I double checked and my Subsonic server (Navidrome) was set to the right time.

I quickly checked out the relevant code, and it seems to me the timestamps are not saved in the unix epoch format? As far as I can tell switching over to that should fix this entirely, as it’s the native time format for both Subsonic scrobbles and Last.fm scrobbles.

BLeeEZ commented 1 week ago

I am saving the scrobble date and time here: https://github.com/BLeeEZ/amperfy/blob/master/AmperfyKit/Player/ScrobbleSyncer.swift#L144 The date will be send to server as timeIntervalSince1970 Integer as described in the specification: https://github.com/BLeeEZ/amperfy/blob/master/AmperfyKit/Api/Subsonic/SubsonicServerApi.swift#L698 I can't see an error here.

el-tiuri commented 1 week ago

Ah, I thought Date() returned it in a different format, it’s been a long while since I coded altogether (clearly lol). I’d have to play around with it myself, because I can’t figure out for the life of me why this goes wrong with some regularity.

I’ll try to find out more, if only to make sure someone with the same problem can find a solution here.

BLeeEZ commented 1 week ago

For some reason, I’m still experiencing this when songs were played in offline mode, while it does work when offline mode is disabled but there’s no connection to the server.

With 055a1aa5fcd33284d1e8c33fe64abfad25e65280 I fixed an error with failed scrobble syncs. If a scrobble request send to the server fails, the scrobble gets cached too and will be synced when the server is available again.