瀏覽代碼

make the eligibility check more strict wrt. brackets

cvium 4 年之前
父節點
當前提交
b0af11c34e
共有 2 個文件被更改,包括 21 次插入4 次删除
  1. 3 4
      Emby.Naming/Video/VideoListResolver.cs
  2. 18 0
      tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs

+ 3 - 4
Emby.Naming/Video/VideoListResolver.cs

@@ -229,15 +229,14 @@ namespace Emby.Naming.Video
 
                 if (CleanStringParser.TryClean(testFilename, _options.CleanStringRegexes, out var cleanName))
                 {
-                    testFilename = cleanName.ToString();
+                    testFilename = cleanName.Trim().ToString();
                 }
 
-                // The CleanStringParser should have removed common keywords etc., so if it starts with -, _ or [ it's eligible.
+                // The CleanStringParser should have removed common keywords etc.
                 return string.IsNullOrEmpty(testFilename)
                        || testFilename[0] == '-'
                        || testFilename[0] == '_'
-                       || testFilename[0] == '['
-                       || string.IsNullOrWhiteSpace(Regex.Replace(testFilename, @"\[([^]]*)\]", string.Empty));
+                       || Regex.IsMatch(testFilename, @"^\[([^]]*)\]");
             }
 
             return false;

+ 18 - 0
tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs

@@ -388,6 +388,24 @@ namespace Jellyfin.Naming.Tests.Video
             Assert.Single(result[0].AlternateVersions);
         }
 
+        [Fact]
+        public void Resolve_GivenUnclosedBrackets_DoesNotGroup()
+        {
+            var files = new[]
+            {
+                @"/movies/John Wick - Chapter 3 (2019)/John Wick - Kapitel 3 (2019) [Version 1].mkv",
+                @"/movies/John Wick - Chapter 3 (2019)/John Wick - Kapitel 3 (2019) [Version 2.mkv"
+            };
+
+            var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
+            {
+                IsDirectory = false,
+                FullName = i
+            }).ToList()).ToList();
+
+            Assert.Equal(2, result.Count);
+        }
+
         [Fact]
         public void TestEmptyList()
         {