Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(source): Stale/orphan scrobble and timestamp improvments #256

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

FoxxMD
Copy link
Owner

@FoxxMD FoxxMD commented Jan 21, 2025

Checklist before requesting a review

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Describe your changes

  • Add user configurable stale/orphaned intervals
  • Clear listening progress after scrobbling stale Play to prevent excess scrobbling if Play is resumed before player is orphaned
  • Improve logging timestamps for activity and stale/orphaned statements

@FoxxMD FoxxMD added enhancement New feature or request safe to test trusted to build image labels Jan 21, 2025
…obble on resume

Clearing pre-stale listening range prevents any future resume (player becomes non-stale) from using old listening range to scrobble. Represents a physical "break" between listening sessions for the same song
Makes logs easier to read when looking for stale source/player
@FoxxMD FoxxMD force-pushed the configurablePlayerStale branch from 973efde to 6c30135 Compare January 21, 2025 18:29
@FoxxMD FoxxMD added the bug Something isn't working label Jan 21, 2025
Copy link
Contributor

📦 A new release has been made for this pull request.

To play around with this PR, pull an image:

  • foxxmd/multi-scrobbler:pr-256

Images are available for x86_64 and ARM64.

Latest commit: 6c30135

@FoxxMD
Copy link
Owner Author

FoxxMD commented Jan 21, 2025

@Fratt please try out this PR.

You can specify stale after X seconds like this in spotify.json

[
  {
    "name": "MySpotify",
    "data": {
      // ...
      "staleAfter": 60, // seconds after which Player becomes stale from no activity
      "orphanedAfter": 360 // seconds after which Player becomes orphaned from no activity (removed after 2x interval)
    }
  }
]

Though I would suggest trying it without these, first. I made a change that should prevent "resumed" plays from scrobbling again if the previous "paused" (before stale) play was scrobbled. There was a bug that let the "paused" listen time count towards the "resumed" (post-stale) listen time that has now been fixed.

Also, can you remind me what platform you are using spotify on when you see it goes stale after pausing? From my own experience -- if on web/desktop and the application remains open the Player never goes stale even if paused for a long time. I haven't tested what this is like on mobile but I imagine that might be where you see it becoming stale.

@Fratt
Copy link
Contributor

Fratt commented Jan 22, 2025

Thanks a lot! I'll try pr-256 right away. (without adding anything in spotify.json, at first)

I know for a fact that it happened on mobile, indeed. But I cannot say for sure that it never happend on Desktop. (I listen 90% of the time on my phone, 10% of the time on my computer)

@Fratt
Copy link
Contributor

Fratt commented Jan 23, 2025

I've been trying it for 2 days now, without any changes to my spotify.json : I'm still experiencing occasional double scrobbles when taking breaks while listening to a song. It's difficult for me to say if this happens "less often" though.

I will now try with staleAfter and orphanedAfter in my spotify.json, but I have two questions for you first:

  • What are the default values?
  • I'm not sure I really understand the difference between the two, so can you tell me which values I should give them if I want to be able to take breaks of up to 8 hours while listening to a song, without having a "double scrobble" ?

Thanks a lot!

@FoxxMD
Copy link
Owner Author

FoxxMD commented Jan 23, 2025

The default values are

  • stale = polling interval (10s) * 3
  • orphaned = polling interval (10s) * 5

The "no activity" mentioned in my previous comment means that the Source (spotify) is no longer returning any data for the unique player ID it was monitoring. This is not the same as the Player being in the same state (paused) for a long time -- it's literally "the data returned from the spotify API for getPlayers() has not included an object for the player with ID 123 for X seconds, consecutively"

Stale and Orphaned are two different levels of "what should MS do when player has no activity for X seconds"

  • When player becomes Stale => Try to scrobble, if there was a track being played
    • If Player becomes active again (new data from API) then MS continues from where it left off in monitoring
      • If it had scrobbled when it became stale then when it tries to scrobble next it (should) only use listening time after becoming active [1]
      • If it did not scrobble when it became stale then it will use all listening time still stored in MS (pre-stale and now active)
  • When player becomes Orphaned => Remove the Player and all data about it from MS
    • If the Source returns the same Player ID with new data, later, then MS treats it as a new Player/track. It doesn't know anything about the old Player since it was removed. [2]

which values I should give them if I want to be able to take breaks of up to 8 hours while listening to a song

You'd probably only want to set orphanedAfter so that the stale data sticks around.

"orphanedAfter": 28800

would be 8 hours in seconds.


But I would also like to address the double scrobble if this really is a bug, or find out if your idea of how scrobbling should work is just different from MS.

From the above explanation, [1] should be working but I don't think it fits your scenario since likely your Player is being orphaned/removed. For [2] you should only see a "double scrobble" if the track you resumed still had enough time left to meet the scrobble threshold of 4 minutes. For the tracks you've seen double scrobbled, is this the case? Put plainly:

  • Listening to Song A (track is longer than 8 minutes)
  • Listen for 4+ minutes, then pause or close spotify on mobile
  • MS stales => scrobbles (4 minutes of listen time)
  • MS orphans => removes player
  • Re-open spotify some hours later, resume Song A
  • Listen for another 4+ minutes
  • Track ends or new track is played or close spotify => stales
  • MS scrobbles (4 minutes of listen time)

@Fratt
Copy link
Contributor

Fratt commented Jan 24, 2025

I will take the time to answer your points properly soon.

In the meantime, I added last evening orphanedAfter into my config file :

[
  {
    "name": "Spotify",
    "enable": true,
    "clients": [],
    "data": {
      "clientId": "xxx",
      "clientSecret": "xxx",
      "redirectUri": "xxx",
      "interval": 60,
      "orphanedAfter": 28800
    },
    "options": {
      "logToFile": "debug"
    }
  }
]

But it seems to cause problems : It does double scrobbling even when I take a break of only 5 minutes while listening to a song, which is way worst than before :-(

image

Any idea why?

I'll rollback the config for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request safe to test trusted to build image
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants