Browse Source

fix chronological sorting for other videos (#2699)

pull/2700/head
Jason Dove 4 weeks ago committed by GitHub
parent
commit
72dc401829
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 48
      ErsatzTV.Core.Tests/Scheduling/ChronologicalContentTests.cs
  3. 6
      ErsatzTV.Core/Scheduling/ChronologicalMediaComparer.cs

1
CHANGELOG.md

@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -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

48
ErsatzTV.Core.Tests/Scheduling/ChronologicalContentTests.cs

@ -8,13 +8,8 @@ namespace ErsatzTV.Core.Tests.Scheduling; @@ -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<MediaItem> contents = Episodes(10);
var state = new CollectionEnumeratorState();
@ -29,6 +24,22 @@ public class ChronologicalContentTests @@ -29,6 +24,22 @@ public class ChronologicalContentTests
}
}
[Test]
public void OtherVideos_Should_Sort_By_ReleaseDate()
{
List<MediaItem> 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<DateTimeOffset>.None);
}
}
[Test]
public void State_Index_Should_Increment()
{
@ -77,14 +88,31 @@ public class ChronologicalContentTests @@ -77,14 +88,31 @@ public class ChronologicalContentTests
Range(1, count).Map(i => (MediaItem)new Episode
{
Id = i,
EpisodeMetadata = new List<EpisodeMetadata>
{
new()
EpisodeMetadata =
[
new EpisodeMetadata
{
ReleaseDate = new DateTime(2020, 1, i),
EpisodeNumber = 20 - i
}
}
]
})
.Reverse()
.ToList();
private static List<MediaItem> 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();

6
ErsatzTV.Core/Scheduling/ChronologicalMediaComparer.cs

@ -23,6 +23,9 @@ internal class ChronologicalMediaComparer : IComparer<MediaItem> @@ -23,6 +23,9 @@ internal class ChronologicalMediaComparer : IComparer<MediaItem>
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<MediaItem> @@ -37,6 +40,9 @@ internal class ChronologicalMediaComparer : IComparer<MediaItem>
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
};

Loading…
Cancel
Save