mirror of https://github.com/ErsatzTV/ErsatzTV.git
19 changed files with 12226 additions and 28 deletions
@ -0,0 +1,70 @@ |
|||||||
|
using ErsatzTV.Core.Domain; |
||||||
|
using ErsatzTV.Core.Domain.Filler; |
||||||
|
using NCalc; |
||||||
|
|
||||||
|
namespace ErsatzTV.Core.Scheduling; |
||||||
|
|
||||||
|
public static class FillerExpression |
||||||
|
{ |
||||||
|
public static List<MediaChapter> FilterChapters(FillerPreset fillerPreset, List<MediaChapter> effectiveChapters, PlayoutItem playoutItem) |
||||||
|
{ |
||||||
|
if (effectiveChapters.Count == 0 || fillerPreset is null || string.IsNullOrWhiteSpace(fillerPreset.Expression)) |
||||||
|
{ |
||||||
|
return effectiveChapters; |
||||||
|
} |
||||||
|
|
||||||
|
var chapterPoints = effectiveChapters.Map(c => c.EndTime).SkipLast().ToList(); |
||||||
|
|
||||||
|
var newChapters = new List<MediaChapter>(); |
||||||
|
|
||||||
|
TimeSpan start = effectiveChapters.Select(c => c.StartTime).Min(); |
||||||
|
TimeSpan end = effectiveChapters.Select(c => c.EndTime).Max(); |
||||||
|
|
||||||
|
double lastFiller = start.TotalSeconds - 99999.0; |
||||||
|
double contentDuration = (playoutItem.FinishOffset - playoutItem.StartOffset).TotalSeconds; |
||||||
|
|
||||||
|
for (var index = 0; index < chapterPoints.Count; index++) |
||||||
|
{ |
||||||
|
TimeSpan chapterPoint = chapterPoints[index]; |
||||||
|
var expression = new Expression(fillerPreset.Expression); |
||||||
|
int chapterNum = index + 1; |
||||||
|
double sinceLastFiller = chapterPoint.TotalSeconds - lastFiller; |
||||||
|
expression.EvaluateParameter += (name, e) => |
||||||
|
{ |
||||||
|
e.Result = name switch |
||||||
|
{ |
||||||
|
"last_mid_filler" => sinceLastFiller, |
||||||
|
"total_points" => effectiveChapters.Count - 1, |
||||||
|
"total_duration" => contentDuration, |
||||||
|
"total_progress" => chapterPoint.TotalSeconds / end.TotalSeconds, |
||||||
|
"remaining_duration" => contentDuration - chapterPoint.TotalSeconds, |
||||||
|
"point" => chapterPoint.TotalSeconds, |
||||||
|
"num" => chapterNum, |
||||||
|
_ => e.Result |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
if (expression.Evaluate() as bool? == true) |
||||||
|
{ |
||||||
|
lastFiller = chapterPoint.TotalSeconds; |
||||||
|
newChapters.Add(effectiveChapters[index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (newChapters.Count > 0) |
||||||
|
{ |
||||||
|
newChapters[0].StartTime = start; |
||||||
|
|
||||||
|
TimeSpan currentTime = start; |
||||||
|
foreach (MediaChapter chapter in newChapters) |
||||||
|
{ |
||||||
|
chapter.StartTime = currentTime; |
||||||
|
currentTime = chapter.EndTime; |
||||||
|
} |
||||||
|
|
||||||
|
newChapters.Add(new MediaChapter { StartTime = currentTime, EndTime = end }); |
||||||
|
} |
||||||
|
|
||||||
|
return newChapters; |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@ |
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||||
|
|
||||||
|
#nullable disable |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.MySql.Migrations |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Add_FillerPresetExpression : Migration |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AddColumn<string>( |
||||||
|
name: "Expression", |
||||||
|
table: "FillerPreset", |
||||||
|
type: "longtext", |
||||||
|
nullable: true) |
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"); |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.DropColumn( |
||||||
|
name: "Expression", |
||||||
|
table: "FillerPreset"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@ |
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||||
|
|
||||||
|
#nullable disable |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.Sqlite.Migrations |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Add_FillerPresetExpression : Migration |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AddColumn<string>( |
||||||
|
name: "Expression", |
||||||
|
table: "FillerPreset", |
||||||
|
type: "TEXT", |
||||||
|
nullable: true); |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.DropColumn( |
||||||
|
name: "Expression", |
||||||
|
table: "FillerPreset"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue