diff options
| author | Bond-009 <bond.009@outlook.com> | 2023-07-06 19:56:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-06 19:56:00 +0200 |
| commit | b95fa294c9e896349c528c032508b9c714c13395 (patch) | |
| tree | 7b85758236caae303e54814f6a13051a3218b60e /MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs | |
| parent | fb9412b65a569f06364ba77841a287c23d142f73 (diff) | |
| parent | 83d6f21fd021c66ab3b1f6501ecdfd016fee540f (diff) | |
Merge pull request #9799 from Bond-009/genregex
Diffstat (limited to 'MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index e1a0e8d67..38118ed0e 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging; namespace MediaBrowser.MediaEncoding.Encoder { - public class EncoderValidator + public partial class EncoderValidator { private static readonly string[] _requiredDecoders = new[] { @@ -165,6 +165,12 @@ namespace MediaBrowser.MediaEncoding.Encoder public static Version? MaxVersion { get; } = null; + [GeneratedRegex(@"^ffmpeg version n?((?:[0-9]+\.?)+)")] + private static partial Regex FfmpegVersionRegex(); + + [GeneratedRegex(@"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))", RegexOptions.Multiline)] + private static partial Regex LibraryRegex(); + public bool ValidateVersion() { string output; @@ -283,7 +289,7 @@ namespace MediaBrowser.MediaEncoding.Encoder internal Version? GetFFmpegVersionInternal(string output) { // For pre-built binaries the FFmpeg version should be mentioned at the very start of the output - var match = Regex.Match(output, @"^ffmpeg version n?((?:[0-9]+\.?)+)"); + var match = FfmpegVersionRegex().Match(output); if (match.Success) { @@ -331,10 +337,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { var map = new Dictionary<string, Version>(); - foreach (Match match in Regex.Matches( - output, - @"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))", - RegexOptions.Multiline)) + foreach (Match match in LibraryRegex().Matches(output)) { var version = new Version( int.Parse(match.Groups["major"].ValueSpan, CultureInfo.InvariantCulture), |
