diff --git a/BasicNodes/Functions/Function.cs b/BasicNodes/Functions/Function.cs index 73aeceb0..7b45869c 100644 --- a/BasicNodes/Functions/Function.cs +++ b/BasicNodes/Functions/Function.cs @@ -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 ExplodeVariables(Dictionary input) //{ // Dictionary result = new(); diff --git a/BasicNodes/Tests/FunctionTests.cs b/BasicNodes/Tests/FunctionTests.cs index 923377e8..b400f551 100644 --- a/BasicNodes/Tests/FunctionTests.cs +++ b/BasicNodes/Tests/FunctionTests.cs @@ -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); + } } } diff --git a/BasicNodes/Tools/Executor.cs b/BasicNodes/Tools/Executor.cs index 988a3962..f5b2fa6d 100644 --- a/BasicNodes/Tools/Executor.cs +++ b/BasicNodes/Tools/Executor.cs @@ -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; } } + + } } \ No newline at end of file diff --git a/VideoNodes/VideoNodes/SubtitleExtractor.cs b/VideoNodes/VideoNodes/SubtitleExtractor.cs index c014df15..0bb5d8e2 100644 --- a/VideoNodes/VideoNodes/SubtitleExtractor.cs +++ b/VideoNodes/VideoNodes/SubtitleExtractor.cs @@ -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)