fix(trackers): preserve Plex library context

This commit is contained in:
edde746
2026-05-12 22:46:38 +02:00
parent 3a01fa25a7
commit de129fbb0a
30 changed files with 845 additions and 119 deletions
+2 -2
View File
@@ -25,8 +25,8 @@ abstract class Tracker {
/// Whether an item in the given library should be scrobbled. Applies the
/// per-tracker whitelist/blacklist — callers pass the Plex library
/// `serverId:sectionId` globalKey (null when unknown, in which case the
/// filter is bypassed so we err on the side of syncing).
/// `serverId:sectionId` globalKey. Null is allowed only when no filter is
/// configured for this tracker.
bool shouldScrobbleForLibrary(String? libraryGlobalKey);
Future<void> markWatched(TrackerContext ctx);
+10 -2
View File
@@ -27,6 +27,7 @@ class TrackerCoordinator {
/// Resolver persists across episode swaps so back-to-back episodes of the
/// same show reuse the cached IDs. Cleared only on profile switch.
TrackerIdResolver? _resolver;
String? _activeLibraryGlobalKey;
TrackerContext? _ctx;
Duration _duration = Duration.zero;
@@ -41,8 +42,13 @@ class TrackerCoordinator {
if (isLive) return;
final mediaType = metadata.kind;
if (mediaType != MediaKind.movie && mediaType != MediaKind.episode) return;
if (!_trackers.any((t) => t.canScrobble)) return;
final libraryGlobalKey = metadata.libraryGlobalKey;
if (!_trackers.any((t) => t.canScrobble && t.shouldScrobbleForLibrary(libraryGlobalKey))) {
_reset();
return;
}
_activeLibraryGlobalKey = libraryGlobalKey;
_resolver ??= TrackerIdResolver(client, needsFribb: _anyTrackerNeedsFribb);
final ctx = await _buildContext(metadata);
if (ctx == null) {
@@ -54,7 +60,8 @@ class TrackerCoordinator {
_ctx = ctx;
}
bool _anyTrackerNeedsFribb() => _trackers.any((t) => t.canScrobble && t.needsFribb);
bool _anyTrackerNeedsFribb() =>
_trackers.any((t) => t.canScrobble && t.needsFribb && t.shouldScrobbleForLibrary(_activeLibraryGlobalKey));
Future<void> stopPlayback() async {
final ctx = _ctx;
@@ -98,6 +105,7 @@ class TrackerCoordinator {
void _reset() {
_ctx = null;
_activeLibraryGlobalKey = null;
_duration = Duration.zero;
_lastPosition = Duration.zero;
_thresholdCrossed = false;