diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs index c4216ca..5979093 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Analyzers/ChapterAnalyzer.cs @@ -115,7 +115,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)) { @@ -124,7 +124,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, @@ -154,6 +154,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;