diff --git a/CHANGELOG.md b/CHANGELOG.md index 80d19f6e6..2b7b0778a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - fix green padding when encoding h264 using main profile - Automatically kill playback troubleshooting ffmpeg process if it hasn't completed after two minutes - Fix playback of certain BT.2020 content +- Use playlist item count when using a playlist as filler (instead of a fixed count of 1 for each playlist item) ### Changed - No longer round framerate to nearest integer when normalizing framerate diff --git a/ErsatzTV.Core.Tests/Scheduling/PlaylistEnumeratorTests.cs b/ErsatzTV.Core.Tests/Scheduling/PlaylistEnumeratorTests.cs index 5d2a496ce..1d174815b 100644 --- a/ErsatzTV.Core.Tests/Scheduling/PlaylistEnumeratorTests.cs +++ b/ErsatzTV.Core.Tests/Scheduling/PlaylistEnumeratorTests.cs @@ -285,6 +285,78 @@ public class PlaylistEnumeratorTests items.ShouldBe([20, 30, 10, 11]); } + [Test] + public async Task CountForFiller_Should_Honor_Custom_Count_And_PlayAll() + { + // this isn't needed for chronological, so no need to implement anything + IMediaCollectionRepository repo = Substitute.For(); + + var playlistItemMap = new Dictionary> + { + { + new PlaylistItem + { + Id = 1, + Index = 0, + PlaybackOrder = PlaybackOrder.Chronological, + PlayAll = false, + Count = 2, + CollectionType = CollectionType.Collection, + CollectionId = 1 + }, + [FakeMovie(10), FakeMovie(11), FakeMovie(12)] + }, + { + new PlaylistItem + { + Id = 2, + Index = 1, + PlaybackOrder = PlaybackOrder.Chronological, + PlayAll = false, + CollectionType = CollectionType.Collection, + CollectionId = 2 + }, + [FakeMovie(15)] + }, + { + new PlaylistItem + { + Id = 3, + Index = 2, + PlaybackOrder = PlaybackOrder.Chronological, + PlayAll = false, + CollectionType = CollectionType.Collection, + CollectionId = 3 + }, + [FakeMovie(20)] + }, + { + new PlaylistItem + { + Id = 4, + Index = 3, + PlaybackOrder = PlaybackOrder.Chronological, + PlayAll = true, + CollectionType = CollectionType.Collection, + CollectionId = 4 + }, + [FakeMovie(25), FakeMovie(26), FakeMovie(27)] + } + }; + + var state = new CollectionEnumeratorState { Seed = 1 }; + + PlaylistEnumerator enumerator = await PlaylistEnumerator.Create( + repo, + playlistItemMap, + state, + shufflePlaylistItems: true, + batchSize: Option.None, + CancellationToken.None); + + enumerator.CountForFiller.ShouldBe(7); + } + private static Movie FakeMovie(int id) => new() { Id = id, diff --git a/ErsatzTV.Core/Scheduling/PlaylistEnumerator.cs b/ErsatzTV.Core/Scheduling/PlaylistEnumerator.cs index 61707d570..65300b270 100644 --- a/ErsatzTV.Core/Scheduling/PlaylistEnumerator.cs +++ b/ErsatzTV.Core/Scheduling/PlaylistEnumerator.cs @@ -23,7 +23,7 @@ public class PlaylistEnumerator : IMediaCollectionEnumerator public int CountForRandom => _allMediaItemIds.Count; - public int CountForFiller => _sortedEnumerators.Select(t => t.PlayAll ? t.Enumerator.Count : 1).Sum(); + public int CountForFiller => _sortedEnumerators.Select(t => t.PlayAll ? t.Enumerator.Count : t.Count ?? 1).Sum(); public ImmutableList ChildEnumerators { get; private set; }