mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-21 04:10:02 -06:00
FF-1680: New flow elements for file/folder dates
This commit is contained in:
@@ -69,26 +69,6 @@ namespace FileFlows.AudioNodes
|
||||
if (ReadAudioFileInfo(args, ffmpegExe, ffprobe, LocalWorkingFile))
|
||||
return 1;
|
||||
return -1;
|
||||
|
||||
// var AudioInfo = GetAudioInfo(args);
|
||||
// if (AudioInfo.Failed(out string error))
|
||||
// {
|
||||
// args.FailureReason = error;
|
||||
// args.Logger?.ELog(error);
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// if (string.IsNullOrEmpty(AudioInfo.Value.Codec) == false)
|
||||
// args.RecordStatistic("CODEC", AudioInfo.Value.Codec);
|
||||
//
|
||||
// string container = FileHelper.GetExtension(args.FileName).ToUpperInvariant().TrimStart('.');
|
||||
// if (string.IsNullOrEmpty(container) == false)
|
||||
// {
|
||||
// args.Logger?.ILog("Audio Container: " + container);
|
||||
// args.RecordStatistic("AUDIO_CONTAINER", container);
|
||||
// }
|
||||
//
|
||||
// return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
157
BasicNodes/File/DirectoryDateCompare.cs
Normal file
157
BasicNodes/File/DirectoryDateCompare.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
using FileFlows.Plugin.Helpers;
|
||||
using FileFlows.Plugin.Models;
|
||||
|
||||
namespace FileFlows.BasicNodes.File;
|
||||
|
||||
/// <summary>
|
||||
/// Flow element that compares if a Directory is older than the given period
|
||||
/// </summary>
|
||||
public class DirectoryDateCompare : Node
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override int Inputs => 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Outputs => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override FlowElementType Type => FlowElementType.Logic;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Icon => "fas fa-calendar";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/directory-date-compare";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the folder to check
|
||||
/// Leave blank to test the working file
|
||||
/// </summary>
|
||||
[TextVariable(1)]
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Date
|
||||
/// </summary>
|
||||
[Select(nameof(DateOptions), 2)]
|
||||
public int Date { get; set; }
|
||||
|
||||
private static List<ListOption> _DateOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date options to show in the UI
|
||||
/// </summary>
|
||||
public static List<ListOption> DateOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DateOptions == null)
|
||||
{
|
||||
_DateOptions = new List<ListOption>
|
||||
{
|
||||
new() { Label = "Date Created", Value = 0 },
|
||||
new() { Label = "Date Modified", Value = 1 }
|
||||
};
|
||||
}
|
||||
|
||||
return _DateOptions;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date comparison mode
|
||||
/// </summary>
|
||||
[DateCompare(3)]
|
||||
public DateCompareModel DateComparision { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
string path = args.ReplaceVariables(Path ?? string.Empty, true)?.EmptyAsNull() ?? args.WorkingFile;
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
args.FailureReason = "Path not set";
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (args.FileService.FileExists(path))
|
||||
path = FileHelper.GetDirectory(path);
|
||||
|
||||
var result = Date == 0
|
||||
? args.FileService.DirectoryCreationTimeUtc(path)
|
||||
: args.FileService.DirectoryLastWriteTimeUtc(path);
|
||||
|
||||
if (result.Failed(out var error))
|
||||
{
|
||||
args.FailureReason = error;
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
var date = result.Value;
|
||||
args.Logger?.ILog($"Mode: {(Date == 1 ? "Last Write Time" : "Date Created")}");
|
||||
args.Logger?.ILog($"Date: {date:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
|
||||
if (DateComparision == null)
|
||||
{
|
||||
args.FailureReason = "Comparison is null";
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
args.Logger?.ILog($"Comparison: {DateComparision.Comparison}");
|
||||
if (DateComparision.Comparison == DateCompareMode.Any)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var date1 = DateComparision.Comparison is DateCompareMode.After or DateCompareMode.Before
|
||||
? DateComparision.DateValue
|
||||
: now.AddMinutes(-DateComparision.Value1);
|
||||
|
||||
if (DateComparision.Comparison is DateCompareMode.Before or DateCompareMode.LessThan)
|
||||
{
|
||||
if (date <= date1)
|
||||
{
|
||||
args.Logger?.ILog($"Date is before: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 1;
|
||||
}
|
||||
|
||||
args.Logger?.ILog($"Date is not before: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (DateComparision.Comparison is DateCompareMode.After or DateCompareMode.GreaterThan)
|
||||
{
|
||||
if (date > date1)
|
||||
{
|
||||
args.Logger?.ILog($"Date is after: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 1;
|
||||
}
|
||||
|
||||
args.Logger?.ILog($"Date is not after: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// then it must be a between or not between
|
||||
var minutes = now.Subtract(date).TotalMinutes;
|
||||
int low = Math.Min(DateComparision.Value1, DateComparision.Value2);
|
||||
int high = Math.Max(DateComparision.Value1, DateComparision.Value2);
|
||||
bool isBetween = minutes >= low && minutes <= high;
|
||||
args.Logger?.ILog(
|
||||
$"Date is {(isBetween ? "" : "not ")}between {low} minutes and {high} minutes");
|
||||
|
||||
if (DateComparision.Comparison is DateCompareMode.Between)
|
||||
{
|
||||
return isBetween ? 1 : 2;
|
||||
}
|
||||
|
||||
// not between
|
||||
return isBetween ? 2 : 1;
|
||||
}
|
||||
|
||||
}
|
||||
153
BasicNodes/File/FileDateCompare.cs
Normal file
153
BasicNodes/File/FileDateCompare.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
using FileFlows.Plugin.Models;
|
||||
|
||||
namespace FileFlows.BasicNodes.File;
|
||||
|
||||
/// <summary>
|
||||
/// Flow element that compares if a file is older than the given period
|
||||
/// </summary>
|
||||
public class FileDateCompare : Node
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override int Inputs => 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Outputs => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override FlowElementType Type => FlowElementType.Logic;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Icon => "fas fa-calendar";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/file-date-compare";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the file to check
|
||||
/// Leave blank to test the working file
|
||||
/// </summary>
|
||||
[TextVariable(1)]
|
||||
public string FileName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Date
|
||||
/// </summary>
|
||||
[Select(nameof(DateOptions), 2)]
|
||||
public int Date { get; set; }
|
||||
|
||||
private static List<ListOption> _DateOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date options to show in the UI
|
||||
/// </summary>
|
||||
public static List<ListOption> DateOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DateOptions == null)
|
||||
{
|
||||
_DateOptions = new List<ListOption>
|
||||
{
|
||||
new() { Label = "Date Created", Value = 0 },
|
||||
new() { Label = "Date Modified", Value = 1 }
|
||||
};
|
||||
}
|
||||
|
||||
return _DateOptions;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date comparison mode
|
||||
/// </summary>
|
||||
[DateCompare(3)]
|
||||
public DateCompareModel DateComparision { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
string file = args.ReplaceVariables(FileName ?? string.Empty, true)?.EmptyAsNull() ?? args.WorkingFile;
|
||||
if (string.IsNullOrWhiteSpace(file))
|
||||
{
|
||||
args.FailureReason = "FileName not set";
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
var result = Date == 0
|
||||
? args.FileService.FileCreationTimeUtc(file)
|
||||
: args.FileService.FileLastWriteTimeUtc(file);
|
||||
|
||||
if (result.Failed(out var error))
|
||||
{
|
||||
args.FailureReason = error;
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
var date = result.Value;
|
||||
args.Logger?.ILog($"Mode: {(Date == 1 ? "Last Write Time" : "Date Created")}");
|
||||
args.Logger?.ILog($"Date: {date:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
|
||||
if (DateComparision == null)
|
||||
{
|
||||
args.FailureReason = "Comparison is null";
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
args.Logger?.ILog($"Comparison: {DateComparision.Comparison}");
|
||||
if (DateComparision.Comparison == DateCompareMode.Any)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var date1 = DateComparision.Comparison is DateCompareMode.After or DateCompareMode.Before
|
||||
? DateComparision.DateValue
|
||||
: now.AddMinutes(-DateComparision.Value1);
|
||||
|
||||
if (DateComparision.Comparison is DateCompareMode.Before or DateCompareMode.LessThan)
|
||||
{
|
||||
if (date <= date1)
|
||||
{
|
||||
args.Logger?.ILog($"Date is before: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 1;
|
||||
}
|
||||
|
||||
args.Logger?.ILog($"Date is not before: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (DateComparision.Comparison is DateCompareMode.After or DateCompareMode.GreaterThan)
|
||||
{
|
||||
if (date > date1)
|
||||
{
|
||||
args.Logger?.ILog($"Date is after: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 1;
|
||||
}
|
||||
|
||||
args.Logger?.ILog($"Date is not after: {date1:yyyy-MM-ddTHH:mm:ss}Z");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// then it must be a between or not between
|
||||
var minutes = now.Subtract(date).TotalMinutes;
|
||||
int low = Math.Min(DateComparision.Value1, DateComparision.Value2);
|
||||
int high = Math.Max(DateComparision.Value1, DateComparision.Value2);
|
||||
bool isBetween = minutes >= low && minutes <= high;
|
||||
args.Logger?.ILog(
|
||||
$"Date is {(isBetween ? "" : "not ")}between {low} minutes and {high} minutes");
|
||||
|
||||
if (DateComparision.Comparison is DateCompareMode.Between)
|
||||
{
|
||||
return isBetween ? 1 : 2;
|
||||
}
|
||||
|
||||
// not between
|
||||
return isBetween ? 2 : 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -82,6 +82,32 @@
|
||||
"OutputErrorVariable-Help": "An optional variable name to store the process error output into"
|
||||
}
|
||||
},
|
||||
"DirectoryDateCompare": {
|
||||
"Description": "Checks if the directory creation or last write time matches the specified date constraint.",
|
||||
"Outputs": {
|
||||
"1": "Matches the date constraint.",
|
||||
"2": "Does not match the date constraint."
|
||||
},
|
||||
"Fields": {
|
||||
"Path": "Path",
|
||||
"Path-Help": "The path to the file to check. Leave empty to check the current working file.\nIf a file is specified the directory containing the file will be checked.",
|
||||
"Date": "Date",
|
||||
"DateComparision": "Comparision"
|
||||
}
|
||||
},
|
||||
"FileDateCompare": {
|
||||
"Description": "Checks if the file creation or last write time matches the specified date constraint.",
|
||||
"Outputs": {
|
||||
"1": "Matches the date constraint.",
|
||||
"2": "Does not match the date constraint."
|
||||
},
|
||||
"Fields": {
|
||||
"FileName": "File Name",
|
||||
"FileName-Help": "The file to check. Leave empty to check the current working file.",
|
||||
"Date": "Date",
|
||||
"DateComparision": "Comparision"
|
||||
}
|
||||
},
|
||||
"FileExtension": {
|
||||
"Description": "Checks if the file has one of the configured extensions.\n\nOutput 1: Matches\nOutput 2: Does not match",
|
||||
"Outputs": {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user