2020-11-05 15:59:15 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-04-21 10:11:55 +00:00
|
|
|
using Emby.Naming.Common;
|
|
|
|
using Emby.Naming.Video;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2019-12-06 19:40:06 +00:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Naming.Tests.Video
|
|
|
|
{
|
2020-04-25 16:55:54 +00:00
|
|
|
public class VideoResolverTests
|
2019-12-06 19:40:06 +00:00
|
|
|
{
|
2021-05-23 22:30:41 +00:00
|
|
|
private static NamingOptions _namingOptions = new NamingOptions();
|
2020-04-21 10:11:55 +00:00
|
|
|
|
2021-03-09 02:04:47 +00:00
|
|
|
public static IEnumerable<object[]> ResolveFile_ValidFileNameTestData()
|
2020-04-21 10:11:55 +00:00
|
|
|
{
|
2020-04-25 13:29:59 +00:00
|
|
|
yield return new object[]
|
2020-04-21 10:11:55 +00:00
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/7 Psychos.mkv/7 Psychos.mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "7 Psychos")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
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)
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/American Psycho/American.Psycho.mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "American.Psycho")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "brave",
|
|
|
|
year: 2006,
|
|
|
|
is3D: true,
|
|
|
|
format3D: "sbs")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "300",
|
|
|
|
year: 2006)
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "300",
|
|
|
|
year: 2006,
|
|
|
|
is3D: true,
|
|
|
|
format3D: "sbs")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc",
|
|
|
|
container: "disc",
|
|
|
|
name: "brave",
|
|
|
|
year: 2006,
|
|
|
|
isStub: true,
|
|
|
|
stubType: "bluray")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc",
|
|
|
|
container: "disc",
|
|
|
|
name: "300",
|
|
|
|
year: 2006,
|
|
|
|
isStub: true,
|
|
|
|
stubType: "bluray")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/Brave (2007)/Brave (2006).bluray.disc",
|
|
|
|
container: "disc",
|
|
|
|
name: "Brave",
|
|
|
|
year: 2006,
|
|
|
|
isStub: true,
|
|
|
|
stubType: "bluray")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/300 (2007)/300 (2006).bluray.disc",
|
|
|
|
container: "disc",
|
|
|
|
name: "300",
|
|
|
|
year: 2006,
|
|
|
|
isStub: true,
|
|
|
|
stubType: "bluray")
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/300 (2007)/300 (2006)-trailer.mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "300",
|
|
|
|
year: 2006,
|
|
|
|
extraType: ExtraType.Trailer)
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "Brave",
|
|
|
|
year: 2006,
|
|
|
|
extraType: ExtraType.Trailer)
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/300 (2007)/300 (2006).mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "300",
|
|
|
|
year: 2006)
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "Bad Boys",
|
|
|
|
year: 1995)
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
new VideoFileInfo(
|
|
|
|
path: @"/server/Movies/Brave (2007)/Brave (2006).mkv",
|
|
|
|
container: "mkv",
|
|
|
|
name: "Brave",
|
|
|
|
year: 2006)
|
2020-04-25 13:29:59 +00:00
|
|
|
};
|
2020-05-04 03:44:18 +00:00
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-20 18:27:37 +00:00
|
|
|
new VideoFileInfo(
|
2021-05-19 06:51:46 +00:00
|
|
|
path: @"/server/Movies/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - JEFF/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - JEFF.mp4",
|
2020-11-20 18:27:37 +00:00
|
|
|
container: "mp4",
|
|
|
|
name: "Rain Man",
|
|
|
|
year: 1988)
|
2020-05-04 03:44:18 +00:00
|
|
|
};
|
2020-04-21 10:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
2021-03-09 02:04:47 +00:00
|
|
|
[MemberData(nameof(ResolveFile_ValidFileNameTestData))]
|
2020-04-21 10:54:04 +00:00
|
|
|
public void ResolveFile_ValidFileName_Success(VideoFileInfo expectedResult)
|
2020-04-21 10:11:55 +00:00
|
|
|
{
|
2021-05-23 22:30:41 +00:00
|
|
|
var result = VideoResolver.ResolveFile(expectedResult.Path, _namingOptions);
|
2020-04-21 10:11:55 +00:00
|
|
|
|
2020-04-21 10:54:04 +00:00
|
|
|
Assert.NotNull(result);
|
2021-05-23 22:30:41 +00:00
|
|
|
Assert.Equal(result!.Path, expectedResult.Path);
|
|
|
|
Assert.Equal(result.Container, expectedResult.Container);
|
|
|
|
Assert.Equal(result.Name, expectedResult.Name);
|
|
|
|
Assert.Equal(result.Year, expectedResult.Year);
|
|
|
|
Assert.Equal(result.ExtraType, expectedResult.ExtraType);
|
|
|
|
Assert.Equal(result.Format3D, expectedResult.Format3D);
|
|
|
|
Assert.Equal(result.Is3D, expectedResult.Is3D);
|
|
|
|
Assert.Equal(result.IsStub, expectedResult.IsStub);
|
|
|
|
Assert.Equal(result.StubType, expectedResult.StubType);
|
|
|
|
Assert.Equal(result.IsDirectory, expectedResult.IsDirectory);
|
|
|
|
Assert.Equal(result.FileNameWithoutExtension.ToString(), expectedResult.FileNameWithoutExtension.ToString());
|
|
|
|
Assert.Equal(result.ToString(), expectedResult.ToString());
|
2020-11-05 15:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ResolveFile_EmptyPath()
|
|
|
|
{
|
2021-05-23 22:30:41 +00:00
|
|
|
var result = VideoResolver.ResolveFile(string.Empty, _namingOptions);
|
2020-11-05 15:59:15 +00:00
|
|
|
|
|
|
|
Assert.Null(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ResolveDirectoryTest()
|
|
|
|
{
|
|
|
|
var paths = new[]
|
|
|
|
{
|
|
|
|
@"/Server/Iron Man",
|
|
|
|
@"Batman",
|
|
|
|
string.Empty
|
|
|
|
};
|
|
|
|
|
2021-05-23 22:30:41 +00:00
|
|
|
var results = paths.Select(path => VideoResolver.ResolveDirectory(path, _namingOptions)).ToList();
|
2020-11-05 15:59:15 +00:00
|
|
|
|
|
|
|
Assert.Equal(3, results.Count);
|
|
|
|
Assert.NotNull(results[0]);
|
|
|
|
Assert.NotNull(results[1]);
|
|
|
|
Assert.Null(results[2]);
|
2021-05-19 06:51:46 +00:00
|
|
|
foreach (var result in results)
|
|
|
|
{
|
|
|
|
Assert.Null(result?.Container);
|
|
|
|
}
|
2019-12-06 19:40:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|