jellyfin/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs

125 lines
4.6 KiB
C#
Raw Normal View History

2020-11-05 08:59:15 -07:00
using System;
using Emby.Naming.Common;
2019-12-06 12:40:06 -07:00
using Emby.Naming.Video;
using MediaBrowser.Model.Entities;
using Xunit;
2020-11-05 08:59:15 -07:00
using MediaType = Emby.Naming.Common.MediaType;
2019-12-06 12:40:06 -07:00
namespace Jellyfin.Naming.Tests.Video
{
2020-04-21 03:11:55 -07:00
public class ExtraTests
2019-12-06 12:40:06 -07:00
{
private readonly NamingOptions _videoOptions = new NamingOptions();
2019-12-06 12:40:06 -07:00
// Requirements
// movie-deleted = ExtraType deletedscene
// All of the above rules should be configurable through the options objects (ideally, even the ExtraTypes)
[Fact]
public void TestKodiExtras()
{
Test("trailer.mp4", ExtraType.Trailer, _videoOptions);
Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions);
2019-12-06 12:40:06 -07:00
Test("theme.mp3", ExtraType.ThemeSong, _videoOptions);
2019-12-06 12:40:06 -07:00
}
[Fact]
public void TestExpandedExtras()
{
Test("trailer.mp4", ExtraType.Trailer, _videoOptions);
Test("trailer.mp3", null, _videoOptions);
Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions);
2019-12-06 12:40:06 -07:00
Test("theme.mp3", ExtraType.ThemeSong, _videoOptions);
Test("theme.mkv", null, _videoOptions);
2019-12-06 12:40:06 -07:00
Test("300-scene.mp4", ExtraType.Scene, _videoOptions);
Test("300-scene2.mp4", ExtraType.Scene, _videoOptions);
Test("300-clip.mp4", ExtraType.Clip, _videoOptions);
2019-12-06 12:40:06 -07:00
Test("300-deleted.mp4", ExtraType.DeletedScene, _videoOptions);
Test("300-deletedscene.mp4", ExtraType.DeletedScene, _videoOptions);
Test("300-interview.mp4", ExtraType.Interview, _videoOptions);
Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes, _videoOptions);
2019-12-06 12:40:06 -07:00
}
[Theory]
2020-09-20 05:02:41 -07:00
[InlineData(ExtraType.BehindTheScenes, "behind the scenes")]
[InlineData(ExtraType.DeletedScene, "deleted scenes")]
[InlineData(ExtraType.Interview, "interviews")]
[InlineData(ExtraType.Scene, "scenes")]
[InlineData(ExtraType.Sample, "samples")]
[InlineData(ExtraType.Clip, "shorts")]
[InlineData(ExtraType.Clip, "featurettes")]
[InlineData(ExtraType.Unknown, "extras")]
public void TestDirectories(ExtraType type, string dirName)
{
Test(dirName + "/300.mp4", type, _videoOptions);
Test("300/" + dirName + "/something.mkv", type, _videoOptions);
Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type, _videoOptions);
}
[Theory]
[InlineData("gibberish")]
[InlineData("not a scene")]
[InlineData("The Big Short")]
public void TestNonExtraDirectories(string dirName)
{
Test(dirName + "/300.mp4", null, _videoOptions);
Test("300/" + dirName + "/something.mkv", null, _videoOptions);
Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null, _videoOptions);
Test("/data/something/Movies/" + dirName + "/" + dirName + ".mp4", null, _videoOptions);
}
2019-12-06 12:40:06 -07:00
[Fact]
public void TestSample()
{
Test("300-sample.mp4", ExtraType.Sample, _videoOptions);
2019-12-06 12:40:06 -07:00
}
private void Test(string input, ExtraType? expectedType, NamingOptions videoOptions)
{
var parser = GetExtraTypeParser(videoOptions);
var extraType = parser.GetExtraInfo(input).ExtraType;
if (expectedType == null)
{
Assert.Null(extraType);
}
else
{
Assert.Equal(expectedType, extraType);
}
}
2020-11-05 08:59:15 -07:00
[Fact]
public void TestExtraInfo_InvalidRuleMediaType()
{
var options = new NamingOptions { VideoExtraRules = new[] { new ExtraRule(ExtraType.Unknown, ExtraRuleType.DirectoryName, " ", MediaType.Photo) } };
Assert.Throws<InvalidOperationException>(() => GetExtraTypeParser(options).GetExtraInfo("sample.jpg"));
}
[Fact]
public void TestExtraInfo_InvalidRuleType()
{
var options = new NamingOptions { VideoExtraRules = new[] { new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, " ", MediaType.Video) } };
Assert.Throws<InvalidOperationException>(() => GetExtraTypeParser(options).GetExtraInfo("sample.mp4"));
}
[Fact]
public void TestFlagsParser()
{
var flags = new FlagParser(_videoOptions).GetFlags(string.Empty);
Assert.Empty(flags);
}
2019-12-06 12:40:06 -07:00
private ExtraResolver GetExtraTypeParser(NamingOptions videoOptions)
{
return new ExtraResolver(videoOptions);
}
}
}