1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
using Emby.Naming.Common;
using Emby.Naming.Video;
using MediaBrowser.Model.Entities;
using Xunit;
using MediaType = Emby.Naming.Common.MediaType;
namespace Jellyfin.Naming.Tests.Video
{
public class ExtraTests
{
private readonly NamingOptions _videoOptions = new NamingOptions();
// 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);
Test("300-trailer.mp4", ExtraType.Trailer);
Test("300.trailer.mp4", ExtraType.Trailer);
Test("300_trailer.mp4", ExtraType.Trailer);
Test("300 - trailer.mp4", ExtraType.Trailer);
Test("theme.mp3", ExtraType.ThemeSong);
}
[Fact]
public void TestExpandedExtras()
{
Test("trailer.mp4", ExtraType.Trailer);
Test("trailer.mp3", null);
Test("300-trailer.mp4", ExtraType.Trailer);
Test("stuff trailerthings.mkv", null);
Test("theme.mp3", ExtraType.ThemeSong);
Test("theme.mkv", null);
Test("300-scene.mp4", ExtraType.Scene);
Test("300-scene2.mp4", ExtraType.Scene);
Test("300-clip.mp4", ExtraType.Clip);
Test("300-deleted.mp4", ExtraType.DeletedScene);
Test("300-deletedscene.mp4", ExtraType.DeletedScene);
Test("300-interview.mp4", ExtraType.Interview);
Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes);
Test("300-featurette.mp4", ExtraType.Featurette);
Test("300-short.mp4", ExtraType.Short);
Test("300-extra.mp4", ExtraType.Unknown);
Test("300-other.mp4", ExtraType.Unknown);
}
[Theory]
[InlineData(ExtraType.ThemeSong, "theme-music")]
public void TestDirectoriesAudioExtras(ExtraType type, string dirName)
{
Test(dirName + "/300.mp3", type);
Test("300/" + dirName + "/something.mp3", type);
Test("/data/something/Movies/300/" + dirName + "/whoknows.mp3", type);
}
[Theory]
[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.Short, "shorts")]
[InlineData(ExtraType.Trailer, "trailers")]
[InlineData(ExtraType.Featurette, "featurettes")]
[InlineData(ExtraType.Clip, "clips")]
[InlineData(ExtraType.ThemeVideo, "backdrops")]
[InlineData(ExtraType.Unknown, "extra")]
[InlineData(ExtraType.Unknown, "extras")]
[InlineData(ExtraType.Unknown, "other")]
public void TestDirectoriesVideoExtras(ExtraType type, string dirName)
{
Test(dirName + "/300.mp4", type);
Test("300/" + dirName + "/something.mkv", type);
Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type);
}
[Theory]
[InlineData("gibberish")]
[InlineData("not a scene")]
[InlineData("The Big Short")]
public void TestNonExtraDirectories(string dirName)
{
Test(dirName + "/300.mp4", null);
Test("300/" + dirName + "/something.mkv", null);
Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null);
Test("/data/something/Movies/" + dirName + "/" + dirName + ".mp4", null);
}
[Theory]
[InlineData(ExtraType.ThemeSong, "theme-music")]
public void TestTopLevelDirectoriesWithAudioExtraNames(ExtraType typicalType, string dirName)
{
string libraryRoot = "/data/something/" + dirName;
TestWithLibraryRoot(libraryRoot + "/300.mp3", libraryRoot, null);
TestWithLibraryRoot(libraryRoot + "/300/" + dirName + "/something.mp3", libraryRoot, typicalType);
}
[Theory]
[InlineData(ExtraType.Trailer, "trailers")]
[InlineData(ExtraType.ThemeVideo, "backdrops")]
[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.Short, "shorts")]
[InlineData(ExtraType.Featurette, "featurettes")]
[InlineData(ExtraType.Unknown, "extras")]
[InlineData(ExtraType.Unknown, "extra")]
[InlineData(ExtraType.Unknown, "other")]
[InlineData(ExtraType.Clip, "clips")]
public void TestTopLevelDirectoriesWithVideoExtraNames(ExtraType typicalType, string dirName)
{
string libraryRoot = "/data/something/" + dirName;
TestWithLibraryRoot(libraryRoot + "/300.mp4", libraryRoot, null);
TestWithLibraryRoot(libraryRoot + "/300/" + dirName + "/something.mkv", libraryRoot, typicalType);
}
[Fact]
public void TestSample()
{
Test("sample.mp4", ExtraType.Sample);
Test("300-sample.mp4", ExtraType.Sample);
Test("300.sample.mp4", ExtraType.Sample);
Test("300_sample.mp4", ExtraType.Sample);
Test("300 - sample.mp4", ExtraType.Sample);
}
[Fact]
public void TestSuffixPartOfTitle()
{
Test("I Live In A Trailer.mp4", null);
Test("The DNA Sample.mp4", null);
}
private void Test(string input, ExtraType? expectedType)
{
var extraType = ExtraRuleResolver.GetExtraInfo(input, _videoOptions).ExtraType;
Assert.Equal(expectedType, extraType);
}
private void TestWithLibraryRoot(string input, string libraryRoot, ExtraType? expectedType)
{
var extraType = ExtraRuleResolver.GetExtraInfo(input, _videoOptions, libraryRoot).ExtraType;
Assert.Equal(expectedType, extraType);
}
[Fact]
public void TestExtraInfo_InvalidRuleType()
{
var rule = new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, @"([eE]x(tra)?\.\w+)", MediaType.Video);
var options = new NamingOptions { VideoExtraRules = new[] { rule } };
var res = ExtraRuleResolver.GetExtraInfo("extra.mp4", options);
Assert.Equal(rule, res.Rule);
}
}
}
|