From 6f66909957dbb1eb402d5142c130e1131fa5b3f2 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Sat, 27 Jul 2024 14:26:33 -0500 Subject: [PATCH] add "all" instruction (#1821) * add "all" instruction * use string for value we don't care about --- .../Handlers/YamlPlayoutAllHandler.cs | 70 +++++++++++++++++++ .../Models/YamlPlayoutAllInstruction.cs | 6 ++ .../YamlScheduling/YamlPlayoutBuilder.cs | 2 + 3 files changed, 78 insertions(+) create mode 100644 ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutAllHandler.cs create mode 100644 ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutAllInstruction.cs diff --git a/ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutAllHandler.cs b/ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutAllHandler.cs new file mode 100644 index 000000000..48bfe565f --- /dev/null +++ b/ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutAllHandler.cs @@ -0,0 +1,70 @@ +using ErsatzTV.Core.Domain; +using ErsatzTV.Core.Interfaces.Scheduling; +using ErsatzTV.Core.Scheduling.YamlScheduling.Models; +using Microsoft.Extensions.Logging; + +namespace ErsatzTV.Core.Scheduling.YamlScheduling.Handlers; + +public class YamlPlayoutAllHandler(EnumeratorCache enumeratorCache) : YamlPlayoutContentHandler(enumeratorCache) +{ + public override async Task Handle( + YamlPlayoutContext context, + YamlPlayoutInstruction instruction, + ILogger logger, + CancellationToken cancellationToken) + { + if (instruction is not YamlPlayoutAllInstruction all) + { + return false; + } + + Option maybeEnumerator = await GetContentEnumerator( + context, + instruction.Content, + logger, + cancellationToken); + + foreach (IMediaCollectionEnumerator enumerator in maybeEnumerator) + { + for (var i = 0; i < enumerator.Count; i++) + { + foreach (MediaItem mediaItem in enumerator.Current) + { + TimeSpan itemDuration = DurationForMediaItem(mediaItem); + + // create a playout item + var playoutItem = new PlayoutItem + { + MediaItemId = mediaItem.Id, + Start = context.CurrentTime.UtcDateTime, + Finish = context.CurrentTime.UtcDateTime + itemDuration, + InPoint = TimeSpan.Zero, + OutPoint = itemDuration, + FillerKind = GetFillerKind(all), + //CustomTitle = scheduleItem.CustomTitle, + //WatermarkId = scheduleItem.WatermarkId, + //PreferredAudioLanguageCode = scheduleItem.PreferredAudioLanguageCode, + //PreferredAudioTitle = scheduleItem.PreferredAudioTitle, + //PreferredSubtitleLanguageCode = scheduleItem.PreferredSubtitleLanguageCode, + //SubtitleMode = scheduleItem.SubtitleMode + GuideGroup = context.GuideGroup + //GuideStart = effectiveBlock.Start.UtcDateTime, + //GuideFinish = blockFinish.UtcDateTime, + //BlockKey = JsonConvert.SerializeObject(effectiveBlock.BlockKey), + //CollectionKey = JsonConvert.SerializeObject(collectionKey, JsonSettings), + //CollectionEtag = collectionEtags[collectionKey] + }; + + context.Playout.Items.Add(playoutItem); + + context.CurrentTime += itemDuration; + enumerator.MoveNext(); + } + } + + return true; + } + + return false; + } +} diff --git a/ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutAllInstruction.cs b/ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutAllInstruction.cs new file mode 100644 index 000000000..551db4977 --- /dev/null +++ b/ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutAllInstruction.cs @@ -0,0 +1,6 @@ +namespace ErsatzTV.Core.Scheduling.YamlScheduling.Models; + +public class YamlPlayoutAllInstruction : YamlPlayoutInstruction +{ + public string All { get; set; } +} diff --git a/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutBuilder.cs index 3990fbafa..113f85ef1 100644 --- a/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutBuilder.cs @@ -130,6 +130,7 @@ public class YamlPlayoutBuilder( YamlPlayoutSkipItemsInstruction => new YamlPlayoutSkipItemsHandler(), // content handlers + YamlPlayoutAllInstruction => new YamlPlayoutAllHandler(enumeratorCache), YamlPlayoutCountInstruction => new YamlPlayoutCountHandler(enumeratorCache), YamlPlayoutDurationInstruction => new YamlPlayoutDurationHandler(enumeratorCache), YamlPlayoutPadToNextInstruction => new YamlPlayoutPadToNextHandler(enumeratorCache), @@ -164,6 +165,7 @@ public class YamlPlayoutBuilder( var instructionKeyMappings = new Dictionary { + { "all", typeof(YamlPlayoutAllInstruction) }, { "count", typeof(YamlPlayoutCountInstruction) }, { "duration", typeof(YamlPlayoutDurationInstruction) }, { "new_epg_group", typeof(YamlPlayoutNewEpgGroupInstruction) },