From 252e30cde09ac2e828483a6ec614c33fd68b1ffc Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Fri, 2 Aug 2024 13:41:03 +0000 Subject: [PATCH] AutoSkip: allow to adjust the intro/credit playback duration (#238) Co-authored-by: rlauu <46294892+rlauu@users.noreply.github.com> Co-authored-by: rlauuzo <46294892+rlauuzo@users.noreply.github.com> Co-authored-by: CasuallyFilthy --- .../AutoSkip.cs | 11 +++--- .../AutoSkipCredits.cs | 13 ++++--- .../Configuration/PluginConfiguration.cs | 12 ++++++- .../Configuration/configPage.html | 36 +++++++++++++++++-- .../Controllers/SkipIntroController.cs | 4 +-- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs index 305549d..f69a5e3 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs @@ -149,15 +149,16 @@ public class AutoSkip : IServerEntryPoint } // Seek is unreliable if called at the very start of an episode. - var adjustedStart = Math.Max(5, intro.IntroStart); + var adjustedStart = Math.Max(5, intro.IntroStart + Plugin.Instance.Configuration.SecondsOfIntroStartToPlay); + var adjustedEnd = intro.IntroEnd - Plugin.Instance.Configuration.RemainingSecondsOfIntro; _logger.LogTrace( "Playback position is {Position}, intro runs from {Start} to {End}", position, adjustedStart, - intro.IntroEnd); + adjustedEnd); - if (position < adjustedStart || position > intro.IntroEnd) + if (position < adjustedStart || position > adjustedEnd) { continue; } @@ -180,8 +181,6 @@ public class AutoSkip : IServerEntryPoint _logger.LogDebug("Sending seek command to {Session}", deviceId); - var introEnd = (long)intro.IntroEnd - Plugin.Instance!.Configuration.SecondsOfIntroToPlay; - _sessionManager.SendPlaystateCommand( session.Id, session.Id, @@ -189,7 +188,7 @@ public class AutoSkip : IServerEntryPoint { Command = PlaystateCommand.Seek, ControllingUserId = session.UserId.ToString("N"), - SeekPositionTicks = introEnd * TimeSpan.TicksPerSecond, + SeekPositionTicks = (long)adjustedEnd * TimeSpan.TicksPerSecond, }, CancellationToken.None); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs index 6ac092b..1b09b55 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs @@ -142,16 +142,17 @@ public class AutoSkipCredits : IServerEntryPoint continue; } - // Seek is unreliable if called at the very start of an episode. - var adjustedStart = Math.Max(5, credit.IntroStart); + // Seek is unreliable if called at the very end of an episode. + var adjustedStart = credit.IntroStart + Plugin.Instance.Configuration.SecondsOfCreditsStartToPlay; + var adjustedEnd = credit.IntroEnd - Plugin.Instance.Configuration.RemainingSecondsOfIntro; _logger.LogTrace( "Playback position is {Position}, credits run from {Start} to {End}", position, adjustedStart, - credit.IntroEnd); + adjustedEnd); - if (position < adjustedStart || position > credit.IntroEnd) + if (position < adjustedStart || position > adjustedEnd) { continue; } @@ -174,8 +175,6 @@ public class AutoSkipCredits : IServerEntryPoint _logger.LogDebug("Sending seek command to {Session}", deviceId); - var creditEnd = (long)credit.IntroEnd; - _sessionManager.SendPlaystateCommand( session.Id, session.Id, @@ -183,7 +182,7 @@ public class AutoSkipCredits : IServerEntryPoint { Command = PlaystateCommand.Seek, ControllingUserId = session.UserId.ToString("N"), - SeekPositionTicks = creditEnd * TimeSpan.TicksPerSecond, + SeekPositionTicks = (long)adjustedEnd * TimeSpan.TicksPerSecond, }, CancellationToken.None); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs index 43fd7b0..7169924 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/PluginConfiguration.cs @@ -161,7 +161,17 @@ public class PluginConfiguration : BasePluginConfiguration /// /// Gets or sets the amount of intro to play (in seconds). /// - public int SecondsOfIntroToPlay { get; set; } = 2; + public int RemainingSecondsOfIntro { get; set; } = 2; + + /// + /// Gets or sets the amount of intro at start to play (in seconds). + /// + public int SecondsOfIntroStartToPlay { get; set; } = 0; + + /// + /// Gets or sets the amount of credit at start to play (in seconds). + /// + public int SecondsOfCreditsStartToPlay { get; set; } = 0; // ===== Internal algorithm settings ===== diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index adc9879..68f2b54 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -365,6 +365,17 @@
+
+ + +
+ Seconds of introduction start that should be played. Defaults to 0. +
+
+
+
+
+ + +
+ Seconds of credits start that should be played. Defaults to 0. +
+
+
+