Files
ersatztv/ErsatzTV.Core/Scheduling/MultiCollectionGroup.cs
T
Jason DoveandGitHub 632753ea93 add multi collections (#315)
* start to add multi-collections

* create multi collection with no items

* edit multi collections

* fix plex credentials threading issue

* add playback order to multi collection items

* group episodes outside of shuffled enumerator

* move playback order onto each schedule item

* fix multi collection grouping

* update changelog
2021-07-17 21:45:41 -05:00

42 lines
1.4 KiB
C#

using System;
using System.Linq;
using ErsatzTV.Core.Domain;
using static LanguageExt.Prelude;
namespace ErsatzTV.Core.Scheduling
{
public class MultiCollectionGroup : GroupedMediaItem
{
public MultiCollectionGroup(CollectionWithItems collectionWithItems)
{
if (collectionWithItems.UseCustomOrder)
{
if (collectionWithItems.MediaItems.Count > 0)
{
First = collectionWithItems.MediaItems.Head();
Additional = collectionWithItems.MediaItems.Tail().ToList();
}
else
{
throw new InvalidOperationException("Collection has no items");
}
}
else
{
switch (collectionWithItems.PlaybackOrder)
{
case PlaybackOrder.Chronological:
var sortedItems = collectionWithItems.MediaItems.OrderBy(identity, new ChronologicalMediaComparer())
.ToList();
First = sortedItems.Head();
Additional = sortedItems.Tail().ToList();
break;
default:
throw new NotSupportedException(
$"Unsupported MultiCollection PlaybackOrder: {collectionWithItems.PlaybackOrder}");
}
}
}
}
}