mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-04 16:38:26 -06:00
updated Function to support variables, which needed dots removed from variable names
fixed some issues with renamer
This commit is contained in:
Binary file not shown.
@@ -69,7 +69,7 @@
|
||||
var dest = args.GetSafeName(Path.Combine(destFolder, newFile));
|
||||
|
||||
|
||||
args.Logger?.ILog("Renaming file to: " + dest.FullName.Substring(destFolder.Length+1));
|
||||
args.Logger?.ILog("Renaming file to: " + dest.FullName);
|
||||
|
||||
if (string.IsNullOrEmpty(CsvFile) == false)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace FileFlows.BasicNodes.Functions
|
||||
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;")]
|
||||
[DefaultValue("// Variables contain variables available to this node from previous nodes.\n// Logger lets you log messages to the flow output.\n\n// return 0 to complete the flow.\n// return -1 to signal an error in the flow\n// return 1+ to select which output node will be processed next\n\nif(Variables.FileSize === 0)\n\treturn -1;\n\nreturn 0;")]
|
||||
[Code(2)]
|
||||
public string Code { get; set; }
|
||||
|
||||
@@ -52,8 +52,7 @@ namespace FileFlows.BasicNodes.Functions
|
||||
options.MaxStatements(100);
|
||||
})
|
||||
.SetValue("Logger", args.Logger)
|
||||
.SetValue("FileSize", fileSize)
|
||||
;
|
||||
.SetValue("Variables", args.Variables);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -52,7 +52,87 @@ namespace BasicNodes.Tests
|
||||
Assert.AreEqual(i, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void Function_UseVariables()
|
||||
{
|
||||
Function pm = new Function();
|
||||
var logger = new TestLogger();
|
||||
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv");
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 }
|
||||
};
|
||||
pm.Code = @"
|
||||
if(Variables['miYear'] == 1984) return 2;
|
||||
return 0";
|
||||
var result = pm.Execute(args);
|
||||
Assert.AreEqual(2, result);
|
||||
}
|
||||
[TestMethod]
|
||||
public void Function_UseVariables_2()
|
||||
{
|
||||
Function pm = new Function();
|
||||
var logger = new TestLogger();
|
||||
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv");
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 }
|
||||
};
|
||||
pm.Code = @"
|
||||
if(Variables['miYear'] == 2000) return 2;
|
||||
return 0";
|
||||
var result = pm.Execute(args);
|
||||
Assert.AreEqual(0, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Function_UseVariables_DotNotation()
|
||||
{
|
||||
Function pm = new Function();
|
||||
var logger = new TestLogger();
|
||||
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv");
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 }
|
||||
};
|
||||
pm.Code = @"
|
||||
if(Variables.miYear == 1984) return 2;
|
||||
return 0";
|
||||
var result = pm.Execute(args);
|
||||
Assert.AreEqual(2, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Function_VariableUpdate()
|
||||
{
|
||||
Function pm = new Function();
|
||||
var logger = new TestLogger();
|
||||
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\sdfsdfdsvfdcxdsf.mkv");
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 }
|
||||
};
|
||||
pm.Code = @"
|
||||
Variables.NewItem = 1234;
|
||||
Variables.miYear = 2001;
|
||||
return 0";
|
||||
var result = pm.Execute(args);
|
||||
Assert.IsTrue(args.Variables.ContainsKey("NewItem"));
|
||||
Assert.AreEqual(1234d, args.Variables["NewItem"]);
|
||||
Assert.AreEqual(2001d, args.Variables["miYear"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -16,21 +16,21 @@ namespace BasicNodes.Tests
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "mi.Title", "Ghostbusters" },
|
||||
{ "mi.Year", 1984 },
|
||||
{ "vi.Resolution", "1080P" }
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 },
|
||||
{ "viResolution", "1080P" }
|
||||
};
|
||||
args.SetWorkingFile($@"c:\temp\{Guid.NewGuid()}.mkv", dontDelete: true);
|
||||
|
||||
|
||||
Renamer node = new Renamer();
|
||||
node.Pattern = @"{mi.Title} ({mi.Year})\{mi.Title} [{vi.Resolution}]{ext}";
|
||||
node.Pattern = @"{miTitle} ({miYear})\{miTitle} [{viResolution}]{ext}";
|
||||
node.LogOnly = true;
|
||||
|
||||
var result = node.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
string expectedShort = $"Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters [1080P].mkv";
|
||||
string expectedShort = $@"c:\temp\Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters [1080P].mkv";
|
||||
Assert.IsTrue(logger.Contains($"Renaming file to: " + expectedShort));
|
||||
}
|
||||
[TestMethod]
|
||||
@@ -41,21 +41,21 @@ namespace BasicNodes.Tests
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "mi.Title", "Ghostbusters" },
|
||||
{ "mi.Year", 1984 },
|
||||
{ "vi.Resolution", "1080P" }
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 },
|
||||
{ "viResolution", "1080P" }
|
||||
};
|
||||
args.SetWorkingFile($@"c:\temp\{Guid.NewGuid()}.mkv", dontDelete: true);
|
||||
|
||||
|
||||
Renamer node = new Renamer();
|
||||
node.Pattern = @"{mi.Title} ({mi.Year})\{mi.Title} [{vi.Resolution}].{ext}";
|
||||
node.Pattern = @"{miTitle} ({miYear})\{miTitle} [{viResolution}].{ext}";
|
||||
node.LogOnly = true;
|
||||
|
||||
var result = node.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
string expectedShort = $"Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters [1080P].mkv";
|
||||
string expectedShort = $@"c:\temp\Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters [1080P].mkv";
|
||||
Assert.IsTrue(logger.Contains($"Renaming file to: " + expectedShort));
|
||||
}
|
||||
|
||||
@@ -67,20 +67,20 @@ namespace BasicNodes.Tests
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "mi.Title", "Ghostbusters" },
|
||||
{ "mi.Year", 1984 }
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 }
|
||||
};
|
||||
args.SetWorkingFile($@"c:\temp\{Guid.NewGuid()}.mkv", dontDelete: true);
|
||||
|
||||
|
||||
Renamer node = new Renamer();
|
||||
node.Pattern = @"{mi.Title} ({mi.Year})\{mi.Title} [{vi.Resolution}] {mi.Year}.{ext}";
|
||||
node.Pattern = @"{miTitle} ({miYear})\{miTitle} [{viResolution}] {miYear}.{ext}";
|
||||
node.LogOnly = true;
|
||||
|
||||
var result = node.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
string expectedShort = $"Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters 1984.mkv";
|
||||
string expectedShort = $@"c:\temp\Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters 1984.mkv";
|
||||
Assert.IsTrue(logger.Contains($"Renaming file to: " + expectedShort));
|
||||
}
|
||||
|
||||
@@ -92,20 +92,20 @@ namespace BasicNodes.Tests
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "mi.Title", "Ghostbusters" },
|
||||
{ "vi.Resolution", "1080p" }
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "viResolution", "1080p" }
|
||||
};
|
||||
args.SetWorkingFile($@"c:\temp\{Guid.NewGuid()}.mkv", dontDelete: true);
|
||||
|
||||
|
||||
Renamer node = new Renamer();
|
||||
node.Pattern = @"{mi.Title} ({mi.Year})\{mi.Title} ({mi.Year}) {vi.Resolution!}.{ext}";
|
||||
node.Pattern = @"{miTitle} ({miYear})\{miTitle} ({miYear}) {viResolution!}.{ext}";
|
||||
node.LogOnly = true;
|
||||
|
||||
var result = node.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
string expectedShort = $"Ghostbusters{Path.DirectorySeparatorChar}Ghostbusters 1080P.mkv";
|
||||
string expectedShort = $@"c:\temp\Ghostbusters{Path.DirectorySeparatorChar}Ghostbusters 1080P.mkv";
|
||||
Assert.IsTrue(logger.Contains($"Renaming file to: " + expectedShort));
|
||||
}
|
||||
[TestMethod]
|
||||
@@ -116,20 +116,20 @@ namespace BasicNodes.Tests
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "mi.Title", "Ghostbusters" },
|
||||
{ "mi.Year", 1984 }
|
||||
{ "miTitle", "Ghostbusters" },
|
||||
{ "miYear", 1984 }
|
||||
};
|
||||
args.SetWorkingFile($@"c:\temp\{Guid.NewGuid()}.mkv", dontDelete: true);
|
||||
|
||||
|
||||
Renamer node = new Renamer();
|
||||
node.Pattern = @"{mi.Title} ({mi.Year})\{mi.Title} [{vi.Resolution}].{ext}";
|
||||
node.Pattern = @"{miTitle} ({miYear})\{miTitle} [{viResolution}].{ext}";
|
||||
node.LogOnly = true;
|
||||
|
||||
var result = node.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
string expectedShort = $"Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters.mkv";
|
||||
string expectedShort = $@"c:\temp\Ghostbusters (1984){Path.DirectorySeparatorChar}Ghostbusters.mkv";
|
||||
Assert.IsTrue(logger.Contains($"Renaming file to: " + expectedShort));
|
||||
}
|
||||
|
||||
@@ -142,20 +142,20 @@ namespace BasicNodes.Tests
|
||||
args.Logger = logger;
|
||||
args.Variables = new Dictionary<string, object>
|
||||
{
|
||||
{ "mi.Title", "Batman Unlimited: Mech vs Mutants" },
|
||||
{ "mi.Year", 2016 }
|
||||
{ "miTitle", "Batman Unlimited: Mech vs Mutants" },
|
||||
{ "miYear", 2016 }
|
||||
};
|
||||
args.SetWorkingFile($@"c:\temp\{Guid.NewGuid()}.mkv", dontDelete: true);
|
||||
|
||||
|
||||
Renamer node = new Renamer();
|
||||
node.Pattern = @"{mi.Title} ({mi.Year})\{mi.Title}.{ext}";
|
||||
node.Pattern = @"{miTitle} ({miYear})\{miTitle}.{ext}";
|
||||
node.LogOnly = true;
|
||||
|
||||
var result = node.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
string expectedShort = $"Batman Unlimited - Mech vs Mutants (2016){Path.DirectorySeparatorChar}Batman Unlimited - Mech vs Mutants.mkv";
|
||||
string expectedShort = $@"c:\temp\Batman Unlimited - Mech vs Mutants (2016){Path.DirectorySeparatorChar}Batman Unlimited - Mech vs Mutants.mkv";
|
||||
Assert.IsTrue(logger.Contains($"Renaming file to: " + expectedShort));
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -120,10 +120,10 @@ namespace MetaNodes.Tests.TheMovieDb
|
||||
|
||||
var result = ml.Execute(args);
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsTrue(args.Variables.ContainsKey("mi.Title"));
|
||||
Assert.IsTrue(args.Variables.ContainsKey("mi.Year"));
|
||||
Assert.AreEqual("Back to the Future Part II", args.Variables["mi.Title"]);
|
||||
Assert.AreEqual("1989", args.Variables["mi.Year"]);
|
||||
Assert.IsTrue(args.Variables.ContainsKey("miTitle"));
|
||||
Assert.IsTrue(args.Variables.ContainsKey("miYear"));
|
||||
Assert.AreEqual("Back to the Future Part II", args.Variables["miTitle"]);
|
||||
Assert.AreEqual(1989, args.Variables["miYear"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -137,8 +137,8 @@ namespace MetaNodes.Tests.TheMovieDb
|
||||
|
||||
var result = ml.Execute(args);
|
||||
Assert.AreEqual(2, result);
|
||||
Assert.IsFalse(args.Variables.ContainsKey("mi.Title"));
|
||||
Assert.IsFalse(args.Variables.ContainsKey("mi.Year"));
|
||||
Assert.IsFalse(args.Variables.ContainsKey("miTitle"));
|
||||
Assert.IsFalse(args.Variables.ContainsKey("miYear"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
{
|
||||
_Variables = new Dictionary<string, object>()
|
||||
{
|
||||
{ "mi.Title", "Batman Begins" },
|
||||
{ "mi.Year", 2005 }
|
||||
{ "miTitle", "Batman Begins" },
|
||||
{ "miYear", 2005 }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@
|
||||
|
||||
args.SetParameter(Globals.MOVIE_INFO, result);
|
||||
|
||||
Variables["mi.Title"] = result.Title;
|
||||
Variables["mi.Year"] = result.ReleaseDate.Year.ToString();
|
||||
Variables["miTitle"] = result.Title;
|
||||
Variables["miYear"] = result.ReleaseDate.Year;
|
||||
|
||||
args.UpdateVariables(Variables);
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ namespace FileFlows.VideoNodes
|
||||
{
|
||||
_Variables = new Dictionary<string, object>()
|
||||
{
|
||||
{ "vi.VideoCodec", "hevc" },
|
||||
{ "vi.AudioCodec", "ac3" },
|
||||
{ "vi.AudioCodecs", "ac3,aac"},
|
||||
{ "vi.AudioLanguage", "eng" },
|
||||
{ "vi.AudioLanguages", "eng, mao" },
|
||||
{ "vi.Resolution", "1080p" },
|
||||
{ "viVideoCodec", "hevc" },
|
||||
{ "viAudioCodec", "ac3" },
|
||||
{ "viAudioCodecs", "ac3,aac"},
|
||||
{ "viAudioLanguage", "eng" },
|
||||
{ "viAudioLanguages", "eng, mao" },
|
||||
{ "viResolution", "1080p" },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -72,28 +72,30 @@ namespace FileFlows.VideoNodes
|
||||
else
|
||||
args.Parameters.Add(VIDEO_INFO, videoInfo);
|
||||
|
||||
variables.AddOrUpdate("vi.VideoCodec", videoInfo.VideoStreams[0].Codec);
|
||||
variables.AddOrUpdate("viVideoCodec", videoInfo.VideoStreams[0].Codec);
|
||||
if (videoInfo.AudioStreams?.Any() == true)
|
||||
{
|
||||
;
|
||||
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec))
|
||||
Variables.AddOrUpdate("vi.AudioCodec", videoInfo.AudioStreams[0].Codec);
|
||||
Variables.AddOrUpdate("viAudioCodec", videoInfo.AudioStreams[0].Codec);
|
||||
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec))
|
||||
Variables.AddOrUpdate("viAudioChannels", videoInfo.AudioStreams[0].Channels);
|
||||
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Language))
|
||||
Variables.AddOrUpdate("vi.AudioLanguage", videoInfo.AudioStreams[0].Language);
|
||||
Variables.AddOrUpdate("vi.AudioCodecs", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
Variables.AddOrUpdate("vi.AudioLanguages", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
Variables.AddOrUpdate("viAudioLanguage", videoInfo.AudioStreams[0].Language);
|
||||
Variables.AddOrUpdate("viAudioCodecs", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
Variables.AddOrUpdate("viAudioLanguages", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
}
|
||||
|
||||
if (videoInfo.VideoStreams[0].Width == 1920)
|
||||
Variables.AddOrUpdate("vi.Resolution", "1080");
|
||||
Variables.AddOrUpdate("viResolution", "1080");
|
||||
else if (videoInfo.VideoStreams[0].Width == 3840)
|
||||
Variables.AddOrUpdate("vi.Resolution", "4l");
|
||||
Variables.AddOrUpdate("viResolution", "4l");
|
||||
else if (videoInfo.VideoStreams[0].Width == 1280)
|
||||
Variables.AddOrUpdate("vi.Resolution", "720p");
|
||||
Variables.AddOrUpdate("viResolution", "720p");
|
||||
else if (videoInfo.VideoStreams[0].Width < 1280)
|
||||
Variables.AddOrUpdate("vi.Resolution", "SD");
|
||||
Variables.AddOrUpdate("viResolution", "SD");
|
||||
else
|
||||
Variables.AddOrUpdate("vi.Resolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height);
|
||||
Variables.AddOrUpdate("viResolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height);
|
||||
|
||||
args.UpdateVariables(variables);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,17 +1,17 @@
|
||||
[
|
||||
{
|
||||
"Name": "BasicNodes",
|
||||
"Version": "0.0.1.12",
|
||||
"Version": "0.0.1.13",
|
||||
"Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/BasicNodes.zip?raw=true"
|
||||
},
|
||||
{
|
||||
"Name": "MetaNodes",
|
||||
"Version": "0.0.1.12",
|
||||
"Version": "0.0.1.13",
|
||||
"Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/MetaNodes.zip?raw=true"
|
||||
},
|
||||
{
|
||||
"Name": "VideoNodes",
|
||||
"Version": "0.0.1.12",
|
||||
"Version": "0.0.1.13",
|
||||
"Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/VideoNodes.zip?raw=true"
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user