FF-1269 - Video Has Stream now check for regex before using a regex

This commit is contained in:
John Andrews
2024-02-04 15:16:11 +13:00
parent 8a7a5420d1
commit 34f82f989f
3 changed files with 30 additions and 15 deletions

View File

@@ -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.

View 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));
}
}

View File

@@ -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)
{