mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-30 09:29:53 -06:00
FF-1269 - Video Has Stream now check for regex before using a regex
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Globalization;
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes.Models;
|
||||
using FileFlows.VideoNodes.Helpers;
|
||||
|
||||
namespace FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
|
||||
@@ -294,7 +295,7 @@ public class FfmpegBuilderTrackSorter : FfmpegBuilderNode
|
||||
}
|
||||
else if (IsMathOperation(comparison))
|
||||
result = ApplyMathOperation(value.ToString(), comparison) ? 0 : 1;
|
||||
else if (IsRegex(comparison))
|
||||
else if (GeneralHelper.IsRegex(comparison))
|
||||
result = Regex.IsMatch(value.ToString(), comparison, RegexOptions.IgnoreCase) ? 0 : 1;
|
||||
else if (value != null && double.TryParse(value.ToString(), out double dbl))
|
||||
result = dbl;
|
||||
@@ -456,16 +457,6 @@ public class FfmpegBuilderTrackSorter : FfmpegBuilderNode
|
||||
// Check if the comparison string starts with <=, <, >, >=, ==, or =
|
||||
return new[] { "<=", "<", ">", ">=", "==", "=" }.Any(comparison.StartsWith);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the comparison string represents a regular expression.
|
||||
/// </summary>
|
||||
/// <param name="comparison">The comparison string to check.</param>
|
||||
/// <returns>True if the comparison is a regular expression, otherwise false.</returns>
|
||||
private static bool IsRegex(string comparison)
|
||||
{
|
||||
return new[] { "?", "|", "^", "$" }.Any(ch => comparison.Contains(ch));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a mathematical operation to the value based on the specified operation string.
|
||||
|
||||
17
VideoNodes/Helpers/GeneralHelper.cs
Normal file
17
VideoNodes/Helpers/GeneralHelper.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace FileFlows.VideoNodes.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// General helper
|
||||
/// </summary>
|
||||
public class GeneralHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the input string represents a regular expression.
|
||||
/// </summary>
|
||||
/// <param name="input">The input string to check.</param>
|
||||
/// <returns>True if the input is a regular expression, otherwise false.</returns>
|
||||
public static bool IsRegex(string input)
|
||||
{
|
||||
return new[] { "?", "|", "^", "$" }.Any(ch => input.Contains(ch));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes.Models;
|
||||
using FileFlows.VideoNodes.Helpers;
|
||||
|
||||
namespace FileFlows.VideoNodes;
|
||||
|
||||
@@ -209,14 +210,20 @@ public class VideoHasStream : VideoNode
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return MatchResult.NoMatch;
|
||||
var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
|
||||
if(rgx.IsMatch(value))
|
||||
return MatchResult.Matched;
|
||||
|
||||
if (GeneralHelper.IsRegex(pattern))
|
||||
{
|
||||
var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
|
||||
if (rgx.IsMatch(value))
|
||||
return MatchResult.Matched;
|
||||
}
|
||||
|
||||
if (value.ToLower() == "hevc" && (pattern.ToLower() == "h265" || pattern == "265" || pattern.ToLower() == "h.265"))
|
||||
return MatchResult.Matched; // special case
|
||||
|
||||
return MatchResult.NoMatch;
|
||||
return pattern.ToLowerInvariant().Trim() == value.ToLowerInvariant().Trim()
|
||||
? MatchResult.Matched
|
||||
: MatchResult.NoMatch;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user