namespace ConfusedPolarBear.Plugin.IntroSkipper.Tests; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using ConfusedPolarBear.Plugin.IntroSkipper.Analyzers; using ConfusedPolarBear.Plugin.IntroSkipper.Data; using MediaBrowser.Model.Entities; using Microsoft.Extensions.Logging; using Xunit; public class TestChapterAnalyzer { [Theory] [InlineData("Opening")] [InlineData("OP")] [InlineData("Intro")] [InlineData("Intro Start")] [InlineData("Introduction")] public void TestIntroductionExpression(string chapterName) { var chapters = CreateChapters(chapterName, AnalysisMode.Introduction); var introChapter = FindChapter(chapters, AnalysisMode.Introduction); Assert.NotNull(introChapter); Assert.Equal(60, introChapter.Start); Assert.Equal(90, introChapter.End); } [Theory] [InlineData("End Credits")] [InlineData("Ending")] [InlineData("Credit start")] [InlineData("Closing Credits")] [InlineData("Credits")] public void TestEndCreditsExpression(string chapterName) { var chapters = CreateChapters(chapterName, AnalysisMode.Credits); var creditsChapter = FindChapter(chapters, AnalysisMode.Credits); Assert.NotNull(creditsChapter); Assert.Equal(1890, creditsChapter.Start); Assert.Equal(2000, creditsChapter.End); } private Segment? FindChapter(Collection chapters, AnalysisMode mode) { var logger = new LoggerFactory().CreateLogger(); var analyzer = new ChapterAnalyzer(logger); var config = new Configuration.PluginConfiguration(); var expression = mode == AnalysisMode.Introduction ? config.ChapterAnalyzerIntroductionPattern : config.ChapterAnalyzerEndCreditsPattern; return analyzer.FindMatchingChapter(new() { Duration = 2000 }, chapters, expression, mode); } private Collection CreateChapters(string name, AnalysisMode mode) { var chapters = new[]{ CreateChapter("Cold Open", 0), CreateChapter(mode == AnalysisMode.Introduction ? name : "Introduction", 60), CreateChapter("Main Episode", 90), CreateChapter(mode == AnalysisMode.Credits ? name : "Credits", 1890) }; return new(new List(chapters)); } /// /// Create a ChapterInfo object. /// /// Chapter name. /// Chapter position (in seconds). /// ChapterInfo. private static ChapterInfo CreateChapter(string name, int position) { return new() { Name = name, StartPositionTicks = TimeSpan.FromSeconds(position).Ticks }; } }