add basic marathon content (#1842)
This commit is contained in:
@@ -79,6 +79,7 @@ public class EnumeratorCache(IMediaCollectionRepository mediaCollectionRepositor
|
||||
case YamlPlayoutContentMultiCollectionItem multiCollection:
|
||||
items = await mediaCollectionRepository.GetMultiCollectionItemsByName(multiCollection.MultiCollection);
|
||||
break;
|
||||
|
||||
// playlist is handled later
|
||||
}
|
||||
|
||||
@@ -86,6 +87,43 @@ public class EnumeratorCache(IMediaCollectionRepository mediaCollectionRepositor
|
||||
|
||||
var state = new CollectionEnumeratorState { Seed = context.Playout.Seed + index, Index = 0 };
|
||||
|
||||
// marathon is a special case that needs to be handled on its own
|
||||
if (content is YamlPlayoutContentMarathonItem marathon)
|
||||
{
|
||||
if (!Enum.TryParse(marathon.ItemOrder, true, out PlaybackOrder playbackOrder))
|
||||
{
|
||||
playbackOrder = PlaybackOrder.Shuffle;
|
||||
}
|
||||
|
||||
var allMediaItems = new List<MediaItem>();
|
||||
|
||||
// grab items from each show guid
|
||||
foreach (string showGuid in marathon.Guids.Map(g => $"{g.Source}://{g.Value}"))
|
||||
{
|
||||
allMediaItems.AddRange(await mediaCollectionRepository.GetShowItemsByShowGuids([showGuid]));
|
||||
}
|
||||
|
||||
// TODO: support different group_by
|
||||
|
||||
var groups = allMediaItems
|
||||
.GroupBy(MediaItemKeyByShow)
|
||||
.ToList();
|
||||
|
||||
Dictionary<PlaylistItem, List<MediaItem>> itemMap = [];
|
||||
|
||||
foreach (IGrouping<int, MediaItem> group in groups)
|
||||
{
|
||||
PlaylistItem playlistItem = GroupToPlaylistItem(marathon, playbackOrder, group);
|
||||
itemMap.Add(playlistItem, group.ToList());
|
||||
}
|
||||
|
||||
return await PlaylistEnumerator.Create(
|
||||
mediaCollectionRepository,
|
||||
itemMap,
|
||||
state,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
// playlist is a special case that needs to be handled on its own
|
||||
if (content is YamlPlayoutContentPlaylistItem playlist)
|
||||
{
|
||||
@@ -121,4 +159,28 @@ public class EnumeratorCache(IMediaCollectionRepository mediaCollectionRepositor
|
||||
|
||||
return Option<IMediaCollectionEnumerator>.None;
|
||||
}
|
||||
|
||||
private int MediaItemKeyByShow(MediaItem mediaItem) =>
|
||||
mediaItem switch
|
||||
{
|
||||
Episode e => e.Season?.ShowId ?? 0,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
private static PlaylistItem GroupToPlaylistItem(
|
||||
YamlPlayoutContentMarathonItem marathon,
|
||||
PlaybackOrder playbackOrder,
|
||||
IGrouping<int, MediaItem> group) =>
|
||||
new()
|
||||
{
|
||||
Index = group.Key,
|
||||
|
||||
CollectionType = ProgramScheduleItemCollectionType.TelevisionShow,
|
||||
MediaItemId = group.Key,
|
||||
|
||||
PlayAll = marathon.PlayAllItems,
|
||||
PlaybackOrder = playbackOrder,
|
||||
|
||||
IncludeInProgramGuide = true
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace ErsatzTV.Core.Scheduling.YamlScheduling.Models;
|
||||
|
||||
public class YamlPlayoutContentMarathonItem : YamlPlayoutContentItem
|
||||
{
|
||||
public string Marathon { get; set; }
|
||||
|
||||
public List<YamlPlayoutContentGuid> Guids { get; set; } = [];
|
||||
|
||||
[YamlMember(Alias = "group_by", ApplyNamingConventions = false)]
|
||||
public string GroupBy { get; set; }
|
||||
|
||||
[YamlMember(Alias = "item_order", ApplyNamingConventions = false)]
|
||||
public string ItemOrder { get; set; }
|
||||
|
||||
[YamlMember(Alias = "play_all_items", ApplyNamingConventions = false)]
|
||||
public bool PlayAllItems { get; set; }
|
||||
}
|
||||
@@ -281,6 +281,7 @@ public class YamlPlayoutBuilder(
|
||||
var contentKeyMappings = new Dictionary<string, Type>
|
||||
{
|
||||
{ "collection", typeof(YamlPlayoutContentCollectionItem) },
|
||||
{ "marathon", typeof(YamlPlayoutContentMarathonItem) },
|
||||
{ "multi_collection", typeof(YamlPlayoutContentMultiCollectionItem) },
|
||||
{ "playlist", typeof(YamlPlayoutContentPlaylistItem) },
|
||||
{ "search", typeof(YamlPlayoutContentSearchItem) },
|
||||
|
||||
Reference in New Issue
Block a user