diff --git a/CHANGELOG.md b/CHANGELOG.md index fe50d5826..34f6840fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Match graphics engine framerate with source content (or channel normalized) framerate - Fix loading requested number of epg entries for motion graphics elements - Fix bug with mirror channels where seemingly random content would be played every ~40 seconds +- Fix chronological sorting for Other Videos that have release date metadata ### Changed - No longer round framerate to nearest integer when normalizing framerate diff --git a/ErsatzTV.Core.Tests/Scheduling/ChronologicalContentTests.cs b/ErsatzTV.Core.Tests/Scheduling/ChronologicalContentTests.cs index 7f30e5f71..a07abb463 100644 --- a/ErsatzTV.Core.Tests/Scheduling/ChronologicalContentTests.cs +++ b/ErsatzTV.Core.Tests/Scheduling/ChronologicalContentTests.cs @@ -8,13 +8,8 @@ namespace ErsatzTV.Core.Tests.Scheduling; [TestFixture] public class ChronologicalContentTests { - [SetUp] - public void SetUp() => _cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token; - - private CancellationToken _cancellationToken; - [Test] - public void Episodes_Should_Sort_By_Aired() + public void Episodes_Should_Sort_By_ReleaseDate() { List contents = Episodes(10); var state = new CollectionEnumeratorState(); @@ -29,6 +24,22 @@ public class ChronologicalContentTests } } + [Test] + public void OtherVideos_Should_Sort_By_ReleaseDate() + { + List contents = OtherVideos(10); + var state = new CollectionEnumeratorState(); + + var chronologicalContent = new ChronologicalMediaCollectionEnumerator(contents, state); + + for (var i = 1; i <= 10; i++) + { + chronologicalContent.Current.IsSome.ShouldBeTrue(); + chronologicalContent.Current.Map(x => x.Id).IfNone(-1).ShouldBe(10 - i); + chronologicalContent.MoveNext(Option.None); + } + } + [Test] public void State_Index_Should_Increment() { @@ -77,14 +88,31 @@ public class ChronologicalContentTests Range(1, count).Map(i => (MediaItem)new Episode { Id = i, - EpisodeMetadata = new List - { - new() + EpisodeMetadata = + [ + new EpisodeMetadata { ReleaseDate = new DateTime(2020, 1, i), EpisodeNumber = 20 - i } - } + ] + }) + .Reverse() + .ToList(); + + private static List OtherVideos(int count) => + Range(1, count).Map(i => (MediaItem)new OtherVideo + { + // ids need to count down because fallback sorting is by id + // and we need the test to fail when these are sorted by id + Id = count - i, + OtherVideoMetadata = + [ + new OtherVideoMetadata + { + ReleaseDate = new DateTime(2020, 1, i) + } + ] }) .Reverse() .ToList(); diff --git a/ErsatzTV.Core/Scheduling/ChronologicalMediaComparer.cs b/ErsatzTV.Core/Scheduling/ChronologicalMediaComparer.cs index ae82a0436..7a2348fdb 100644 --- a/ErsatzTV.Core/Scheduling/ChronologicalMediaComparer.cs +++ b/ErsatzTV.Core/Scheduling/ChronologicalMediaComparer.cs @@ -23,6 +23,9 @@ internal class ChronologicalMediaComparer : IComparer MusicVideo mv => mv.MusicVideoMetadata.HeadOrNone().Match( mvm => mvm.ReleaseDate ?? DateTime.MaxValue, () => DateTime.MaxValue), + OtherVideo ov => ov.OtherVideoMetadata.HeadOrNone().Match( + ovm => ovm.ReleaseDate ?? DateTime.MaxValue, + () => DateTime.MaxValue), _ => DateTime.MaxValue }; @@ -37,6 +40,9 @@ internal class ChronologicalMediaComparer : IComparer MusicVideo mv => mv.MusicVideoMetadata.HeadOrNone().Match( mvm => mvm.ReleaseDate ?? DateTime.MaxValue, () => DateTime.MaxValue), + OtherVideo ov => ov.OtherVideoMetadata.HeadOrNone().Match( + ovm => ovm.ReleaseDate ?? DateTime.MaxValue, + () => DateTime.MaxValue), _ => DateTime.MaxValue };