jellyfin-server/tests/Jellyfin.Naming.Tests/Video/MultiVersionTests.cs

449 lines
15 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2019-12-06 19:40:06 +00:00
using Emby.Naming.Common;
using Emby.Naming.Video;
using MediaBrowser.Model.IO;
using Xunit;
namespace Jellyfin.Naming.Tests.Video
{
public class MultiVersionTests
{
2021-05-23 22:30:41 +00:00
private readonly NamingOptions _namingOptions = new NamingOptions();
2020-04-21 10:11:55 +00:00
[Fact]
public void TestMultiEdition1()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past - 1080p.mkv",
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past-trailer.mp4",
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past - [hsbs].mkv",
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past [hsbs].mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Single(result[0].Extras);
}
[Fact]
public void TestMultiEdition2()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past - apple.mkv",
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past-trailer.mp4",
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past - banana.mkv",
@"/movies/X-Men Days of Future Past/X-Men Days of Future Past [banana].mp4"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Single(result[0].Extras);
Assert.Equal(2, result[0].AlternateVersions.Count);
}
[Fact]
public void TestMultiEdition3()
{
var files = new[]
{
@"/movies/The Phantom of the Opera (1925)/The Phantom of the Opera (1925) - 1925 version.mkv",
@"/movies/The Phantom of the Opera (1925)/The Phantom of the Opera (1925) - 1929 version.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Single(result[0].AlternateVersions);
}
[Fact]
public void TestLetterFolders()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/M/Movie 1.mkv",
@"/movies/M/Movie 2.mkv",
@"/movies/M/Movie 3.mkv",
@"/movies/M/Movie 4.mkv",
@"/movies/M/Movie 5.mkv",
@"/movies/M/Movie 6.mkv",
@"/movies/M/Movie 7.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Equal(7, result.Count);
Assert.Empty(result[0].Extras);
Assert.Empty(result[0].AlternateVersions);
}
[Fact]
public void TestMultiVersionLimit()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Movie/Movie.mkv",
@"/movies/Movie/Movie-2.mkv",
@"/movies/Movie/Movie-3.mkv",
@"/movies/Movie/Movie-4.mkv",
@"/movies/Movie/Movie-5.mkv",
@"/movies/Movie/Movie-6.mkv",
@"/movies/Movie/Movie-7.mkv",
@"/movies/Movie/Movie-8.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Empty(result[0].Extras);
Assert.Equal(7, result[0].AlternateVersions.Count);
}
[Fact]
public void TestMultiVersionLimit2()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Mo/Movie 1.mkv",
@"/movies/Mo/Movie 2.mkv",
@"/movies/Mo/Movie 3.mkv",
@"/movies/Mo/Movie 4.mkv",
@"/movies/Mo/Movie 5.mkv",
@"/movies/Mo/Movie 6.mkv",
@"/movies/Mo/Movie 7.mkv",
@"/movies/Mo/Movie 8.mkv",
@"/movies/Mo/Movie 9.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Equal(9, result.Count);
Assert.Empty(result[0].Extras);
Assert.Empty(result[0].AlternateVersions);
}
[Fact]
public void TestMultiVersion3()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Movie/Movie 1.mkv",
@"/movies/Movie/Movie 2.mkv",
@"/movies/Movie/Movie 3.mkv",
@"/movies/Movie/Movie 4.mkv",
@"/movies/Movie/Movie 5.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Equal(5, result.Count);
Assert.Empty(result[0].Extras);
Assert.Empty(result[0].AlternateVersions);
}
[Fact]
public void TestMultiVersion4()
2019-12-06 19:40:06 +00:00
{
// Test for false positive
var files = new[]
{
@"/movies/Iron Man/Iron Man.mkv",
@"/movies/Iron Man/Iron Man (2008).mkv",
@"/movies/Iron Man/Iron Man (2009).mkv",
@"/movies/Iron Man/Iron Man (2010).mkv",
@"/movies/Iron Man/Iron Man (2011).mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Equal(5, result.Count);
Assert.Empty(result[0].Extras);
Assert.Empty(result[0].AlternateVersions);
}
[Fact]
public void TestMultiVersion5()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Iron Man/Iron Man.mkv",
@"/movies/Iron Man/Iron Man-720p.mkv",
@"/movies/Iron Man/Iron Man-test.mkv",
@"/movies/Iron Man/Iron Man-bluray.mkv",
@"/movies/Iron Man/Iron Man-3d.mkv",
@"/movies/Iron Man/Iron Man-3d-hsbs.mkv",
@"/movies/Iron Man/Iron Man-3d.hsbs.mkv",
@"/movies/Iron Man/Iron Man[test].mkv",
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Empty(result[0].Extras);
Assert.Equal(7, result[0].AlternateVersions.Count);
Assert.False(result[0].AlternateVersions[2].Is3D);
Assert.True(result[0].AlternateVersions[3].Is3D);
Assert.True(result[0].AlternateVersions[4].Is3D);
}
[Fact]
public void TestMultiVersion6()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Iron Man/Iron Man.mkv",
@"/movies/Iron Man/Iron Man - 720p.mkv",
@"/movies/Iron Man/Iron Man - test.mkv",
@"/movies/Iron Man/Iron Man - bluray.mkv",
@"/movies/Iron Man/Iron Man - 3d.mkv",
@"/movies/Iron Man/Iron Man - 3d-hsbs.mkv",
@"/movies/Iron Man/Iron Man - 3d.hsbs.mkv",
@"/movies/Iron Man/Iron Man [test].mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Empty(result[0].Extras);
Assert.Equal(7, result[0].AlternateVersions.Count);
Assert.False(result[0].AlternateVersions[3].Is3D);
Assert.True(result[0].AlternateVersions[4].Is3D);
Assert.True(result[0].AlternateVersions[5].Is3D);
}
[Fact]
public void TestMultiVersion7()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Iron Man/Iron Man - B (2006).mkv",
@"/movies/Iron Man/Iron Man - C (2007).mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Equal(2, result.Count);
}
[Fact]
public void TestMultiVersion8()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Iron Man/Iron Man.mkv",
@"/movies/Iron Man/Iron Man_720p.mkv",
@"/movies/Iron Man/Iron Man_test.mkv",
@"/movies/Iron Man/Iron Man_bluray.mkv",
@"/movies/Iron Man/Iron Man_3d.mkv",
@"/movies/Iron Man/Iron Man_3d-hsbs.mkv",
@"/movies/Iron Man/Iron Man_3d.hsbs.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Equal(7, result.Count);
2019-12-06 19:40:06 +00:00
Assert.Empty(result[0].Extras);
Assert.Empty(result[0].AlternateVersions);
2019-12-06 19:40:06 +00:00
}
[Fact]
public void TestMultiVersion9()
2019-12-06 19:40:06 +00:00
{
// Test for false positive
var files = new[]
{
@"/movies/Iron Man/Iron Man (2007).mkv",
@"/movies/Iron Man/Iron Man (2008).mkv",
@"/movies/Iron Man/Iron Man (2009).mkv",
@"/movies/Iron Man/Iron Man (2010).mkv",
@"/movies/Iron Man/Iron Man (2011).mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Equal(5, result.Count);
Assert.Empty(result[0].Extras);
Assert.Empty(result[0].AlternateVersions);
}
[Fact]
public void TestMultiVersion10()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/Blade Runner (1982)/Blade Runner (1982) [Final Cut] [1080p HEVC AAC].mkv",
@"/movies/Blade Runner (1982)/Blade Runner (1982) [EE by ADM] [480p HEVC AAC,AAC,AAC].mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Empty(result[0].Extras);
Assert.Single(result[0].AlternateVersions);
}
[Fact]
public void TestMultiVersion11()
2019-12-06 19:40:06 +00:00
{
var files = new[]
{
@"/movies/X-Men Apocalypse (2016)/X-Men Apocalypse (2016) [1080p] Blu-ray.x264.DTS.mkv",
@"/movies/X-Men Apocalypse (2016)/X-Men Apocalypse (2016) [2160p] Blu-ray.x265.AAC.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
2019-12-06 19:40:06 +00:00
Assert.Single(result);
Assert.Empty(result[0].Extras);
Assert.Single(result[0].AlternateVersions);
}
[Fact]
public void Resolve_GivenFolderNameWithBracketsAndHyphens_GroupsBasedOnFolderName()
{
var files = new[]
{
@"/movies/John Wick - Kapitel 3 (2019) [imdbid=tt6146586]/John Wick - Kapitel 3 (2019) [imdbid=tt6146586] - Version 1.mkv",
@"/movies/John Wick - Kapitel 3 (2019) [imdbid=tt6146586]/John Wick - Kapitel 3 (2019) [imdbid=tt6146586] - Version 2.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
Assert.Single(result);
Assert.Empty(result[0].Extras);
Assert.Single(result[0].AlternateVersions);
}
[Fact]
public void Resolve_GivenUnclosedBrackets_DoesNotGroup()
{
var files = new[]
{
2021-03-10 18:30:23 +00:00
@"/movies/John Wick - Chapter 3 (2019)/John Wick - Chapter 3 (2019) [Version 1].mkv",
@"/movies/John Wick - Chapter 3 (2019)/John Wick - Chapter 3 (2019) [Version 2.mkv"
};
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(
files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}).ToList(),
_namingOptions).ToList();
Assert.Equal(2, result.Count);
}
[Fact]
public void TestEmptyList()
{
2021-05-23 22:30:41 +00:00
var result = VideoListResolver.Resolve(new List<FileSystemMetadata>(), _namingOptions).ToList();
Assert.Empty(result);
}
2019-12-06 19:40:06 +00:00
}
}