Jelajahi Sumber

Made CleanStringParser go through regexps only once

sushilicious 3 tahun lalu
induk
melakukan
b2a10609af
2 mengubah file dengan 9 tambahan dan 28 penghapusan
  1. 2 2
      Emby.Naming/Common/NamingOptions.cs
  2. 7 26
      Emby.Naming/Video/CleanStringParser.cs

+ 2 - 2
Emby.Naming/Common/NamingOptions.cs

@@ -139,9 +139,9 @@ namespace Emby.Naming.Common
             {
             {
                 @"^\s*(?<cleaned>.+?)[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|HDR|HDC|UHD|UltraHD|4k|ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|cd[1-9]|r3|r5|bd5|bd|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|2160p|hrhd|hrhdtv|hddvd|bluray|blu-ray|x264|x265|h264|h265|xvid|xvidvd|xxx|www.www|AAC|DTS|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
                 @"^\s*(?<cleaned>.+?)[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|HDR|HDC|UHD|UltraHD|4k|ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|cd[1-9]|r3|r5|bd5|bd|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|2160p|hrhd|hrhdtv|hddvd|bluray|blu-ray|x264|x265|h264|h265|xvid|xvidvd|xxx|www.www|AAC|DTS|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
                 @"^(?<cleaned>.+?)(\[.*\])",
                 @"^(?<cleaned>.+?)(\[.*\])",
-                @"^\s*(?<cleaned>.+?)\WE\d+(-|~)E?\d+(\W|$)",
+                @"^\s*(?<cleaned>.+?)\WE[0-9]+(-|~)E?[0-9]+(\W|$)",
                 @"^\s*\[[^\]]+\](?!\.\w+$)\s*(?<cleaned>.+)",
                 @"^\s*\[[^\]]+\](?!\.\w+$)\s*(?<cleaned>.+)",
-                @"^\s*(?<cleaned>.+?)\s+-\s+\d+\s*$"
+                @"^\s*(?<cleaned>.+?)\s+-\s+[0-9]+\s*$"
             };
             };
 
 
             SubtitleFileExtensions = new[]
             SubtitleFileExtensions = new[]

+ 7 - 26
Emby.Naming/Video/CleanStringParser.cs

@@ -25,37 +25,18 @@ namespace Emby.Naming.Video
                 return false;
                 return false;
             }
             }
 
 
-            // Iteratively remove extra cruft until we're left with the string
-            // we want.
-            newName = ReadOnlySpan<char>.Empty;
-            const int maxTries = 100;       // This is just a precautionary
-                                            // measure. Should not be neccesary.
-            var loopCounter = 0;
-            for (; loopCounter < maxTries; loopCounter++)
+            // Iteratively apply the regexps to clean the string.
+            bool cleaned = false;
+            for (int i = 0; i < expressions.Count; i++)
             {
             {
-                bool cleaned = false;
-                var len = expressions.Count;
-                for (int i = 0; i < len; i++)
-                {
-                    if (TryClean(name, expressions[i], out newName))
-                    {
-                        cleaned = true;
-                        name = newName.ToString();
-                        break;
-                    }
-                }
-
-                if (!cleaned)
+                if (TryClean(name, expressions[i], out newName))
                 {
                 {
-                    break;
+                    cleaned = true;
+                    name = newName.ToString();
                 }
                 }
             }
             }
 
 
-            if (loopCounter > 0)
-            {
-                newName = name.AsSpan();
-            }
-
+            newName = cleaned ? name.AsSpan() : ReadOnlySpan<char>.Empty;
             return newName != ReadOnlySpan<char>.Empty;
             return newName != ReadOnlySpan<char>.Empty;
         }
         }