Merge pull request #2950 from Bond-009/videoresolver

Fix VideoResolver and tests
This commit is contained in:
Anthony Lavado 2020-05-04 04:21:30 -04:00 committed by GitHub
commit 0e11646107
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 235 additions and 321 deletions

View File

@ -89,14 +89,14 @@ namespace Emby.Naming.Video
if (parseName) if (parseName)
{ {
var cleanDateTimeResult = CleanDateTime(name); var cleanDateTimeResult = CleanDateTime(name);
name = cleanDateTimeResult.Name;
year = cleanDateTimeResult.Year;
if (extraResult.ExtraType == null if (extraResult.ExtraType == null
&& TryCleanString(cleanDateTimeResult.Name, out ReadOnlySpan<char> newName)) && TryCleanString(name, out ReadOnlySpan<char> newName))
{ {
name = newName.ToString(); name = newName.ToString();
} }
year = cleanDateTimeResult.Year;
} }
return new VideoFileInfo return new VideoFileInfo

View File

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Emby.Server.Implementations.HttpServer; using Emby.Server.Implementations.HttpServer;
using Emby.Server.Implementations.Updates; using Emby.Server.Implementations.Updates;
using MediaBrowser.Providers.Music;
using static MediaBrowser.Controller.Extensions.ConfigurationExtensions; using static MediaBrowser.Controller.Extensions.ConfigurationExtensions;
namespace Emby.Server.Implementations namespace Emby.Server.Implementations

View File

@ -1,13 +0,0 @@
using Emby.Naming.Common;
using Emby.Naming.Video;
namespace Jellyfin.Naming.Tests.Video
{
public abstract class BaseVideoTest
{
private readonly NamingOptions _namingOptions = new NamingOptions();
protected VideoResolver GetParser()
=> new VideoResolver(_namingOptions);
}
}

View File

@ -46,6 +46,7 @@ namespace Jellyfin.Naming.Tests.Video
[InlineData("Maximum Ride - 2016 - WEBDL-1080p - x264 AC3.mkv", "Maximum Ride", 2016)] [InlineData("Maximum Ride - 2016 - WEBDL-1080p - x264 AC3.mkv", "Maximum Ride", 2016)]
// FIXME: [InlineData("Robin Hood [Multi-Subs] [2018].mkv", "Robin Hood", 2018)] // FIXME: [InlineData("Robin Hood [Multi-Subs] [2018].mkv", "Robin Hood", 2018)]
[InlineData(@"3.Days.to.Kill.2014.720p.BluRay.x264.YIFY.mkv", "3.Days.to.Kill", 2014)] // In this test case, running CleanDateTime first produces no date, so it will attempt to run CleanString first and then CleanDateTime again [InlineData(@"3.Days.to.Kill.2014.720p.BluRay.x264.YIFY.mkv", "3.Days.to.Kill", 2014)] // In this test case, running CleanDateTime first produces no date, so it will attempt to run CleanString first and then CleanDateTime again
[InlineData("3 days to kill (2005).mkv", "3 days to kill", 2005)]
public void CleanDateTimeTest(string input, string expectedName, int? expectedYear) public void CleanDateTimeTest(string input, string expectedName, int? expectedYear)
{ {
input = Path.GetFileName(input); input = Path.GetFileName(input);

View File

@ -5,7 +5,7 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video namespace Jellyfin.Naming.Tests.Video
{ {
public class ExtraTests : BaseVideoTest public class ExtraTests
{ {
private readonly NamingOptions _videoOptions = new NamingOptions(); private readonly NamingOptions _videoOptions = new NamingOptions();

View File

@ -4,26 +4,26 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video namespace Jellyfin.Naming.Tests.Video
{ {
public class Format3DTests : BaseVideoTest public class Format3DTests
{ {
private readonly NamingOptions _namingOptions = new NamingOptions();
[Fact] [Fact]
public void TestKodiFormat3D() public void TestKodiFormat3D()
{ {
var options = new NamingOptions(); Test("Super movie.3d.mp4", false, null);
Test("Super movie.3d.hsbs.mp4", true, "hsbs");
Test("Super movie.3d.mp4", false, null, options); Test("Super movie.3d.sbs.mp4", true, "sbs");
Test("Super movie.3d.hsbs.mp4", true, "hsbs", options); Test("Super movie.3d.htab.mp4", true, "htab");
Test("Super movie.3d.sbs.mp4", true, "sbs", options); Test("Super movie.3d.tab.mp4", true, "tab");
Test("Super movie.3d.htab.mp4", true, "htab", options); Test("Super movie 3d hsbs.mp4", true, "hsbs");
Test("Super movie.3d.tab.mp4", true, "tab", options);
Test("Super movie 3d hsbs.mp4", true, "hsbs", options);
} }
[Fact] [Fact]
public void Test3DName() public void Test3DName()
{ {
var result = var result =
GetParser().ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.3d.hsbs.mkv"); new VideoResolver(_namingOptions).ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.3d.hsbs.mkv");
Assert.Equal("hsbs", result.Format3D); Assert.Equal("hsbs", result.Format3D);
Assert.Equal("Oblivion", result.Name); Assert.Equal("Oblivion", result.Name);
@ -34,32 +34,31 @@ namespace Jellyfin.Naming.Tests.Video
{ {
// These were introduced for Media Browser 3 // These were introduced for Media Browser 3
// Kodi conventions are preferred but these still need to be supported // Kodi conventions are preferred but these still need to be supported
var options = new NamingOptions();
Test("Super movie.3d.mp4", false, null, options); Test("Super movie.3d.mp4", false, null);
Test("Super movie.3d.hsbs.mp4", true, "hsbs", options); Test("Super movie.3d.hsbs.mp4", true, "hsbs");
Test("Super movie.3d.sbs.mp4", true, "sbs", options); Test("Super movie.3d.sbs.mp4", true, "sbs");
Test("Super movie.3d.htab.mp4", true, "htab", options); Test("Super movie.3d.htab.mp4", true, "htab");
Test("Super movie.3d.tab.mp4", true, "tab", options); Test("Super movie.3d.tab.mp4", true, "tab");
Test("Super movie.hsbs.mp4", true, "hsbs", options); Test("Super movie.hsbs.mp4", true, "hsbs");
Test("Super movie.sbs.mp4", true, "sbs", options); Test("Super movie.sbs.mp4", true, "sbs");
Test("Super movie.htab.mp4", true, "htab", options); Test("Super movie.htab.mp4", true, "htab");
Test("Super movie.tab.mp4", true, "tab", options); Test("Super movie.tab.mp4", true, "tab");
Test("Super movie.sbs3d.mp4", true, "sbs3d", options); Test("Super movie.sbs3d.mp4", true, "sbs3d");
Test("Super movie.3d.mvc.mp4", true, "mvc", options); Test("Super movie.3d.mvc.mp4", true, "mvc");
Test("Super movie [3d].mp4", false, null, options); Test("Super movie [3d].mp4", false, null);
Test("Super movie [hsbs].mp4", true, "hsbs", options); Test("Super movie [hsbs].mp4", true, "hsbs");
Test("Super movie [fsbs].mp4", true, "fsbs", options); Test("Super movie [fsbs].mp4", true, "fsbs");
Test("Super movie [ftab].mp4", true, "ftab", options); Test("Super movie [ftab].mp4", true, "ftab");
Test("Super movie [htab].mp4", true, "htab", options); Test("Super movie [htab].mp4", true, "htab");
Test("Super movie [sbs3d].mp4", true, "sbs3d", options); Test("Super movie [sbs3d].mp4", true, "sbs3d");
} }
private void Test(string input, bool is3D, string format3D, NamingOptions options) private void Test(string input, bool is3D, string? format3D)
{ {
var parser = new Format3DParser(options); var parser = new Format3DParser(_namingOptions);
var result = parser.Parse(input); var result = parser.Parse(input);

View File

@ -8,6 +8,8 @@ namespace Jellyfin.Naming.Tests.Video
{ {
public class MultiVersionTests public class MultiVersionTests
{ {
private readonly NamingOptions _namingOptions = new NamingOptions();
// FIXME // FIXME
// [Fact] // [Fact]
public void TestMultiEdition1() public void TestMultiEdition1()
@ -430,8 +432,7 @@ namespace Jellyfin.Naming.Tests.Video
private VideoListResolver GetResolver() private VideoListResolver GetResolver()
{ {
var options = new NamingOptions(); return new VideoListResolver(_namingOptions);
return new VideoListResolver(options);
} }
} }
} }

View File

@ -6,8 +6,10 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video namespace Jellyfin.Naming.Tests.Video
{ {
public class StackTests : BaseVideoTest public class StackTests
{ {
private readonly NamingOptions _namingOptions = new NamingOptions();
[Fact] [Fact]
public void TestSimpleStack() public void TestSimpleStack()
{ {
@ -446,7 +448,7 @@ namespace Jellyfin.Naming.Tests.Video
private StackResolver GetResolver() private StackResolver GetResolver()
{ {
return new StackResolver(new NamingOptions()); return new StackResolver(_namingOptions);
} }
} }
} }

View File

@ -4,8 +4,10 @@ using Xunit;
namespace Jellyfin.Naming.Tests.Video namespace Jellyfin.Naming.Tests.Video
{ {
public class StubTests : BaseVideoTest public class StubTests
{ {
private readonly NamingOptions _namingOptions = new NamingOptions();
[Fact] [Fact]
public void TestStubs() public void TestStubs()
{ {
@ -27,16 +29,14 @@ namespace Jellyfin.Naming.Tests.Video
public void TestStubName() public void TestStubName()
{ {
var result = var result =
GetParser().ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.dvd.disc"); new VideoResolver(_namingOptions).ResolveFile(@"C:/Users/media/Desktop/Video Test/Movies/Oblivion/Oblivion.dvd.disc");
Assert.Equal("Oblivion", result.Name); Assert.Equal("Oblivion", result.Name);
} }
private void Test(string path, bool isStub, string stubType) private void Test(string path, bool isStub, string stubType)
{ {
var options = new NamingOptions(); var isStubResult = StubResolver.TryResolveFile(path, _namingOptions, out var stubTypeResult);
var isStubResult = StubResolver.TryResolveFile(path, options, out var stubTypeResult);
Assert.Equal(isStub, isStubResult); Assert.Equal(isStub, isStubResult);

View File

@ -8,6 +8,7 @@ namespace Jellyfin.Naming.Tests.Video
{ {
public class VideoListResolverTests public class VideoListResolverTests
{ {
private readonly NamingOptions _namingOptions = new NamingOptions();
// FIXME // FIXME
// [Fact] // [Fact]
public void TestStackAndExtras() public void TestStackAndExtras()
@ -450,8 +451,7 @@ namespace Jellyfin.Naming.Tests.Video
private VideoListResolver GetResolver() private VideoListResolver GetResolver()
{ {
var options = new NamingOptions(); return new VideoListResolver(_namingOptions);
return new VideoListResolver(options);
} }
} }
} }

View File

@ -1,275 +1,200 @@
using MediaBrowser.Model.Entities; using System.Collections.Generic;
using Emby.Naming.Common;
using Emby.Naming.Video;
using MediaBrowser.Model.Entities;
using Xunit; using Xunit;
namespace Jellyfin.Naming.Tests.Video namespace Jellyfin.Naming.Tests.Video
{ {
public class VideoResolverTests : BaseVideoTest public class VideoResolverTests
{ {
// FIXME private readonly NamingOptions _namingOptions = new NamingOptions();
// [Fact]
public void TestSimpleFile() public static IEnumerable<object[]> GetResolveFileTestData()
{ {
var parser = GetParser(); yield return new object[]
{
var result = new VideoFileInfo()
parser.ResolveFile(@"/server/Movies/Brave (2007)/Brave (2006).mkv"); {
Path = @"/server/Movies/7 Psychos.mkv/7 Psychos.mkv",
Assert.Equal(2006, result.Year); Container = "mkv",
Assert.False(result.IsStub); Name = "7 Psychos"
Assert.False(result.Is3D); }
Assert.Equal("Brave", result.Name); };
Assert.Null(result.ExtraType); yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/3 days to kill (2005)/3 days to kill (2005).mkv",
Container = "mkv",
Name = "3 days to kill",
Year = 2005
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/American Psycho/American.Psycho.mkv",
Container = "mkv",
Name = "American.Psycho",
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv",
Container = "mkv",
Name = "brave",
Year = 2006,
Is3D = true,
Format3D = "sbs",
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv",
Container = "mkv",
Name = "300",
Year = 2006
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv",
Container = "mkv",
Name = "300",
Year = 2006,
Is3D = true,
Format3D = "sbs",
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc",
Container = "disc",
Name = "brave",
Year = 2006,
IsStub = true,
StubType = "bluray",
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc",
Container = "disc",
Name = "300",
Year = 2006,
IsStub = true,
StubType = "bluray",
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/Brave (2007)/Brave (2006).bluray.disc",
Container = "disc",
Name = "Brave",
Year = 2006,
IsStub = true,
StubType = "bluray",
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/300 (2007)/300 (2006).bluray.disc",
Container = "disc",
Name = "300",
Year = 2006,
IsStub = true,
StubType = "bluray",
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/300 (2007)/300 (2006)-trailer.mkv",
Container = "mkv",
Name = "300",
Year = 2006,
ExtraType = ExtraType.Trailer,
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv",
Container = "mkv",
Name = "Brave",
Year = 2006,
ExtraType = ExtraType.Trailer,
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/300 (2007)/300 (2006).mkv",
Container = "mkv",
Name = "300",
Year = 2006
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv",
Container = "mkv",
Name = "Bad Boys",
Year = 1995,
}
};
yield return new object[]
{
new VideoFileInfo()
{
Path = @"/server/Movies/Brave (2007)/Brave (2006).mkv",
Container = "mkv",
Name = "Brave",
Year = 2006,
}
};
} }
// FIXME
// [Fact] [Theory]
public void TestSimpleFile2() [MemberData(nameof(GetResolveFileTestData))]
public void ResolveFile_ValidFileName_Success(VideoFileInfo expectedResult)
{ {
var parser = GetParser(); var result = new VideoResolver(_namingOptions).ResolveFile(expectedResult.Path);
var result = Assert.NotNull(result);
parser.ResolveFile(@"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv"); Assert.Equal(result.Path, expectedResult.Path);
Assert.Equal(result.Container, expectedResult.Container);
Assert.Equal(1995, result.Year); Assert.Equal(result.Name, expectedResult.Name);
Assert.False(result.IsStub); Assert.Equal(result.Year, expectedResult.Year);
Assert.False(result.Is3D); Assert.Equal(result.ExtraType, expectedResult.ExtraType);
Assert.Equal("Bad Boys", result.Name); Assert.Equal(result.Format3D, expectedResult.Format3D);
Assert.Null(result.ExtraType); Assert.Equal(result.Is3D, expectedResult.Is3D);
} Assert.Equal(result.IsStub, expectedResult.IsStub);
Assert.Equal(result.StubType, expectedResult.StubType);
// FIXME Assert.Equal(result.IsDirectory, expectedResult.IsDirectory);
// [Fact] Assert.Equal(result.FileNameWithoutExtension, expectedResult.FileNameWithoutExtension);
public void TestSimpleFileWithNumericName()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).mkv");
Assert.Equal(2006, result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Equal("300", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void TestExtra()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv");
Assert.Equal(2006, result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Equal(ExtraType.Trailer, result.ExtraType);
Assert.Equal("Brave (2006)-trailer", result.Name);
}
// FIXME
// [Fact]
public void TestExtraWithNumericName()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006)-trailer.mkv");
Assert.Equal(2006, result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Equal("300 (2006)-trailer", result.Name);
Assert.Equal(ExtraType.Trailer, result.ExtraType);
}
// FIXME
// [Fact]
public void TestStubFileWithNumericName()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).bluray.disc");
Assert.Equal(2006, result.Year);
Assert.True(result.IsStub);
Assert.Equal("bluray", result.StubType);
Assert.False(result.Is3D);
Assert.Equal("300", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void TestStubFile()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/Brave (2007)/Brave (2006).bluray.disc");
Assert.Equal(2006, result.Year);
Assert.True(result.IsStub);
Assert.Equal("bluray", result.StubType);
Assert.False(result.Is3D);
Assert.Equal("Brave", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void TestExtraStubWithNumericNameNotSupported()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc");
Assert.Equal(2006, result.Year);
Assert.True(result.IsStub);
Assert.Equal("bluray", result.StubType);
Assert.False(result.Is3D);
Assert.Equal("300", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void TestExtraStubNotSupported()
{
// Using a stub for an extra is currently not supported
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc");
Assert.Equal(2006, result.Year);
Assert.True(result.IsStub);
Assert.Equal("bluray", result.StubType);
Assert.False(result.Is3D);
Assert.Equal("brave", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void Test3DFileWithNumericName()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv");
Assert.Equal(2006, result.Year);
Assert.False(result.IsStub);
Assert.True(result.Is3D);
Assert.Equal("sbs", result.Format3D);
Assert.Equal("300", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void TestBad3DFileWithNumericName()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv");
Assert.Equal(2006, result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Equal("300", result.Name);
Assert.Null(result.ExtraType);
Assert.Null(result.Format3D);
}
// FIXME
// [Fact]
public void Test3DFile()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv");
Assert.Equal(2006, result.Year);
Assert.False(result.IsStub);
Assert.True(result.Is3D);
Assert.Equal("sbs", result.Format3D);
Assert.Equal("brave", result.Name);
Assert.Null(result.ExtraType);
}
[Fact]
public void TestNameWithoutDate()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/American Psycho/American.Psycho.mkv");
Assert.Null(result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Null(result.Format3D);
Assert.Equal("American.Psycho", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void TestCleanDateAndStringsSequence()
{
var parser = GetParser();
// In this test case, running CleanDateTime first produces no date, so it will attempt to run CleanString first and then CleanDateTime again
var result =
parser.ResolveFile(@"/server/Movies/3.Days.to.Kill/3.Days.to.Kill.2014.720p.BluRay.x264.YIFY.mkv");
Assert.Equal(2014, result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Null(result.Format3D);
Assert.Equal("3.Days.to.Kill", result.Name);
Assert.Null(result.ExtraType);
}
// FIXME
// [Fact]
public void TestCleanDateAndStringsSequence1()
{
var parser = GetParser();
// In this test case, running CleanDateTime first produces no date, so it will attempt to run CleanString first and then CleanDateTime again
var result =
parser.ResolveFile(@"/server/Movies/3 days to kill (2005)/3 days to kill (2005).mkv");
Assert.Equal(2005, result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Null(result.Format3D);
Assert.Equal("3 days to kill", result.Name);
Assert.Null(result.ExtraType);
}
[Fact]
public void TestFolderNameWithExtension()
{
var parser = GetParser();
var result =
parser.ResolveFile(@"/server/Movies/7 Psychos.mkv/7 Psychos.mkv");
Assert.Null(result.Year);
Assert.False(result.IsStub);
Assert.False(result.Is3D);
Assert.Equal("7 Psychos", result.Name);
Assert.Null(result.ExtraType);
} }
} }
} }