Skip to content

feat: Add history scrobbling for the Plex source - #835

Draft
owendaprile wants to merge 5 commits into
FoxxMD:masterfrom
owendaprile:plexHistoryBacklog
Draft

owendaprile wants to merge 5 commits into
FoxxMD:masterfrom
owendaprile:plexHistoryBacklog

Conversation

@owendaprile

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Describe your changes

AI disclosure: The PR was mostly written by Claude Opus 5.5, and reviewed by Opus 5.5 and Fable 5.2. I manually reviewed it.

See #409 for background.

This PR adds backlog scrobbling for the Plex source (similar to Spotify). This mainly affects Plexamp downloads (or cached songs) played offline, which get uploaded when coming back online. It also catches plays made while MS or the Plex server were offline. I tested Plex Desktop (macOS) and it does not upload or scrobble plays made offline when coming back online.

The feature was developed and tested based on the following data from my Plex library and usage:

  1. ~165k plays from 2021 to now stored on my Plex server. These showed a lot of inconsistent behavior that the feature needs to work around. The tests are based on these scenarios.
  2. Stored server logs that show Plex and Plexamp’s behavior.
  3. A live test of how Plex handles local user plays in history (which are stored as the server owner, unlike live-tracked plays).

I also found during testing that the auth token needs to be the server owner’s for live-tracking to work at all. This likely applies to Plex Home accounts as well, but I didn’t test that. 69e3e64 adds a note about this to the docs.

I’m going to continue testing this PR against my Plex server and multiple clients, with different offline scenarios to make sure it works properly without scrobbling duplicates.

Known limits:

  1. It won’t scrobble plays made more than about 7 days before the check.
  2. Plays that come from history ignore scrobble thresholds (like Spotify).
  3. Duplicate detection is not perfect, so in rare cases a song may be scrobbled twice (e.g. a track longer than about 8 minutes that's playing when MS starts) or multiple plays may be merged into one (e.g. a track which is restarted soon after it's halfway done).

Open design questions:

  1. Should this be enabled by default on update? I chose to default to on, similar to Spotify, but Plex history is messier.
  2. A large portion of the feature is matching logic to determine if a play in Plex’s history is the same as one found by MS. The current duplicate matching didn’t cover all the cases found in my history. I could make this generic if it would be useful for other sources.
  3. a737673 changes the database’s retention so that each component only removes or compacts its own plays, instead of all of them. This feature relies on the Plex source’s own retention deciding when to delete its plays, since it uses those plays to tell whether a history entry was already scrobbled. One consequence of this is that removed or renamed components leave orphan records in the database which don’t get cleaned up by anything. I could add a sweep to this change which cleans those up automatically.

Retention cleanup didn't pass the component's ID to the play repository,
so its query matched the plays of every source and client. A component
with a shorter deleteAfter or compactAfter then deleted or compacted
other components' plays, ignoring their own retention settings.
The ENV docs used devicesBlock's description for PLEX_DEVICES_ALLOW and
devicesAllow's for PLEX_DEVICES_BLOCK, so each variable was documented
as doing the opposite of what it does. The log messages for plays
dropped by the user and device filters also started with a stray quote.
The Plex source polls the server's playback sessions, and Plex doesn't
let a shared account read them. A shared account's own token gets 401
from the server, and the server token plex.tv issues it gets 403 for
/status/sessions, so the source only works with the owner's token. The
docs only said to find a Plex token.
Plexamp plays made offline never appear in Plex's sessions, so
multi-scrobbler can't scrobble them. Plexamp uploads them to the
server's play history when it reconnects, so the Plex source now checks
that history at startup and every 15 minutes for plays that real-time
tracking missed.

History entries don't line up with tracked plays. Plex records an online
play about halfway through and an offline play when it ends, and it can
record one play several times or under another copy of the track. The
shared duplicate check would treat these as separate plays, so the
source matches each entry against its own saved plays by user, title,
and time. Nothing else records which entries were handled, so the source
only scrobbles entries recent enough that retention still keeps those
plays.

Closes FoxxMD#409.
@netlify

netlify Bot commented Dec 5, 2026

Copy link
Copy Markdown

👷 Deploy request for multi-scrobbler pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 8a3861a

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant