diff --git a/CHANGELOG.md b/CHANGELOG.md index 8deb6fa02..deaf9b83a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - More rarely, content with an embedded subtitle that has stream index zero would create invalid subtitle records - Both cases will automatically be cleaned up during the next local library scan - Use `und` language tag with sidecar subtitles that have no language in the file name +- Automatically remove already-played playout items from all on demand channels +- Automatically remove already-played playout items from (continuous) scripted schedules ### Changed - Upgrade Intel driver in docker containers to support latest Battlemage devices (e.g. B70) diff --git a/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs index 1d467f567..582eb65d1 100644 --- a/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs @@ -301,6 +301,7 @@ public class PlayoutBuilder : IPlayoutBuilder playout.Seed = new Random().Next(); // don't trim start for on demand channels, we want to time shift it all forward + // on-demand channels will trim already-played items in time shifter if (referenceData.Channel.PlayoutMode is ChannelPlayoutMode.OnDemand) { TrimStart = false; diff --git a/ErsatzTV.Core/Scheduling/ScriptedScheduling/ScriptedPlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/ScriptedScheduling/ScriptedPlayoutBuilder.cs index 2345d5344..3091a5752 100644 --- a/ErsatzTV.Core/Scheduling/ScriptedScheduling/ScriptedPlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/ScriptedScheduling/ScriptedPlayoutBuilder.cs @@ -108,6 +108,12 @@ public class ScriptedPlayoutBuilder( playout.Anchor = schedulingEngine.GetAnchor(); + // on-demand channels will trim already-played items in time shifter + if (referenceData.Channel.PlayoutMode != ChannelPlayoutMode.OnDemand) + { + schedulingEngine.RemoveBefore(start.AddHours(-4)); + } + result = MergeResult(result, schedulingEngine.GetState()); } catch (OperationCanceledException) diff --git a/ErsatzTV.Infrastructure/Scheduling/PlayoutTimeShifter.cs b/ErsatzTV.Infrastructure/Scheduling/PlayoutTimeShifter.cs index bac5f42e4..9e93f6ea8 100644 --- a/ErsatzTV.Infrastructure/Scheduling/PlayoutTimeShifter.cs +++ b/ErsatzTV.Infrastructure/Scheduling/PlayoutTimeShifter.cs @@ -72,6 +72,21 @@ public class PlayoutTimeShifter( playout.OnDemandCheckpoint = playout.Items.Min(p => p.StartOffset); } + // remove items that have finished before the checkpoint + foreach (DateTimeOffset checkpoint in Optional(playout.OnDemandCheckpoint)) + { + DateTime checkpointUtc = checkpoint.UtcDateTime; + int removed = playout.Items.RemoveAll(i => i.Finish < checkpointUtc); + if (removed > 0) + { + logger.LogDebug( + "Removing {Count} played items before shifting playout for channel {Number} - {Name}", + removed, + playout.Channel.Number, + playout.Channel.Name); + } + } + TimeSpan toOffset = now - playout.OnDemandCheckpoint.IfNone(now); logger.LogDebug(