added options to function node

This commit is contained in:
reven
2022-01-09 15:38:47 +13:00
parent cfabf2421c
commit bef561830e
4 changed files with 86 additions and 3 deletions

View File

@@ -28,8 +28,12 @@ namespace FileFlows.BasicNodes.Functions
public string Code { get; set; }
delegate void LogDelegate(params object[] values);
private NodeParameters NodeParameters;
public override int Execute(NodeParameters args)
{
NodeParameters = args;
if (string.IsNullOrEmpty(Code))
return -1; // no code, flow cannot continue doesnt know what to do
@@ -63,7 +67,8 @@ namespace FileFlows.BasicNodes.Functions
})
.SetValue("Logger", args.Logger)
.SetValue("Variables", args.Variables)
.SetValue("Flow", args);
.SetValue("Flow", args)
.SetValue("Process", Process);
try
{
@@ -77,6 +82,13 @@ namespace FileFlows.BasicNodes.Functions
}
}
public ProcessResult Process(ExecuteArgs args)
{
var result = NodeParameters.Process.ExecuteShellCommand(args).Result;
return result;
}
//private Dictionary<string, object> ExplodeVariables(Dictionary<string, object> input)
//{
// Dictionary<string, object> result = new();

View File

@@ -186,6 +186,68 @@ return 1";
var result = pm.Execute(args);
Assert.IsTrue(result > 0);
}
[TestMethod]
public void Function_Flow_Execute()
{
Function pm = new Function();
var logger = new TestLogger();
var args = new FileFlows.Plugin.NodeParameters(@"D:\videos\unprocessed\The IT Crowd - 2x04 - The Dinner Party - No English.mkv", logger, false, string.Empty);
pm.Code = @"
let result = Flow.Execute({command:'c:\\utils\\ffmpeg\\ffmpeg.exe', argumentList: ['-i', Variables.file.FullName]});
Logger.ILog('ExitCode: ' + result.exitCode);
Logger.ILog('completed: ' + result.completed);
Logger.ILog('standardOutput: ' + result.standardOutput);
if(!result.standardOutput || result.standardOutput.length < 1)
return 3;
if(result.exitCode === 1)
return 2;
return 0;
;";
var result = pm.Execute(args);
Assert.AreEqual(2, result);
}
[TestMethod]
public void Function_Flow_ExecuteFfmpeg()
{
Function pm = new Function();
var logger = new TestLogger();
var args = new FileFlows.Plugin.NodeParameters(@"D:\videos\unprocessed\The IT Crowd - 2x04 - The Dinner Party - No English.mkv", logger, false, string.Empty);
args.GetToolPath = (string name) => @"C:\utils\ffmpeg\ffmpeg.exe";
args.TempPath = @"D:\videos\temp";
pm.Code = @"
let output = Flow.TempPath + '/' + Flow.NewGuid() + '.mkv';
let ffmpeg = Flow.GetToolPath('ffmpeg');
let process = Flow.Execute({
command: ffmpeg,
argumentList: [
'-i',
Variables.file.FullName,
'-c:v',
'libx265',
'-c:a',
'copy',
output
]
});
if(process.standardOutput)
Logger.ILog('Standard output: ' + process.standardOutput);
if(process.starndardError)
Logger.ILog('Standard error: ' + process.starndardError);
if(process.exitCode !== 0){
Logger.ELog('Failed processing ffmpeg: ' + process.exitCode);
return -1;
}
Flow.SetWorkingFile(output);
return 1;
;";
var result = pm.Execute(args);
Assert.AreEqual(1, result);
}
}
}

View File

@@ -3,6 +3,7 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
@@ -48,7 +49,6 @@
{
args?.Process?.Cancel();
}
public override int Execute(NodeParameters args)
{
this.args = args;
@@ -91,5 +91,7 @@
return 2;
}
}
}
}

View File

@@ -63,7 +63,14 @@
var result = args.Process.ExecuteShellCommand(new ExecuteArgs
{
Command = ffmpegExe,
Arguments = $"-i \"{args.WorkingFile}\" -map \"0:s:{subTrack.TypeIndex}\" -map \"-0:v\" -map \"-0:a\" \"{OutputFile}\""
ArgumentList = new []
{
"-i", args.WorkingFile,
"-map", $"0:s:{subTrack.TypeIndex}",
"-map", "-0:v",
"-map", "-0:a",
OutputFile
}
}).Result;
if (result.ExitCode == 0)