mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-19 07:06:48 +01:00
Merge pull request #16695 from ExpctING/fix_dummy_chapter
Fix dummy chapter handling for videos with a single chapter or short duration.
This commit is contained in:
@@ -129,7 +129,7 @@ public class ChapterManager : IChapterManager
|
||||
|
||||
var averageChapterDuration = GetAverageDurationBetweenChapters(chapters);
|
||||
var threshold = TimeSpan.FromSeconds(1).Ticks;
|
||||
if (averageChapterDuration < threshold)
|
||||
if (chapters.Count >= 2 && averageChapterDuration < threshold)
|
||||
{
|
||||
_logger.LogInformation("Skipping chapter image extraction for {Video} as the average chapter duration {AverageDuration} was lower than the minimum threshold {Threshold}", video.Name, averageChapterDuration, threshold);
|
||||
extractImages = false;
|
||||
|
||||
@@ -276,7 +276,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
if (options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh
|
||||
|| options.MetadataRefreshMode == MetadataRefreshMode.Default)
|
||||
{
|
||||
if (_config.Configuration.DummyChapterDuration > 0 && chapters.Length == 0 && mediaStreams.Any(i => i.Type == MediaStreamType.Video))
|
||||
if (_config.Configuration.DummyChapterDuration > 0 && chapters.Length <= 1 && mediaStreams.Any(i => i.Type == MediaStreamType.Video))
|
||||
{
|
||||
chapters = CreateDummyChapters(video);
|
||||
}
|
||||
@@ -616,12 +616,13 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
}
|
||||
|
||||
long dummyChapterDuration = TimeSpan.FromSeconds(_config.Configuration.DummyChapterDuration).Ticks;
|
||||
if (runtime <= dummyChapterDuration)
|
||||
|
||||
if (runtime <= 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
int chapterCount = (int)(runtime / dummyChapterDuration);
|
||||
int chapterCount = Math.Max(1, (int)(runtime / dummyChapterDuration));
|
||||
var chapters = new ChapterInfo[chapterCount];
|
||||
|
||||
long currentChapterTicks = 0;
|
||||
|
||||
@@ -45,8 +45,9 @@ public class FFProbeVideoInfoTests
|
||||
[Theory]
|
||||
[InlineData(null, 0)]
|
||||
[InlineData(0L, 0)]
|
||||
[InlineData(1L, 0)]
|
||||
[InlineData(TimeSpan.TicksPerMinute * 5, 0)]
|
||||
[InlineData(1L, 1)]
|
||||
[InlineData(TimeSpan.TicksPerMinute * 3, 1)]
|
||||
[InlineData(TimeSpan.TicksPerMinute * 5, 1)]
|
||||
[InlineData((TimeSpan.TicksPerMinute * 5) + 1, 1)]
|
||||
[InlineData(TimeSpan.TicksPerMinute * 50, 10)]
|
||||
public void CreateDummyChapters_ValidRuntime_CorrectChaptersCount(long? runtime, int chaptersCount)
|
||||
@@ -58,4 +59,20 @@ public class FFProbeVideoInfoTests
|
||||
|
||||
Assert.Equal(chaptersCount, chapters.Length);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1L)]
|
||||
[InlineData(TimeSpan.TicksPerMinute * 3)]
|
||||
[InlineData(TimeSpan.TicksPerMinute * 5)]
|
||||
[InlineData((TimeSpan.TicksPerMinute * 5) + 1)]
|
||||
[InlineData((TimeSpan.TicksPerMinute * 50) + 1)]
|
||||
public void CreateDummyChapters_PositiveRuntime_NoChapterBeyondRuntime(long runtime)
|
||||
{
|
||||
var chapters = _fFProbeVideoInfo.CreateDummyChapters(new Video()
|
||||
{
|
||||
RunTimeTicks = runtime
|
||||
});
|
||||
|
||||
Assert.All(chapters, chapter => Assert.True(chapter.StartPositionTicks < runtime));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user