From e58e74b5d428e9e108b04a72f2dc892ae086412a Mon Sep 17 00:00:00 2001 From: rlauuzo <46294892+rlauuzo@users.noreply.github.com> Date: Wed, 1 May 2024 17:13:34 +0200 Subject: [PATCH] find the first credits chapter marker (#138) --- .../Analyzers/ChapterAnalyzer.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs index 1987ea9..4536227 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs @@ -116,7 +116,7 @@ public class ChapterAnalyzer : IMediaFileAnalyzer for (int i = chapters.Count - 2; i >= 0; i--) { var current = chapters[i]; - var next = chapters[i + 1]; + var previous = chapters[i - 1]; if (string.IsNullOrWhiteSpace(current.Name)) { @@ -125,7 +125,7 @@ public class ChapterAnalyzer : IMediaFileAnalyzer var currentRange = new TimeRange( TimeSpan.FromTicks(current.StartPositionTicks).TotalSeconds, - TimeSpan.FromTicks(next.StartPositionTicks).TotalSeconds); + TimeSpan.FromTicks(chapters[i + 1].StartPositionTicks).TotalSeconds); var baseMessage = string.Format( CultureInfo.InvariantCulture, @@ -155,6 +155,21 @@ public class ChapterAnalyzer : IMediaFileAnalyzer continue; } + if (!string.IsNullOrWhiteSpace(previous.Name)) + { + // Check for possibility of overlapping keywords + var overlap = Regex.IsMatch( + previous.Name, + expression, + RegexOptions.None, + TimeSpan.FromSeconds(1)); + + if (overlap) + { + continue; + } + } + matchingChapter = new(episode.EpisodeId, currentRange); _logger.LogTrace("{Base}: okay", baseMessage); break;