mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.4 KiB
76 lines
2.4 KiB
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Interfaces.Metadata; |
|
using ErsatzTV.Core.Interfaces.Scheduling; |
|
using ErsatzTV.Core.Scheduling.ScriptedScheduling.Modules; |
|
using IronPython.Hosting; |
|
using IronPython.Runtime; |
|
using Microsoft.Extensions.Logging; |
|
|
|
namespace ErsatzTV.Core.Scheduling.ScriptedScheduling; |
|
|
|
public class ScriptedPlayoutBuilder( |
|
//IConfigElementRepository configElementRepository, |
|
//IMediaCollectionRepository mediaCollectionRepository, |
|
ILocalFileSystem localFileSystem, |
|
ILogger<ScriptedPlayoutBuilder> logger) |
|
: IScriptedPlayoutBuilder |
|
{ |
|
public async Task<PlayoutBuildResult> Build( |
|
DateTimeOffset start, |
|
Playout playout, |
|
PlayoutReferenceData referenceData, |
|
PlayoutBuildMode mode, |
|
CancellationToken cancellationToken) |
|
{ |
|
await Task.Delay(10, cancellationToken); |
|
|
|
var result = PlayoutBuildResult.Empty; |
|
|
|
if (!localFileSystem.FileExists(playout.ScheduleFile)) |
|
{ |
|
logger.LogError("Cannot build scripted playout; schedule file {File} does not exist", playout.ScheduleFile); |
|
return result; |
|
} |
|
|
|
logger.LogInformation("Building scripted playout..."); |
|
|
|
//int daysToBuild = await GetDaysToBuild(); |
|
//DateTimeOffset finish = start.AddDays(daysToBuild); |
|
|
|
//var enumeratorCache = new EnumeratorCache(mediaCollectionRepository, logger); |
|
|
|
// apply all history??? |
|
|
|
try |
|
{ |
|
var engine = Python.CreateEngine(); |
|
var scope = engine.CreateScope(); |
|
|
|
var sys = engine.GetSysModule(); |
|
var modules = (PythonDictionary)sys.GetVariable("modules"); |
|
|
|
var types = engine.ImportModule("types"); |
|
dynamic moduleType = types.GetVariable("ModuleType"); |
|
|
|
dynamic ersatztv = engine.Operations.Invoke(moduleType, "ersatztv"); |
|
modules["ersatztv"] = ersatztv; |
|
|
|
var contentModule = new ContentModule(); |
|
engine.Operations.SetMember(ersatztv, "content", contentModule); |
|
|
|
engine.ExecuteFile(playout.ScheduleFile, scope); |
|
} |
|
catch (Exception ex) |
|
{ |
|
logger.LogError(ex, "Unexpected error building scripted playout"); |
|
throw; |
|
} |
|
|
|
return result; |
|
} |
|
|
|
// private async Task<int> GetDaysToBuild() => |
|
// await configElementRepository |
|
// .GetValue<int>(ConfigElementKey.PlayoutDaysToBuild) |
|
// .IfNoneAsync(2); |
|
}
|
|
|