added validation to some nodes

This commit is contained in:
reven
2021-11-24 17:55:27 +13:00
parent 962fe7959c
commit 599ee1700e
20 changed files with 24 additions and 220 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@ TestStore/
.vs/FileFlowsPlugins/v17/.futdcache.v1
.vs/FileFlowsPlugins/DesignTimeBuild/.dtbcache.v2
.vs/FileFlowsPlugins/project-colors.json
/Plugin.pdb

Binary file not shown.

View File

@@ -1,6 +1,7 @@
namespace FileFlows.BasicNodes.File
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
@@ -13,6 +14,7 @@ namespace FileFlows.BasicNodes.File
private string _DestinationPath = string.Empty;
[Required]
[Folder(1)]
public string DestinationPath
{

View File

@@ -1,6 +1,7 @@
namespace FileFlows.BasicNodes.File
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
@@ -11,6 +12,7 @@ namespace FileFlows.BasicNodes.File
public override string Icon => "far fa-file-excel";
[StringArray(1)]
[Required]
public string[] Extensions { get; set; }
public override FlowElementType Type => FlowElementType.Logic;

View File

@@ -1,6 +1,7 @@
namespace FileFlows.BasicNodes.File
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
@@ -12,6 +13,7 @@ namespace FileFlows.BasicNodes.File
public override FlowElementType Type => FlowElementType.Process;
public override string Icon => "fas fa-file-export";
[Required]
[Folder(1)]
public string DestinationPath { get; set; }

View File

@@ -1,5 +1,6 @@
namespace FileFlows.BasicNodes.File
{
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
@@ -14,6 +15,7 @@
public override FlowElementType Type => FlowElementType.Process;
[Required]
[TextVariable(1)]
public string? Pattern
{

View File

@@ -7,6 +7,7 @@ namespace FileFlows.BasicNodes.Functions
using Jint.Native.Object;
using Jint;
using System.Text;
using System.ComponentModel.DataAnnotations;
public class Function : Node
{
@@ -15,9 +16,10 @@ namespace FileFlows.BasicNodes.Functions
public override string Icon => "fas fa-code";
[DefaultValue(1)]
[NumberIntAttribute(1)]
[NumberInt(1)]
public new int Outputs { get; set; }
[Required]
[DefaultValue("// VideoFile object contains info about the video file\n\n// return 0 to complete the flow.\n// return -1 to signal an error in the flow\n// return 1+ to indicate which output to process next\n\n return 0;")]
[Code(2)]
public string Code { get; set; }

View File

@@ -7,6 +7,7 @@ namespace FileFlows.BasicNodes.Functions
using Jint.Native.Object;
using Jint;
using System.Text;
using System.ComponentModel.DataAnnotations;
public class Log : Node
{
@@ -19,6 +20,7 @@ namespace FileFlows.BasicNodes.Functions
public LogType LogType { get; set; }
[TextArea(2)]
[Required]
public string Message { get; set; }
public override int Execute(NodeParameters args)
{

View File

@@ -1,6 +1,7 @@
namespace FileFlows.BasicNodes.Functions
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
@@ -13,6 +14,7 @@ namespace FileFlows.BasicNodes.Functions
[DefaultValue("")]
[Text(1)]
[Required]
public string Pattern { get; set; }
public override int Execute(NodeParameters args)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,7 +2,6 @@
namespace MetaNodes.Tests.TheMovieDb
{
using BasicNodes.Tests;
using DM.MovieApi.MovieDb.Movies;
using MetaNodes.TheMovieDb;
using Microsoft.VisualStudio.TestTools.UnitTesting;

View File

@@ -1,134 +0,0 @@
#if(DEBUG)
namespace MetaNodes.Tests.TheMovieDb
{
using BasicNodes.Tests;
using DM.MovieApi.MovieDb.Movies;
using MetaNodes.TheMovieDb;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class MovieMovieRenamerTests
{
[TestMethod]
public void MovieRenamerTests_File_TitleYearExt()
{
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters.mkv");
var logger = new TestLogger();
args.Logger = logger;
args.SetParameter(Globals.MOVIE_INFO, new MovieInfo
{
Title = "Back to the Future Part II",
ReleaseDate = new DateTime(1989, 5, 5)
});
MovieRenamer node = new MovieRenamer();
node.Pattern = "{Title} ({Year}).{ext}";
node.LogOnly = true;
var result = node.Execute(args);
Assert.AreEqual(1, result);
Assert.IsTrue(logger.Contains("Renaming file to: Back to the Future Part II (1989).mkv"));
}
[TestMethod]
public void MovieRenamerTests_File_TitleExt()
{
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters.mkv");
var logger = new TestLogger();
args.Logger = logger;
args.SetParameter(Globals.MOVIE_INFO, new MovieInfo
{
Title = "Back to the Future Part II",
ReleaseDate = new DateTime(1989, 5, 5)
});
MovieRenamer node = new MovieRenamer();
node.Pattern = "{Title}.{ext}";
node.LogOnly = true;
var result = node.Execute(args);
Assert.AreEqual(1, result);
Assert.IsTrue(logger.Contains("Renaming file to: Back to the Future Part II.mkv"));
}
[TestMethod]
public void MovieRenamerTests_Folder_TitleYear_Windows()
{
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters.mkv");
var logger = new TestLogger();
args.Logger = logger;
args.SetParameter(Globals.MOVIE_INFO, new MovieInfo
{
Title = "Back to the Future Part II",
ReleaseDate = new DateTime(1989, 5, 5)
});
MovieRenamer node = new MovieRenamer();
node.Pattern = @"{Title} ({Year})\{Title}.{ext}";
node.LogOnly = true;
var result = node.Execute(args);
Assert.AreEqual(1, result);
Assert.IsTrue(logger.Contains($"Renaming file to: Back to the Future Part II (1989){Path.DirectorySeparatorChar}Back to the Future Part II.mkv"));
}
[TestMethod]
public void MovieRenamerTests_Folder_TitleYear_Linux()
{
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\Ghostbusters.mkv");
var logger = new TestLogger();
args.Logger = logger;
args.SetParameter(Globals.MOVIE_INFO, new MovieInfo
{
Title = "Back to the Future Part II",
ReleaseDate = new DateTime(1989, 5, 5)
});
MovieRenamer node = new MovieRenamer();
node.Pattern = @"{Title} ({Year})/{Title}.{ext}";
node.LogOnly = true;
var result = node.Execute(args);
Assert.AreEqual(1, result);
Assert.IsTrue(logger.Contains($"Renaming file to: Back to the Future Part II (1989){Path.DirectorySeparatorChar}Back to the Future Part II.mkv"));
}
[TestMethod]
public void MovieRenamerTests_Folder_TitleYear_MoveActual()
{
string tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".mkv");
string path = new FileInfo(tempFile).DirectoryName;
File.WriteAllText(tempFile, "test");
var args = new FileFlows.Plugin.NodeParameters(tempFile);
var logger = new TestLogger();
args.Logger = logger;
args.SetParameter(Globals.MOVIE_INFO, new MovieInfo
{
Title = "Back to the Future Part II",
ReleaseDate = new DateTime(1989, 5, 5)
});
MovieRenamer node = new MovieRenamer();
node.Pattern = @"{Title} ({Year})/{Title}.{ext}";
var result = node.Execute(args);
Assert.AreEqual(1, result);
string expectedShort = $"Back to the Future Part II (1989){Path.DirectorySeparatorChar}Back to the Future Part II.mkv";
Assert.IsTrue(logger.Contains($"Renaming file to: " + expectedShort));
string expected = Path.Combine(path, expectedShort);
Assert.IsTrue(File.Exists(expected));
Directory.Delete(new FileInfo(expected).DirectoryName, true);
}
}
}
#endif

View File

@@ -1,81 +0,0 @@
namespace MetaNodes.TheMovieDb
{
using System.Text.RegularExpressions;
using DM.MovieApi;
using DM.MovieApi.ApiResponse;
using DM.MovieApi.MovieDb.Movies;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
public class MovieRenamer : Node
{
public override int Inputs => 1;
public override int Outputs => 1;
public override string Icon => "fas fa-font";
public override FlowElementType Type => FlowElementType.Process;
public string _Pattern = string.Empty;
[TextVariable(1)]
public string? Pattern
{
get => _Pattern;
set { _Pattern = value ?? ""; }
}
private string _DestinationPath = string.Empty;
[Folder(2)]
public string DestinationPath
{
get => _DestinationPath;
set { _DestinationPath = value ?? ""; }
}
[Boolean(3)]
public bool LogOnly { get; set; }
public override int Execute(NodeParameters args)
{
if(string.IsNullOrEmpty(Pattern))
{
args.Logger?.ELog("No pattern specified");
return -1;
}
var movieInfo = args.GetParameter<MovieInfo>(Globals.MOVIE_INFO);
if (movieInfo == null) {
args.Logger?.ELog("MovieInfo not found, you must execute the Movie Lookup node first");
return -1;
}
string newFile = Pattern;
// incase they set a linux path on windows or vice versa
newFile = newFile.Replace('\\', Path.DirectorySeparatorChar);
newFile = newFile.Replace('/', Path.DirectorySeparatorChar);
newFile = ReplaceVariable(newFile, "Year", movieInfo.ReleaseDate.Year.ToString());
newFile = ReplaceVariable(newFile, "Title", movieInfo.Title);
newFile = ReplaceVariable(newFile, "Extension", args.WorkingFile.Substring(args.WorkingFile.LastIndexOf(".")+1));
newFile = ReplaceVariable(newFile, "Ext", args.WorkingFile.Substring(args.WorkingFile.LastIndexOf(".") + 1));
string destFolder = DestinationPath;
if (string.IsNullOrEmpty(destFolder))
destFolder = new FileInfo(args.WorkingFile).Directory?.FullName ?? "";
var dest = new FileInfo(Path.Combine(destFolder, newFile));
args.Logger?.ILog("Renaming file to: " + (string.IsNullOrEmpty(DestinationPath) ? "" : DestinationPath + Path.DirectorySeparatorChar) + newFile);
if (LogOnly)
return 1;
return args.MoveFile(dest.FullName) ? 1 : -1;
}
private string ReplaceVariable(string input, string variable, string value)
{
return Regex.Replace(input, @"{" + Regex.Escape(variable) + @"}", value, RegexOptions.IgnoreCase);
}
}
}

View File

@@ -1,6 +1,7 @@
namespace FileFlows.VideoNodes
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
@@ -10,10 +11,12 @@ namespace FileFlows.VideoNodes
[DefaultValue("-i {WorkingFile} {TempDir}output.mkv")]
[TextArea(1)]
[Required]
public string CommandLine { get; set; }
[DefaultValue("mkv")]
[Text(2)]
[Required]
public string Extension { get; set; }
public override string Icon => "far fa-file-video";

View File

@@ -4,6 +4,7 @@ namespace FileFlows.VideoNodes
using System.ComponentModel;
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
using System.ComponentModel.DataAnnotations;
public class VideoCodec : VideoNode
{
@@ -12,6 +13,7 @@ namespace FileFlows.VideoNodes
public override FlowElementType Type => FlowElementType.Logic;
[StringArray(1)]
[Required]
public string[] Codecs { get; set; }
public override int Execute(NodeParameters args)

Binary file not shown.

View File

@@ -1,17 +1,17 @@
[
{
"Name": "BasicNodes",
"Version": "0.0.1.10",
"Version": "0.0.1.11",
"Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/BasicNodes.zip?raw=true"
},
{
"Name": "MetaNodes",
"Version": "0.0.1.10",
"Version": "0.0.1.11",
"Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/MetaNodes.zip?raw=true"
},
{
"Name": "VideoNodes",
"Version": "0.0.1.10",
"Version": "0.0.1.11",
"Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/VideoNodes.zip?raw=true"
}
]