diff --git a/BasicNodes/Functions/Matches.cs b/BasicNodes/Functions/Matches.cs
index 524d9c8e..6298f942 100644
--- a/BasicNodes/Functions/Matches.cs
+++ b/BasicNodes/Functions/Matches.cs
@@ -3,6 +3,7 @@ using FileFlows.Plugin.Attributes;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using FileFlows.BasicNodes.Helpers;
+using FileFlows.Plugin.Helpers;
namespace FileFlows.BasicNodes.Functions;
@@ -83,7 +84,7 @@ public class Matches : Node
if (MathHelper.IsMathOperation(match.Value))
{
- if (MathHelper.IsTrue(strValue, match.Value))
+ if (MathHelper.IsTrue(match.Value, strValue))
{
args.Logger?.ILog($"Match found '{match.Value}' = {strValue}");
return output;
diff --git a/BasicNodes/Helpers/MathHelper.cs b/BasicNodes/Helpers/MathHelper.cs
index 88e00ba5..f20ea268 100644
--- a/BasicNodes/Helpers/MathHelper.cs
+++ b/BasicNodes/Helpers/MathHelper.cs
@@ -1,166 +1,166 @@
-using System.Globalization;
-
-namespace FileFlows.BasicNodes.Helpers;
-
-///
-/// Helper for math operations
-///
-public class MathHelper
-{
- ///
- /// Checks if the comparison string represents a mathematical operation.
- ///
- /// The comparison string to check.
- /// True if the comparison is a mathematical operation, otherwise false.
- public static bool IsMathOperation(string comparison)
- {
- // Check if the comparison string starts with <=, <, >, >=, ==, or =
- return new[] { "<=", "<", ">", ">=", "==", "=" }.Any(comparison.StartsWith);
- }
-
-
- ///
- /// Tests if a math operation is true
- ///
- /// The value to apply the operation to.
- /// The operation string representing the mathematical operation.
- /// True if the mathematical operation is successful, otherwise false.
- public static bool IsTrue(string value, string operation)
- {
- // This is a basic example; you may need to handle different operators
- switch (operation[..2])
- {
- case "<=":
- return Convert.ToDouble(value) <= Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()));
- case ">=":
- return Convert.ToDouble(value) >= Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()));
- case "==":
- return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()))) < 0.05f;
- case "!=":
- case "<>":
- return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()))) > 0.05f;
- }
-
- switch (operation[..1])
- {
- case "<":
- return Convert.ToDouble(value) < Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim()));
- case ">":
- return Convert.ToDouble(value) > Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim()));
- case "=":
- return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim()))) < 0.05f;
- }
-
- return false;
- }
-
- ///
- /// Adjusts the comparison string by handling common mistakes in units and converting them into full numbers.
- ///
- /// The original comparison string to be adjusted.
- /// The adjusted comparison string with corrected units or the original comparison if no adjustments are made.
- private static string AdjustComparisonValue(string comparisonValue)
- {
- if (string.IsNullOrWhiteSpace(comparisonValue))
- return string.Empty;
-
- string adjustedComparison = comparisonValue.ToLower().Trim();
-
- // Handle common mistakes in units
- if (adjustedComparison.EndsWith("mbps"))
- {
- // Make an educated guess for Mbps to kbps conversion
- return adjustedComparison[..^4] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000)
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("kbps"))
- {
- // Make an educated guess for kbps to bps conversion
- return adjustedComparison[..^4] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000)
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("kb"))
- {
- return adjustedComparison[..^2] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000 )
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("mb"))
- {
- return adjustedComparison[..^2] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000 )
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("gb"))
- {
- return adjustedComparison[..^2] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000 )
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("tb"))
- {
- return adjustedComparison[..^2] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000_000)
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
-
- if (adjustedComparison.EndsWith("kib"))
- {
- return adjustedComparison[..^3] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_024 )
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("mib"))
- {
- return adjustedComparison[..^3] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_048_576 )
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("gib"))
- {
- return adjustedComparison[..^3] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_099_511_627_776 )
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- if (adjustedComparison.EndsWith("tib"))
- {
- return adjustedComparison[..^3] switch
- {
- { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000_000)
- .ToString(CultureInfo.InvariantCulture),
- _ => comparisonValue
- };
- }
- return comparisonValue;
- }
-
-}
\ No newline at end of file
+// using System.Globalization;
+//
+// namespace FileFlows.BasicNodes.Helpers;
+//
+// ///
+// /// Helper for math operations
+// ///
+// public class MathHelper
+// {
+// ///
+// /// Checks if the comparison string represents a mathematical operation.
+// ///
+// /// The comparison string to check.
+// /// True if the comparison is a mathematical operation, otherwise false.
+// public static bool IsMathOperation(string comparison)
+// {
+// // Check if the comparison string starts with <=, <, >, >=, ==, or =
+// return new[] { "<=", "<", ">", ">=", "==", "=" }.Any(comparison.StartsWith);
+// }
+//
+//
+// ///
+// /// Tests if a math operation is true
+// ///
+// /// The value to apply the operation to.
+// /// The operation string representing the mathematical operation.
+// /// True if the mathematical operation is successful, otherwise false.
+// public static bool IsTrue(string value, string operation)
+// {
+// // This is a basic example; you may need to handle different operators
+// switch (operation[..2])
+// {
+// case "<=":
+// return Convert.ToDouble(value) <= Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()));
+// case ">=":
+// return Convert.ToDouble(value) >= Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()));
+// case "==":
+// return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()))) < 0.05f;
+// case "!=":
+// case "<>":
+// return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[2..].Trim()))) > 0.05f;
+// }
+//
+// switch (operation[..1])
+// {
+// case "<":
+// return Convert.ToDouble(value) < Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim()));
+// case ">":
+// return Convert.ToDouble(value) > Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim()));
+// case "=":
+// return Math.Abs(Convert.ToDouble(value) - Convert.ToDouble(AdjustComparisonValue(operation[1..].Trim()))) < 0.05f;
+// }
+//
+// return false;
+// }
+//
+// ///
+// /// Adjusts the comparison string by handling common mistakes in units and converting them into full numbers.
+// ///
+// /// The original comparison string to be adjusted.
+// /// The adjusted comparison string with corrected units or the original comparison if no adjustments are made.
+// private static string AdjustComparisonValue(string comparisonValue)
+// {
+// if (string.IsNullOrWhiteSpace(comparisonValue))
+// return string.Empty;
+//
+// string adjustedComparison = comparisonValue.ToLower().Trim();
+//
+// // Handle common mistakes in units
+// if (adjustedComparison.EndsWith("mbps"))
+// {
+// // Make an educated guess for Mbps to kbps conversion
+// return adjustedComparison[..^4] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000)
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("kbps"))
+// {
+// // Make an educated guess for kbps to bps conversion
+// return adjustedComparison[..^4] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000)
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("kb"))
+// {
+// return adjustedComparison[..^2] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000 )
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("mb"))
+// {
+// return adjustedComparison[..^2] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000 )
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("gb"))
+// {
+// return adjustedComparison[..^2] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000 )
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("tb"))
+// {
+// return adjustedComparison[..^2] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000_000)
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+//
+// if (adjustedComparison.EndsWith("kib"))
+// {
+// return adjustedComparison[..^3] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_024 )
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("mib"))
+// {
+// return adjustedComparison[..^3] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_048_576 )
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("gib"))
+// {
+// return adjustedComparison[..^3] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_099_511_627_776 )
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// if (adjustedComparison.EndsWith("tib"))
+// {
+// return adjustedComparison[..^3] switch
+// {
+// { } value when double.TryParse(value, out var numericValue) => (numericValue * 1_000_000_000_000)
+// .ToString(CultureInfo.InvariantCulture),
+// _ => comparisonValue
+// };
+// }
+// return comparisonValue;
+// }
+//
+// }
\ No newline at end of file
diff --git a/FileFlows.Plugin.dll b/FileFlows.Plugin.dll
index ed56948a..a7ea7457 100644
Binary files a/FileFlows.Plugin.dll and b/FileFlows.Plugin.dll differ
diff --git a/FileFlows.Plugin.pdb b/FileFlows.Plugin.pdb
index 1b517708..955ea42d 100644
Binary files a/FileFlows.Plugin.pdb and b/FileFlows.Plugin.pdb differ
diff --git a/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConverter.cs b/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConverter.cs
index 1a001532..88e3c1f4 100644
--- a/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConverter.cs
+++ b/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConverter.cs
@@ -15,7 +15,6 @@ public class FfmpegBuilderAudioConverter : FfmpegBuilderNode
///
public override int Outputs => 2;
-
///
/// Gets or sets the codec to use
///
diff --git a/VideoNodes/LogicalNodes/VideoHasStream.cs b/VideoNodes/LogicalNodes/VideoHasStream.cs
index bab7d787..dc6abb7a 100644
--- a/VideoNodes/LogicalNodes/VideoHasStream.cs
+++ b/VideoNodes/LogicalNodes/VideoHasStream.cs
@@ -75,10 +75,17 @@ public class VideoHasStream : VideoNode
///
/// Gets or sets the number of channels to look for
///
- [ConditionEquals(nameof(Stream), "Audio")]
- [NumberFloat(5)]
+ [Obsolete]
public float Channels { get; set; }
+ ///
+ /// Gets or sets the number of channels to look for
+ /// This is a string so math operations can be done
+ ///
+ [ConditionEquals(nameof(Stream), "Audio")]
+ [MathValue(5)]
+ public string ChannelsValue { get; set; }
+
///
/// Gets or sets if deleted tracks should also be checked
///
@@ -124,6 +131,8 @@ public class VideoHasStream : VideoNode
return -1;
}
+ var channels = ChannelsValue?.EmptyAsNull() ?? (Channels > 0 ? "=" + Channels : string.Empty);
+
bool found = false;
string title = args.ReplaceVariables(Title, stripMissing: true);
string codec = args.ReplaceVariables(Codec, stripMissing: true);
@@ -170,7 +179,7 @@ public class VideoHasStream : VideoNode
}
else if (this.Stream == "Audio")
{
- args.Logger?.ILog("Channels to match: " + Channels);
+ args.Logger?.ILog("Channels to match: " + channels);
var streams = ffmpegModel == null
? videoInfo.AudioStreams
: ffmpegModel.AudioStreams.Where(x => x.Deleted == false).Select(x => x.Stream).ToList();
@@ -195,7 +204,7 @@ public class VideoHasStream : VideoNode
return false;
}
- if (this.Channels > 0 && Math.Abs(x.Channels - this.Channels) > 0.05f)
+ if (string.IsNullOrWhiteSpace(channels) == false && MathHelper.IsFalse(channels, x.Channels))
{
args.Logger.ILog("Channels does not match: " + x.Channels + ", Diff : " + Math.Abs(x.Channels - this.Channels));
return false;