From 1be3cf9889eb6c0c83def7ce8ef26bfc3429795a Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Thu, 21 Sep 2023 17:24:57 +0200 Subject: [PATCH] fix: track watch sessions but don't sync remote Always track the watch session if syncing during or after playback is enabled, but don't actually sync during the playback if syncing during playback is not enabled. This is to make sure the syncing after playback is not treated as an accidental event because it is below the initial skip event count if we don't track the events that would be fired during the playback. --- Shokofin/Sync/UserDataSyncManager.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Shokofin/Sync/UserDataSyncManager.cs b/Shokofin/Sync/UserDataSyncManager.cs index c96992a6..95bfa531 100644 --- a/Shokofin/Sync/UserDataSyncManager.cs +++ b/Shokofin/Sync/UserDataSyncManager.cs @@ -103,7 +103,7 @@ public bool ShouldSendEvent(bool isPauseOrResumeEvent = false) public void OnSessionStarted(object sender, SessionEventArgs e) { - if (TryGetUserConfiguration(e.SessionInfo.UserId, out var userConfig) && userConfig.SyncUserDataUnderPlayback) { + if (TryGetUserConfiguration(e.SessionInfo.UserId, out var userConfig) && (userConfig.SyncUserDataUnderPlayback || userConfig.SyncUserDataAfterPlayback)) { var sessionMetadata = new SessionMetadata(Logger) { ItemId = Guid.Empty, Session = e.SessionInfo, @@ -114,7 +114,7 @@ public void OnSessionStarted(object sender, SessionEventArgs e) ActiveSessions.TryAdd(e.SessionInfo.UserId, sessionMetadata); } foreach (var user in e.SessionInfo.AdditionalUsers) { - if (TryGetUserConfiguration(e.SessionInfo.UserId, out userConfig) && userConfig.SyncUserDataUnderPlayback) { + if (TryGetUserConfiguration(e.SessionInfo.UserId, out userConfig) && (userConfig.SyncUserDataUnderPlayback || userConfig.SyncUserDataAfterPlayback)) { var sessionMetadata = new SessionMetadata(Logger) { ItemId = Guid.Empty, Session = e.SessionInfo, @@ -177,7 +177,7 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e) sessionMetadata.SkipCount = userConfig.SyncUserDataInitialSkipEventCount; Logger.LogInformation("Playback has started. (File={FileId})", fileId); - if (sessionMetadata.ShouldSendEvent()) + if (sessionMetadata.ShouldSendEvent() && userConfig.SyncUserDataUnderPlayback) success = await APIClient.ScrobbleFile(fileId, episodeId, "play", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false); } else { @@ -190,7 +190,7 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e) sessionMetadata.SentPaused = true; Logger.LogInformation("Playback was paused. (File={FileId})", fileId); - if (sessionMetadata.ShouldSendEvent(true)) + if (sessionMetadata.ShouldSendEvent(true) && userConfig.SyncUserDataUnderPlayback ) success = await APIClient.ScrobbleFile(fileId, episodeId, "pause", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false); } // The playback was resumed. @@ -200,7 +200,7 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e) sessionMetadata.SentPaused = false; Logger.LogInformation("Playback was resumed. (File={FileId})", fileId); - if (sessionMetadata.ShouldSendEvent(true)) + if (sessionMetadata.ShouldSendEvent(true) && userConfig.SyncUserDataUnderPlayback ) success = await APIClient.ScrobbleFile(fileId, episodeId, "resume", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false); } // Return early if we're not scrobbling. @@ -216,10 +216,11 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e) ++sessionMetadata.ScrobbleTicks < userConfig.SyncUserDataUnderPlaybackAtEveryXTicks) return; - Logger.LogInformation("Scrobbled during playback. (File={FileId})", fileId); + Logger.LogInformation("Playback is running. (File={FileId})", fileId); sessionMetadata.ScrobbleTicks = 0; - if (sessionMetadata.ShouldSendEvent()) + if (sessionMetadata.ShouldSendEvent() && userConfig.SyncUserDataUnderPlayback ) { success = await APIClient.ScrobbleFile(fileId, episodeId, "scrobble", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false); + } } } break;