make the eligibility check more strict wrt. brackets

This commit is contained in:
cvium 2021-03-10 19:29:52 +01:00
parent 3824c09e77
commit b0af11c34e
2 changed files with 21 additions and 4 deletions

View File

@ -229,15 +229,14 @@ namespace Emby.Naming.Video
if (CleanStringParser.TryClean(testFilename, _options.CleanStringRegexes, out var cleanName)) 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) return string.IsNullOrEmpty(testFilename)
|| testFilename[0] == '-' || testFilename[0] == '-'
|| testFilename[0] == '_' || testFilename[0] == '_'
|| testFilename[0] == '[' || Regex.IsMatch(testFilename, @"^\[([^]]*)\]");
|| string.IsNullOrWhiteSpace(Regex.Replace(testFilename, @"\[([^]]*)\]", string.Empty));
} }
return false; return false;

View File

@ -388,6 +388,24 @@ namespace Jellyfin.Naming.Tests.Video
Assert.Single(result[0].AlternateVersions); 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] [Fact]
public void TestEmptyList() public void TestEmptyList()
{ {