Browse Source

add xmltv days to build setting (#1678)

pull/1679/head
Jason Dove 1 year ago committed by GitHub
parent
commit
af5dc0968b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      CHANGELOG.md
  2. 23
      ErsatzTV.Application/Channels/Commands/RefreshChannelDataHandler.cs
  3. 17
      ErsatzTV.Application/Configuration/Commands/UpdateXmltvSettingsHandler.cs
  4. 3
      ErsatzTV.Application/Configuration/Queries/GetXmltvSettingsHandler.cs
  5. 1
      ErsatzTV.Application/Configuration/XmltvSettingsViewModel.cs
  6. 1
      ErsatzTV.Core/Domain/ConfigElementKey.cs
  7. 14
      ErsatzTV/Pages/Settings.razor

3
CHANGELOG.md

@ -19,6 +19,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -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

23
ErsatzTV.Application/Channels/Commands/RefreshChannelDataHandler.cs

@ -170,13 +170,23 @@ public class RefreshChannelDataHandler : IRequestHandler<RefreshChannelData> @@ -170,13 +170,23 @@ public class RefreshChannelDataHandler : IRequestHandler<RefreshChannelData>
await using var xml = XmlWriter.Create(
ms,
new XmlWriterSettings { Async = true, ConformanceLevel = ConformanceLevel.Fragment });
int daysToBuild = await _configElementRepository
.GetValue<int>(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<RefreshChannelData> @@ -190,7 +200,11 @@ public class RefreshChannelDataHandler : IRequestHandler<RefreshChannelData>
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<RefreshChannelData> @@ -204,7 +218,10 @@ public class RefreshChannelDataHandler : IRequestHandler<RefreshChannelData>
xml);
break;
case ProgramSchedulePlayoutType.ExternalJson:
List<PlayoutItem> externalJsonSorted = await CollectExternalJsonItems(playout.ExternalJsonFile);
var externalJsonSorted = (await CollectExternalJsonItems(playout.ExternalJsonFile))
.Filter(pi => pi.StartOffset <= finish)
.ToList();
await WritePlayoutXml(
request,
externalJsonSorted,

17
ErsatzTV.Application/Configuration/Commands/UpdateXmltvSettingsHandler.cs

@ -16,11 +16,26 @@ public class UpdateXmltvSettingsHandler( @@ -16,11 +16,26 @@ public class UpdateXmltvSettingsHandler(
{
public async Task<Either<BaseError, Unit>> Handle(
UpdateXmltvSettings request,
CancellationToken cancellationToken) => await ApplyUpdate(request.XmltvSettings);
CancellationToken cancellationToken)
{
int playoutDaysToBuild =
await configElementRepository
.GetValue<int>(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<Unit> ApplyUpdate(XmltvSettingsViewModel xmltvSettings)
{
await configElementRepository.Upsert(ConfigElementKey.XmltvTimeZone, xmltvSettings.TimeZone);
await configElementRepository.Upsert(ConfigElementKey.XmltvDaysToBuild, xmltvSettings.DaysToBuild);
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync();

3
ErsatzTV.Application/Configuration/Queries/GetXmltvSettingsHandler.cs

@ -8,11 +8,14 @@ public class GetXmltvSettingsHandler(IConfigElementRepository configElementRepos @@ -8,11 +8,14 @@ public class GetXmltvSettingsHandler(IConfigElementRepository configElementRepos
{
public async Task<XmltvSettingsViewModel> Handle(GetXmltvSettings request, CancellationToken cancellationToken)
{
Option<int> daysToBuild = await configElementRepository.GetValue<int>(ConfigElementKey.XmltvDaysToBuild);
Option<XmltvTimeZone> maybeTimeZone =
await configElementRepository.GetValue<XmltvTimeZone>(ConfigElementKey.XmltvTimeZone);
return new XmltvSettingsViewModel
{
DaysToBuild = await daysToBuild.IfNoneAsync(2),
TimeZone = await maybeTimeZone.IfNoneAsync(XmltvTimeZone.Local)
};
}

1
ErsatzTV.Application/Configuration/XmltvSettingsViewModel.cs

@ -2,5 +2,6 @@ namespace ErsatzTV.Application.Configuration; @@ -2,5 +2,6 @@ namespace ErsatzTV.Application.Configuration;
public class XmltvSettingsViewModel
{
public int DaysToBuild { get; set; }
public XmltvTimeZone TimeZone { get; set; }
}

1
ErsatzTV.Core/Domain/ConfigElementKey.cs

@ -43,4 +43,5 @@ public class ConfigElementKey @@ -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");
}

14
ErsatzTV/Pages/Settings.razor

@ -236,7 +236,7 @@ @@ -236,7 +236,7 @@
@bind-Value="_playoutSettings.DaysToBuild"
Validation="@(new Func<int, string>(ValidatePlayoutDaysToBuild))"
Required="true"
RequiredError="Days to build is required!"
RequiredError="Playout days to build is required!"
Adornment="Adornment.End"
AdornmentText="Days"/>
<MudElement HtmlTag="div" Class="mt-3">
@ -298,6 +298,14 @@ @@ -298,6 +298,14 @@
</CardHeaderContent>
</MudCardHeader>
<MudCardContent>
<MudTextField T="int"
Label="Days To Build"
@bind-Value="_xmltvSettings.DaysToBuild"
Validation="@(new Func<int, string>(ValidateXmltvDaysToBuild))"
Required="true"
RequiredError="XMLTV days to build is required!"
Adornment="Adornment.End"
AdornmentText="Days"/>
<MudSelect Class="mt-3"
Label="XMLTV Time Zone"
@bind-Value="_xmltvSettings.TimeZone"
@ -374,7 +382,9 @@ @@ -374,7 +382,9 @@
_ => 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;

Loading…
Cancel
Save