瀏覽代碼

Use generated regex

Stepan Goremykin 1 年之前
父節點
當前提交
3259d484ff

+ 10 - 4
MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs

@@ -499,8 +499,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
 
             var required = codec == Codec.Encoder ? _requiredEncoders : _requiredDecoders;
             var required = codec == Codec.Encoder ? _requiredEncoders : _requiredDecoders;
 
 
-            var found = Regex
-                .Matches(output, @"^\s\S{6}\s(?<codec>[\w|-]+)\s+.+$", RegexOptions.Multiline)
+            var found = CodecRegex()
+                .Matches(output)
                 .Select(x => x.Groups["codec"].Value)
                 .Select(x => x.Groups["codec"].Value)
                 .Where(x => required.Contains(x));
                 .Where(x => required.Contains(x));
 
 
@@ -527,8 +527,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
                 return Enumerable.Empty<string>();
                 return Enumerable.Empty<string>();
             }
             }
 
 
-            var found = Regex
-                .Matches(output, @"^\s\S{3}\s(?<filter>[\w|-]+)\s+.+$", RegexOptions.Multiline)
+            var found = FilterRegex()
+                .Matches(output)
                 .Select(x => x.Groups["filter"].Value)
                 .Select(x => x.Groups["filter"].Value)
                 .Where(x => _requiredFilters.Contains(x));
                 .Where(x => _requiredFilters.Contains(x));
 
 
@@ -582,5 +582,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
                 return reader.ReadToEnd();
                 return reader.ReadToEnd();
             }
             }
         }
         }
+
+        [GeneratedRegex("^\\s\\S{6}\\s(?<codec>[\\w|-]+)\\s+.+$", RegexOptions.Multiline)]
+        private static partial Regex CodecRegex();
+
+        [GeneratedRegex("^\\s\\S{3}\\s(?<filter>[\\w|-]+)\\s+.+$", RegexOptions.Multiline)]
+        private static partial Regex FilterRegex();
     }
     }
 }
 }

+ 5 - 4
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -22,7 +22,7 @@ namespace MediaBrowser.MediaEncoding.Probing
     /// <summary>
     /// <summary>
     /// Class responsible for normalizing FFprobe output.
     /// Class responsible for normalizing FFprobe output.
     /// </summary>
     /// </summary>
-    public class ProbeResultNormalizer
+    public partial class ProbeResultNormalizer
     {
     {
         // When extracting subtitles, the maximum length to consider (to avoid invalid filenames)
         // When extracting subtitles, the maximum length to consider (to avoid invalid filenames)
         private const int MaxSubtitleDescriptionExtractionLength = 100;
         private const int MaxSubtitleDescriptionExtractionLength = 100;
@@ -31,8 +31,6 @@ namespace MediaBrowser.MediaEncoding.Probing
 
 
         private readonly char[] _nameDelimiters = { '/', '|', ';', '\\' };
         private readonly char[] _nameDelimiters = { '/', '|', ';', '\\' };
 
 
-        private static readonly Regex _performerPattern = new(@"(?<name>.*) \((?<instrument>.*)\)");
-
         private readonly ILogger _logger;
         private readonly ILogger _logger;
         private readonly ILocalizationManager _localization;
         private readonly ILocalizationManager _localization;
 
 
@@ -1215,7 +1213,7 @@ namespace MediaBrowser.MediaEncoding.Probing
             {
             {
                 foreach (var person in Split(performer, false))
                 foreach (var person in Split(performer, false))
                 {
                 {
-                    Match match = _performerPattern.Match(person);
+                    Match match = PerformerRegex().Match(person);
 
 
                     // If the performer doesn't have any instrument/role associated, it won't match. In that case, chances are it's simply a band name, so we skip it.
                     // If the performer doesn't have any instrument/role associated, it won't match. In that case, chances are it's simply a band name, so we skip it.
                     if (match.Success)
                     if (match.Success)
@@ -1654,5 +1652,8 @@ namespace MediaBrowser.MediaEncoding.Probing
 
 
             return TransportStreamTimestamp.Valid;
             return TransportStreamTimestamp.Valid;
         }
         }
+
+        [GeneratedRegex("(?<name>.*) \\((?<instrument>.*)\\)")]
+        private static partial Regex PerformerRegex();
     }
     }
 }
 }