diff --git a/CHANGELOG.md b/CHANGELOG.md index e43a4805b..6d5d3070e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Block playouts can also have a default deco - This will apply whenever a deco template is missing, or when a deco template item cannot be found for the current time - Effectively, this sets a default watermark and dead air fallback for the entire playout +- Add `XMLTV Days To Build` setting, which is distinct from the existing `Playout Days To Build` setting + - The value for `XMLTV Days To Build` cannot be larger than `Playout Days To Build` + - This allows, for example, a week of playout data while optimizing XMLTV data to only a day or two ### Fixed - Fix some cases of 404s from Plex when files were replaced and scanning the library from ETV didn't help diff --git a/ErsatzTV.Application/Channels/Commands/RefreshChannelDataHandler.cs b/ErsatzTV.Application/Channels/Commands/RefreshChannelDataHandler.cs index afba0e363..6b84bcfea 100644 --- a/ErsatzTV.Application/Channels/Commands/RefreshChannelDataHandler.cs +++ b/ErsatzTV.Application/Channels/Commands/RefreshChannelDataHandler.cs @@ -170,13 +170,23 @@ public class RefreshChannelDataHandler : IRequestHandler await using var xml = XmlWriter.Create( ms, new XmlWriterSettings { Async = true, ConformanceLevel = ConformanceLevel.Fragment }); + + int daysToBuild = await _configElementRepository + .GetValue(ConfigElementKey.XmltvDaysToBuild) + .IfNoneAsync(2); + DateTimeOffset finish = DateTimeOffset.UtcNow.AddDays(daysToBuild); + foreach (Playout playout in playouts) { switch (playout.ProgramSchedulePlayoutType) { case ProgramSchedulePlayoutType.Flood: - var floodSorted = playouts.Collect(p => p.Items).OrderBy(pi => pi.Start).ToList(); + var floodSorted = playouts + .Collect(p => p.Items) + .OrderBy(pi => pi.Start) + .Filter(pi => pi.StartOffset <= finish) + .ToList(); await WritePlayoutXml( request, floodSorted, @@ -190,7 +200,11 @@ public class RefreshChannelDataHandler : IRequestHandler xml); break; case ProgramSchedulePlayoutType.Block: - var blockSorted = playouts.Collect(p => p.Items).OrderBy(pi => pi.Start).ToList(); + var blockSorted = playouts + .Collect(p => p.Items) + .OrderBy(pi => pi.Start) + .Filter(pi => pi.StartOffset <= finish) + .ToList(); await WriteBlockPlayoutXml( request, blockSorted, @@ -204,7 +218,10 @@ public class RefreshChannelDataHandler : IRequestHandler xml); break; case ProgramSchedulePlayoutType.ExternalJson: - List externalJsonSorted = await CollectExternalJsonItems(playout.ExternalJsonFile); + var externalJsonSorted = (await CollectExternalJsonItems(playout.ExternalJsonFile)) + .Filter(pi => pi.StartOffset <= finish) + .ToList(); + await WritePlayoutXml( request, externalJsonSorted, diff --git a/ErsatzTV.Application/Configuration/Commands/UpdateXmltvSettingsHandler.cs b/ErsatzTV.Application/Configuration/Commands/UpdateXmltvSettingsHandler.cs index 242c0a70d..0695bb9c9 100644 --- a/ErsatzTV.Application/Configuration/Commands/UpdateXmltvSettingsHandler.cs +++ b/ErsatzTV.Application/Configuration/Commands/UpdateXmltvSettingsHandler.cs @@ -16,11 +16,26 @@ public class UpdateXmltvSettingsHandler( { public async Task> Handle( UpdateXmltvSettings request, - CancellationToken cancellationToken) => await ApplyUpdate(request.XmltvSettings); + CancellationToken cancellationToken) + { + int playoutDaysToBuild = + await configElementRepository + .GetValue(ConfigElementKey.PlayoutDaysToBuild) + .IfNoneAsync(2); + + if (playoutDaysToBuild < request.XmltvSettings.DaysToBuild) + { + return BaseError.New( + $"XMLTV days to build ({request.XmltvSettings.DaysToBuild}) cannot be greater than Playout days to build ({playoutDaysToBuild})"); + } + + return await ApplyUpdate(request.XmltvSettings); + } private async Task ApplyUpdate(XmltvSettingsViewModel xmltvSettings) { await configElementRepository.Upsert(ConfigElementKey.XmltvTimeZone, xmltvSettings.TimeZone); + await configElementRepository.Upsert(ConfigElementKey.XmltvDaysToBuild, xmltvSettings.DaysToBuild); await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(); diff --git a/ErsatzTV.Application/Configuration/Queries/GetXmltvSettingsHandler.cs b/ErsatzTV.Application/Configuration/Queries/GetXmltvSettingsHandler.cs index a55a6a90a..365833bde 100644 --- a/ErsatzTV.Application/Configuration/Queries/GetXmltvSettingsHandler.cs +++ b/ErsatzTV.Application/Configuration/Queries/GetXmltvSettingsHandler.cs @@ -8,11 +8,14 @@ public class GetXmltvSettingsHandler(IConfigElementRepository configElementRepos { public async Task Handle(GetXmltvSettings request, CancellationToken cancellationToken) { + Option daysToBuild = await configElementRepository.GetValue(ConfigElementKey.XmltvDaysToBuild); + Option maybeTimeZone = await configElementRepository.GetValue(ConfigElementKey.XmltvTimeZone); return new XmltvSettingsViewModel { + DaysToBuild = await daysToBuild.IfNoneAsync(2), TimeZone = await maybeTimeZone.IfNoneAsync(XmltvTimeZone.Local) }; } diff --git a/ErsatzTV.Application/Configuration/XmltvSettingsViewModel.cs b/ErsatzTV.Application/Configuration/XmltvSettingsViewModel.cs index c7bd5128f..18909dcbf 100644 --- a/ErsatzTV.Application/Configuration/XmltvSettingsViewModel.cs +++ b/ErsatzTV.Application/Configuration/XmltvSettingsViewModel.cs @@ -2,5 +2,6 @@ namespace ErsatzTV.Application.Configuration; public class XmltvSettingsViewModel { + public int DaysToBuild { get; set; } public XmltvTimeZone TimeZone { get; set; } } diff --git a/ErsatzTV.Core/Domain/ConfigElementKey.cs b/ErsatzTV.Core/Domain/ConfigElementKey.cs index a501cba7f..5f2fe435f 100644 --- a/ErsatzTV.Core/Domain/ConfigElementKey.cs +++ b/ErsatzTV.Core/Domain/ConfigElementKey.cs @@ -43,4 +43,5 @@ public class ConfigElementKey public static ConfigElementKey PlayoutDaysToBuild => new("playout.days_to_build"); public static ConfigElementKey PlayoutSkipMissingItems => new("playout.skip_missing_items"); public static ConfigElementKey XmltvTimeZone => new("xmltv.time_zone"); + public static ConfigElementKey XmltvDaysToBuild => new("xmltv.days_to_build"); } diff --git a/ErsatzTV/Pages/Settings.razor b/ErsatzTV/Pages/Settings.razor index c4f730254..acafc5b1f 100644 --- a/ErsatzTV/Pages/Settings.razor +++ b/ErsatzTV/Pages/Settings.razor @@ -236,7 +236,7 @@ @bind-Value="_playoutSettings.DaysToBuild" Validation="@(new Func(ValidatePlayoutDaysToBuild))" Required="true" - RequiredError="Days to build is required!" + RequiredError="Playout days to build is required!" Adornment="Adornment.End" AdornmentText="Days"/> @@ -298,6 +298,14 @@ + null }; - private static string ValidatePlayoutDaysToBuild(int daysToBuild) => daysToBuild <= 0 ? "Days to build must be greater than zero" : null; + private static string ValidateXmltvDaysToBuild(int daysToBuild) => daysToBuild <= 0 ? "XMLTV days to build must be greater than zero" : null; + + private static string ValidatePlayoutDaysToBuild(int daysToBuild) => daysToBuild <= 0 ? "Playout days to build must be greater than zero" : null; private static string ValidateHlsSegmenterIdleTimeout(int idleTimeout) => idleTimeout < 30 ? "HLS Segmenter idle timeout must be greater than or equal to 30" : null;