mirror of https://github.com/ErsatzTV/ErsatzTV.git
7 changed files with 149 additions and 41 deletions
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
using ErsatzTV.Core.Interfaces.Scheduling; |
||||
using ErsatzTV.Core.Scheduling.YamlScheduling.Models; |
||||
using Microsoft.Extensions.Logging; |
||||
|
||||
namespace ErsatzTV.Core.Scheduling.YamlScheduling.Handlers; |
||||
|
||||
public class YamlPlayoutPadUntilHandler(EnumeratorCache enumeratorCache) : YamlPlayoutDurationHandler(enumeratorCache) |
||||
{ |
||||
public override async Task<bool> Handle( |
||||
YamlPlayoutContext context, |
||||
YamlPlayoutInstruction instruction, |
||||
ILogger<YamlPlayoutBuilder> logger, |
||||
CancellationToken cancellationToken) |
||||
{ |
||||
if (instruction is not YamlPlayoutPadUntilInstruction padUntil) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
DateTimeOffset targetTime = context.CurrentTime; |
||||
|
||||
if (TimeOnly.TryParse(padUntil.PadUntil, out TimeOnly result)) |
||||
{ |
||||
//logger.LogDebug("Will pad until time {Time}", result);
|
||||
|
||||
var dayOnly = DateOnly.FromDateTime(targetTime.LocalDateTime); |
||||
var timeOnly = TimeOnly.FromDateTime(targetTime.LocalDateTime); |
||||
|
||||
if (timeOnly > result) |
||||
{ |
||||
if (padUntil.Tomorrow) |
||||
{ |
||||
// this is wrong when offset changes
|
||||
dayOnly = dayOnly.AddDays(1); |
||||
targetTime = new DateTimeOffset(dayOnly, result, targetTime.Offset); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
// this is wrong when offset changes
|
||||
targetTime = new DateTimeOffset(dayOnly, result, targetTime.Offset); |
||||
} |
||||
} |
||||
|
||||
// logger.LogDebug(
|
||||
// "Padding from {CurrentTime} until {TargetTime}",
|
||||
// context.CurrentTime,
|
||||
// targetTime);
|
||||
|
||||
Option<IMediaCollectionEnumerator> maybeEnumerator = await GetContentEnumerator( |
||||
context, |
||||
instruction.Content, |
||||
logger, |
||||
cancellationToken); |
||||
|
||||
Option<IMediaCollectionEnumerator> fallbackEnumerator = await GetContentEnumerator( |
||||
context, |
||||
padUntil.Fallback, |
||||
logger, |
||||
cancellationToken); |
||||
|
||||
foreach (IMediaCollectionEnumerator enumerator in maybeEnumerator) |
||||
{ |
||||
context.CurrentTime = Schedule( |
||||
context, |
||||
targetTime, |
||||
padUntil.DiscardAttempts, |
||||
padUntil.Trim, |
||||
GetFillerKind(padUntil), |
||||
enumerator, |
||||
fallbackEnumerator); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
using YamlDotNet.Serialization; |
||||
|
||||
namespace ErsatzTV.Core.Scheduling.YamlScheduling.Models; |
||||
|
||||
public class YamlPlayoutPadUntilInstruction : YamlPlayoutInstruction |
||||
{ |
||||
[YamlMember(Alias = "pad_until", ApplyNamingConventions = false)] |
||||
public string PadUntil { get; set; } |
||||
|
||||
public bool Tomorrow { get; set; } |
||||
|
||||
public bool Trim { get; set; } |
||||
|
||||
public string Fallback { get; set; } |
||||
|
||||
[YamlMember(Alias = "discard_attempts", ApplyNamingConventions = false)] |
||||
public int DiscardAttempts { get; set; } |
||||
} |
Loading…
Reference in new issue