diff --git a/BasicNodes/BasicNodes.csproj b/BasicNodes/BasicNodes.csproj index 37855f83..fe1b3924 100644 Binary files a/BasicNodes/BasicNodes.csproj and b/BasicNodes/BasicNodes.csproj differ diff --git a/BasicNodes/BasicNodes.en.json b/BasicNodes/BasicNodes.en.json index 14a7f66c..b5cd2a47 100644 --- a/BasicNodes/BasicNodes.en.json +++ b/BasicNodes/BasicNodes.en.json @@ -30,6 +30,22 @@ "IncludePatterns-Help": "Optional, if set only files matching these patterns will be counted to see if the folder is empty. Any of these patterns can match." } }, + "Executor": { + "Description": "Execute the following process against the file.\nOutput 1: The process returned the success exit code\nOutput 2: The process return a non-successful exit code.", + "Fields": { + "FileName": "File Name", + "FileName-Help": "The name of the file to execute", + "Arguments": "Arguments", + "Arguments-Help": "The arguments to be passed to the process to execute", + "WorkingDirectory": "Working Directory", + "WorkingDirectory-Help": "The directory where the process will be executed from", + "SuccessCode": "Success Code", + "SuccessCode-Help": "The exit code of the process indicating the process was successful. Usually this should be 0.", + "Timeout": "Timeout", + "Timeout-Help": "How long the process can run for before being terminated. Use 0 for no timeout.", + "Timeout-Suffix": "seconds" + } + }, "FileExtension": { "Description": "Checks if the file has one of the configured extensions.\n\nOutput 1: Matches\nOutput 2: Does not match", "Fields": { diff --git a/BasicNodes/Tests/FileExtensionTests.cs b/BasicNodes/Tests/FileExtensionTests.cs index e39e1849..c7e1e7a2 100644 --- a/BasicNodes/Tests/FileExtensionTests.cs +++ b/BasicNodes/Tests/FileExtensionTests.cs @@ -13,8 +13,7 @@ namespace BasicNodes.Tests [TestInitialize] public void TestStarting() { - Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); - Args.Logger = new TestLogger(); + Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", new TestLogger());; } diff --git a/BasicNodes/Tests/FileSizeTests.cs b/BasicNodes/Tests/FileSizeTests.cs index 19522a27..58cd22fd 100644 --- a/BasicNodes/Tests/FileSizeTests.cs +++ b/BasicNodes/Tests/FileSizeTests.cs @@ -13,8 +13,7 @@ namespace BasicNodes.Tests [TestInitialize] public void TestStarting() { - Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); - Args.Logger = new TestLogger(); + Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", new TestLogger()); } diff --git a/BasicNodes/Tests/FunctionTests.cs b/BasicNodes/Tests/FunctionTests.cs index b298c1dd..d938fb16 100644 --- a/BasicNodes/Tests/FunctionTests.cs +++ b/BasicNodes/Tests/FunctionTests.cs @@ -13,8 +13,7 @@ namespace BasicNodes.Tests [TestInitialize] public void TestStarting() { - Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); - Args.Logger = new TestLogger(); + Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", new TestLogger()); } @@ -59,8 +58,7 @@ namespace BasicNodes.Tests { Function pm = new Function(); var logger = new TestLogger(); - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv"); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -77,8 +75,7 @@ return 0"; { Function pm = new Function(); var logger = new TestLogger(); - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv"); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -96,8 +93,7 @@ return 0"; { Function pm = new Function(); var logger = new TestLogger(); - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv"); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -115,8 +111,7 @@ return 0"; { Function pm = new Function(); var logger = new TestLogger(); - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv"); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, diff --git a/BasicNodes/Tests/PatternMatchTests.cs b/BasicNodes/Tests/PatternMatchTests.cs index 54477b3e..3a207fab 100644 --- a/BasicNodes/Tests/PatternMatchTests.cs +++ b/BasicNodes/Tests/PatternMatchTests.cs @@ -13,7 +13,7 @@ namespace BasicNodes.Tests { PatternMatch pm = new PatternMatch(); pm.Pattern = @"\.mkv$"; - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", new TestLogger()); args.SetWorkingFile($@"c:\temp\{Guid.NewGuid().ToString()}.mkv", dontDelete: true); var result = pm.Execute(args); @@ -25,7 +25,7 @@ namespace BasicNodes.Tests { PatternMatch pm = new PatternMatch(); pm.Pattern = @"\.mkv$"; - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.avi"); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.avi", new TestLogger()); args.SetWorkingFile($@"c:\temp\{Guid.NewGuid().ToString()}.avi", dontDelete: true); var result = pm.Execute(args); @@ -37,7 +37,7 @@ namespace BasicNodes.Tests { PatternMatch pm = new PatternMatch(); pm.Pattern = @"[-$"; - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.avi"); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.avi", new TestLogger()); args.SetWorkingFile($@"c:\temp\{Guid.NewGuid().ToString()}.avi", dontDelete: true); var result = pm.Execute(args); @@ -48,7 +48,7 @@ namespace BasicNodes.Tests { PatternMatch pm = new PatternMatch(); pm.Pattern = @"\-trailer"; - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile-TRAILER.avi"); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile-TRAILER.avi", new TestLogger()); args.SetWorkingFile($@"c:\temp\{Guid.NewGuid().ToString()}.avi", dontDelete: true); var result = pm.Execute(args); diff --git a/BasicNodes/Tests/PatternReplacerTests.cs b/BasicNodes/Tests/PatternReplacerTests.cs index 9966d180..8de63484 100644 --- a/BasicNodes/Tests/PatternReplacerTests.cs +++ b/BasicNodes/Tests/PatternReplacerTests.cs @@ -17,7 +17,7 @@ namespace BasicNodes.Tests new KeyValuePair("Seinfeld", "Batman") }; node.UnitTest = true; - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Seinfeld.mkv"); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Seinfeld.mkv", new TestLogger()); var result = node.Execute(args); Assert.AreEqual(1, result); @@ -34,7 +34,7 @@ namespace BasicNodes.Tests new KeyValuePair(@"0([1-9]+x[\d]+)", "$1"), }; node.UnitTest = true; - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Seinfeld S03E06.mkv"); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Seinfeld S03E06.mkv", new TestLogger()); var result = node.Execute(args); Assert.AreEqual(1, result); diff --git a/BasicNodes/Tests/RenamerTests.cs b/BasicNodes/Tests/RenamerTests.cs index 819fe7d7..ccf8779d 100644 --- a/BasicNodes/Tests/RenamerTests.cs +++ b/BasicNodes/Tests/RenamerTests.cs @@ -11,9 +11,8 @@ namespace BasicNodes.Tests [TestMethod] public void Renamer_Extension() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); var logger = new TestLogger(); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -36,9 +35,8 @@ namespace BasicNodes.Tests [TestMethod] public void Renamer_Extension_DoubleDot() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); var logger = new TestLogger(); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -62,9 +60,8 @@ namespace BasicNodes.Tests [TestMethod] public void Renamer_Empty_SquareBrackets() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); var logger = new TestLogger(); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -87,9 +84,8 @@ namespace BasicNodes.Tests [TestMethod] public void Renamer_Empty_RoundBrackets() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); var logger = new TestLogger(); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -111,9 +107,8 @@ namespace BasicNodes.Tests [TestMethod] public void Renamer_Empty_SquareBrackets_Extension() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); var logger = new TestLogger(); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Ghostbusters" }, @@ -137,9 +132,8 @@ namespace BasicNodes.Tests [TestMethod] public void Renamer_Colon() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv"); var logger = new TestLogger(); - args.Logger = logger; + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger); args.Variables = new Dictionary { { "miTitle", "Batman Unlimited: Mech vs Mutants" }, diff --git a/BasicNodes/Tools/Executor.cs b/BasicNodes/Tools/Executor.cs new file mode 100644 index 00000000..ce768184 --- /dev/null +++ b/BasicNodes/Tools/Executor.cs @@ -0,0 +1,70 @@ +namespace FileFlows.BasicNodes.File +{ + using System.ComponentModel; + using System.ComponentModel.DataAnnotations; + using System.Diagnostics; + using FileFlows.Plugin; + using FileFlows.Plugin.Attributes; + + public class Executor : Node + { + public override int Inputs => 1; + public override int Outputs => 2; + public override FlowElementType Type => FlowElementType.Process; + public override string Icon => "fas fa-terminal"; + + [Required] + [File(1)] + public string FileName { get; set; } + + [Required] + [TextVariable(2)] + public string Arguments { get; set; } + + [Folder(3)] + public string WorkingDirectory { get; set; } + + [Required] + [NumberInt(4)] + public int SuccessCode { get; set; } + + [NumberInt(5)] + public int Timeout { get; set; } + + private NodeParameters args; + + public override async Task Cancel() + { + args?.Process?.Cancel(); + } + + public override int Execute(NodeParameters args) + { + this.args = args; + string pArgs = args.ReplaceVariables(Arguments ?? string.Empty); + var task = args.Process.ExecuteShellCommand(new ExecuteArgs + { + Command = FileName, + Arguments = pArgs, + Timeout = Timeout, + WorkingDirectory = WorkingDirectory + }); + + task.Wait(); + + if(task.Result.Completed == false) + { + args.Logger?.ELog("Process failed to complete"); + return -1; + } + bool success = task.Result.ExitCode == this.SuccessCode; + if (success) + return 1; + else + { + args.Logger?.ILog("Unsuccesful exit code returned: " + task.Result.ExitCode); + return 2; + } + } + } +} \ No newline at end of file diff --git a/Builds/BasicNodes.zip b/Builds/BasicNodes.zip index a0b89639..fe48c971 100644 Binary files a/Builds/BasicNodes.zip and b/Builds/BasicNodes.zip differ diff --git a/Builds/MetaNodes.zip b/Builds/MetaNodes.zip index f0510d2a..a6ce5c35 100644 Binary files a/Builds/MetaNodes.zip and b/Builds/MetaNodes.zip differ diff --git a/Builds/VideoNodes.zip b/Builds/VideoNodes.zip index 0f2d3444..81c35693 100644 Binary files a/Builds/VideoNodes.zip and b/Builds/VideoNodes.zip differ diff --git a/MetaNodes/MetaNodes.csproj b/MetaNodes/MetaNodes.csproj index e0b575ad..ec03db6e 100644 Binary files a/MetaNodes/MetaNodes.csproj and b/MetaNodes/MetaNodes.csproj differ diff --git a/MetaNodes/Tests/TheMovieDb/MovieLookupTests.cs b/MetaNodes/Tests/TheMovieDb/MovieLookupTests.cs index 11d32d85..409b3a46 100644 --- a/MetaNodes/Tests/TheMovieDb/MovieLookupTests.cs +++ b/MetaNodes/Tests/TheMovieDb/MovieLookupTests.cs @@ -12,8 +12,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_File_Ghostbusters() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters 1984.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters 1984.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = false; @@ -32,8 +31,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_File_Ghostbusters2() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters 2.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters 2.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = false; @@ -52,8 +50,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_File_WithDots() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back.To.The.Future.2.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back.To.The.Future.2.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = false; @@ -72,8 +69,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_File_WithYear() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back.To.The.Future.1989.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back.To.The.Future.1989.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = false; @@ -92,8 +88,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_Folder_WithYear() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back To The Future (1989)\Jaws.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back To The Future (1989)\Jaws.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = true; @@ -112,8 +107,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_VariablesSet() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back To The Future (1989)\Jaws.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Back To The Future (1989)\Jaws.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = true; @@ -129,8 +123,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_NoMatchNoVariables() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = false; @@ -145,8 +138,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_ComplexFile() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Constantine.2005.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}\Constantine.2005.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Constantine.2005.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}\Constantine.2005.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = false; @@ -165,8 +157,7 @@ namespace MetaNodes.Tests.TheMovieDb [TestMethod] public void MovieLookupTests_WonderWoman() { - var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Wonder.Woman.1984.2020.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}\Wonder.Woman.1984.2020.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}.mkv"); - args.Logger = new TestLogger(); + var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Wonder.Woman.1984.2020.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}\Wonder.Woman.1984.2020.German.DL.AC3.1080p.BluRay.x265-Fun{{fdg$ERGESDG32fesdfgds}}.mkv", new TestLogger()); MovieLookup ml = new MovieLookup(); ml.UseFolderName = false; diff --git a/VideoNodes/VideoNodes.csproj b/VideoNodes/VideoNodes.csproj index 8366eeb8..d5aff337 100644 Binary files a/VideoNodes/VideoNodes.csproj and b/VideoNodes/VideoNodes.csproj differ diff --git a/plugins.json b/plugins.json index 98360adf..2acb3287 100644 --- a/plugins.json +++ b/plugins.json @@ -1,17 +1,17 @@ [ { "Name": "BasicNodes", - "Version": "0.0.1.23", + "Version": "0.0.1.24", "Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/BasicNodes.zip?raw=true" }, { "Name": "MetaNodes", - "Version": "0.0.1.23", + "Version": "0.0.1.24", "Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/MetaNodes.zip?raw=true" }, { "Name": "VideoNodes", - "Version": "0.0.1.23", + "Version": "0.0.1.24", "Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/VideoNodes.zip?raw=true" } ]