diff --git a/FileFlowsScriptRepo.csproj b/FileFlowsScriptRepo.csproj index f400f8e..000888a 100644 --- a/FileFlowsScriptRepo.csproj +++ b/FileFlowsScriptRepo.csproj @@ -18,4 +18,9 @@ + + + + + diff --git a/Generators/RepoGenerator.cs b/Generators/RepoGenerator.cs index 60fdf37..fc7404c 100644 --- a/Generators/RepoGenerator.cs +++ b/Generators/RepoGenerator.cs @@ -18,7 +18,7 @@ public static void Run() repo.SystemScripts = GetScripts(Path.Combine(projDir, "Scripts/System"), ScriptType.System); repo.FlowScripts = GetScripts(Path.Combine(projDir, "Scripts/Flow"), ScriptType.Flow); repo.WebhookScripts = GetScripts(Path.Combine(projDir, "Scripts/Webhook"), ScriptType.Webhook); - repo.FunctionScripts = GetScripts(Path.Combine(projDir, "Scripts/Function"), ScriptType.Template); + repo.FunctionScripts = GetScripts(Path.Combine(projDir, "Scripts/Function"), ScriptType.Template, new [] { ".js", ".cs", ".bat", ".ps1", "sh"}); repo.FlowTemplates = GetTemplates(Path.Combine(projDir, "Templates/Flow"), community: false); repo.CommunityFlowTemplates = GetTemplates(Path.Combine(projDir, "Templates/Flow"), community: true); repo.LibraryTemplates = GetTemplates(Path.Combine(projDir, "Templates/Library")); @@ -41,13 +41,17 @@ public static void Run() Console.WriteLine("Done"); } - private static List GetScripts(string path, ScriptType type) + private static List GetScripts(string path, ScriptType type, string[] extensions = null) { + extensions ??= new string[] { ".js" }; List scripts = new List(); var rgxComments = new Regex(@"\/\*(\*)?(.*?)\*\/", RegexOptions.Singleline); var basePath = new DirectoryInfo(path); - foreach(var file in basePath.GetFiles("*.js", SearchOption.AllDirectories)) + foreach(var file in basePath.GetFiles("*.*", SearchOption.AllDirectories)) { + if (extensions.Contains(file.Extension.ToLowerInvariant()) == false) + continue; + string content = File.ReadAllText(file.FullName); var script = new RepositoryObject(); diff --git a/Scripts/Function/File/File - Greater Than 1GB.cs b/Scripts/Function/File/File - Greater Than 1GB.cs new file mode 100644 index 0000000..5310eac --- /dev/null +++ b/Scripts/Function/File/File - Greater Than 1GB.cs @@ -0,0 +1,16 @@ +/** + * Checks if a file is larger than 1 GB + * @revision 1 + * @outputs 2 + * @minimumVersion 24.08.1.3441 + */ + +if(Variables.TryGetValue("file.Size", out var oSize) == false || oSize is long size == false) +{ + Flow.FailureReason = "file.Size not set in variables"; + Logger.ELog(Flow.FailureReason); + return -1; +} +if(size > 1_000_000_000) + return 1; +return 2; \ No newline at end of file diff --git a/Scripts/Function/Video/Video - Bitrate Greater Than.cs b/Scripts/Function/Video/Video - Bitrate Greater Than.cs new file mode 100644 index 0000000..86fc27f --- /dev/null +++ b/Scripts/Function/Video/Video - Bitrate Greater Than.cs @@ -0,0 +1,57 @@ +/** + * Checks if a video files bitrate is greater than a specific bitrate + * @revision 1 + * @outputs 2 + * @minimumVersion 24.08.1.3441 + */ + +// check if the bitrate for a video is over a certain amount +var MAX_BITRATE = 3_000_000; // bitrate is 3,000 KBps + +if(Variables.TryGetValue("vi.VideoInfo", out var oVideoInfo) == false || oVideoInfo is FileFlows.VideoNodes.VideoInfo videoInfo == false) +{ + Logger.ILog("Failed to locate VideoInformation in variables"); + return -1; +} +Logger.ILog("Got video information."); + +var video = videoInfo.VideoStreams.FirstOrDefault(); +if(video == null) +{ + Logger.ILog("No video streams detected."); + return -1; +} + +// get the video stream +var bitrate = video.Bitrate; + +if(bitrate < 1) +{ + // video stream doesn't have bitrate information + // need to use the overall bitrate + var overall = videoInfo.Bitrate; + if(overall < 1) + return 0; // couldn't get overall bitrate either + + // overall bitrate includes all audio streams, so we try and subtract those + var calculated = overall; + if(videoInfo.AudioStreams.Count > 0) // check there are audio streams + { + foreach(var audio in videoInfo.AudioStreams) + { + if(audio.Bitrate > 0) + calculated -= audio.Bitrate; + else{ + // audio doesn't have bitrate either, so we just subtract 5% of the original bitrate + // this is a guess, but it should get us close + calculated -= (overall * 0.05f); + } + } + } + bitrate = calculated; +} + +// check if the bitrate is over the maximum bitrate +if(bitrate > MAX_BITRATE) + return 1; // it is, so call output 1 +return 2; // it isn't so call output 2 \ No newline at end of file diff --git a/Scripts/Function/Video/Video - Resolution.cs b/Scripts/Function/Video/Video - Resolution.cs new file mode 100644 index 0000000..fda64fd --- /dev/null +++ b/Scripts/Function/Video/Video - Resolution.cs @@ -0,0 +1,29 @@ +/** + * A switch statement for video resolution + * @revision 1 + * @outputs 4 + * @minimumVersion 24.08.1.3441 + */ + +// get the first video stream, likely the only one +if(Variables.TryGetValue("vi.VideoInfo", out var oVideoInfo) == false || oVideoInfo is FileFlows.VideoNodes.VideoInfo videoInfo == false) +{ + Logger.ILog("Failed to locate VideoInformation in variables"); + return -1; +} +Logger.ILog("Got video information."); +var video = videoInfo.VideoStreams.FirstOrDefault(); +if(video == null) +{ + Logger.ILog("No video streams detected."); + return -1; +} + +Logger.ILog("Video stream detected."); +if(video.Width > 3700) + return 1; // 4k +if(video.Width > 1800) + return 2; // 1080p +if(video.Width > 1200) + return 3; // 720p +return 4; // SD \ No newline at end of file