Browse Source

yaml playout skip items expression (#2092)

pull/2093/head
Jason Dove 2 months ago committed by GitHub
parent
commit
7457301d3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      CHANGELOG.md
  2. 35
      ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutSkipItemsHandler.cs
  3. 2
      ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutSkipItemsInstruction.cs

8
CHANGELOG.md

@ -46,6 +46,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- The current time (as a decimal) can also be used in the expression, e.g. `now > 23` - The current time (as a decimal) can also be used in the expression, e.g. `now > 23`
- `now = hours + minutes / 60.0 + seconds / 3600.0` - `now = hours + minutes / 60.0 + seconds / 3600.0`
- So `10:30 AM` would be `10.5`, `10:45 PM` would be `22.75`, etc - So `10:30 AM` would be `10.5`, `10:45 PM` would be `22.75`, etc
- YAML playout: make `skip_items` an expression
- The following parameters can be used:
- `count`: the total number of items in the content
- `random`: a random number between zero and (count - 1)
- For example:
- `count / 2` will start in the middle of the content
- `random` will start at a random point in the content
- `2` (similar to before this change) will skip the first two items in the content
### Changed ### Changed
- Allow `Other Video` libraries and `Image` libraries to use the same folders - Allow `Other Video` libraries and `Image` libraries to use the same folders

35
ErsatzTV.Core/Scheduling/YamlScheduling/Handlers/YamlPlayoutSkipItemsHandler.cs

@ -20,12 +20,6 @@ public class YamlPlayoutSkipItemsHandler(EnumeratorCache enumeratorCache) : IYam
return false; return false;
} }
if (skipItems.SkipItems < 0)
{
logger.LogWarning("Unable to skip invalid number: {Skip}", skipItems.SkipItems);
return false;
}
Option<IMediaCollectionEnumerator> maybeEnumerator = await enumeratorCache.GetCachedEnumeratorForContent( Option<IMediaCollectionEnumerator> maybeEnumerator = await enumeratorCache.GetCachedEnumeratorForContent(
context, context,
skipItems.Content, skipItems.Content,
@ -33,7 +27,34 @@ public class YamlPlayoutSkipItemsHandler(EnumeratorCache enumeratorCache) : IYam
foreach (IMediaCollectionEnumerator enumerator in maybeEnumerator) foreach (IMediaCollectionEnumerator enumerator in maybeEnumerator)
{ {
for (var i = 0; i < skipItems.SkipItems; i++) var expression = new NCalc.Expression(skipItems.SkipItems);
expression.EvaluateParameter += (name, e) =>
{
e.Result = name switch
{
"count" => enumerator.Count,
"random" => new Random().Next() % enumerator.Count,
_ => e.Result
};
};
object expressionResult = expression.Evaluate();
int skipCount = expressionResult switch
{
double doubleResult => (int)Math.Floor(doubleResult),
int intResult => intResult,
_ => 0
};
skipCount %= enumerator.Count;
if (skipCount < 0)
{
logger.LogWarning("Unable to skip invalid number: {Skip}", skipItems.SkipItems);
return false;
}
for (var i = 0; i < skipCount; i++)
{ {
enumerator.MoveNext(); enumerator.MoveNext();
} }

2
ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutSkipItemsInstruction.cs

@ -5,5 +5,5 @@ namespace ErsatzTV.Core.Scheduling.YamlScheduling.Models;
public class YamlPlayoutSkipItemsInstruction : YamlPlayoutInstruction public class YamlPlayoutSkipItemsInstruction : YamlPlayoutInstruction
{ {
[YamlMember(Alias = "skip_items", ApplyNamingConventions = false)] [YamlMember(Alias = "skip_items", ApplyNamingConventions = false)]
public int SkipItems { get; set; } public string SkipItems { get; set; }
} }

Loading…
Cancel
Save