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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
using System;
using System.Linq;
using Emby.Naming.AudioBook;
using Emby.Naming.Common;
using MediaBrowser.Model.IO;
using Xunit;
namespace Jellyfin.Naming.Tests.AudioBook
{
public class AudioBookListResolverTests
{
private readonly NamingOptions _namingOptions = new NamingOptions();
[Fact]
public void TestStackAndExtras()
{
// No stacking here because there is no part/disc/etc
var files = new[]
{
"Harry Potter and the Deathly Hallows/Part 1.mp3",
"Harry Potter and the Deathly Hallows/Part 2.mp3",
"Harry Potter and the Deathly Hallows/Extra.mp3",
"Batman/Chapter 1.mp3",
"Batman/Chapter 2.mp3",
"Batman/Chapter 3.mp3",
"Badman/audiobook.mp3",
"Badman/extra.mp3",
"Superman (2020)/Part 1.mp3",
"Superman (2020)/extra.mp3",
"Ready Player One (2020)/audiobook.mp3",
"Ready Player One (2020)/extra.mp3",
".mp3"
};
var resolver = GetResolver();
var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
})).ToList();
Assert.Equal(5, result.Count);
Assert.Equal(2, result[0].Files.Count);
Assert.Single(result[0].Extras);
Assert.Equal("Harry Potter and the Deathly Hallows", result[0].Name);
Assert.Equal(3, result[1].Files.Count);
Assert.Empty(result[1].Extras);
Assert.Equal("Batman", result[1].Name);
Assert.Single(result[2].Files);
Assert.Single(result[2].Extras);
Assert.Equal("Badman", result[2].Name);
Assert.Single(result[3].Files);
Assert.Single(result[3].Extras);
Assert.Equal("Superman", result[3].Name);
Assert.Single(result[4].Files);
Assert.Single(result[4].Extras);
Assert.Equal("Ready Player One", result[4].Name);
}
[Fact]
public void TestAlternativeVersions()
{
var files = new[]
{
"Harry Potter and the Deathly Hallows/Chapter 1.ogg",
"Harry Potter and the Deathly Hallows/Chapter 1.mp3",
"Deadpool.mp3",
"Deadpool [HQ].mp3",
"Superman/audiobook.mp3",
"Superman/Superman.mp3",
"Superman/Superman [HQ].mp3",
"Superman/extra.mp3",
"Batman/ Chapter 1 .mp3",
"Batman/Chapter 1[loss-less].mp3"
};
var resolver = GetResolver();
var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
})).ToList();
Assert.Equal(5, result.Count);
// HP - Same name so we don't care which file is alternative
Assert.Single(result[0].AlternateVersions);
// DP
Assert.Empty(result[1].AlternateVersions);
// DP HQ (directory missing so we do not group deadpools together)
Assert.Empty(result[2].AlternateVersions);
// Superman
// Priority:
// 1. Name
// 2. audiobook
// 3. Names with modifiers
Assert.Equal(2, result[3].AlternateVersions.Count);
var paths = result[3].AlternateVersions.Select(x => x.Path).ToList();
Assert.Contains("Superman/audiobook.mp3", paths);
Assert.Contains("Superman/Superman [HQ].mp3", paths);
// Batman
Assert.Single(result[4].AlternateVersions);
}
[Fact]
public void TestNameYearExtraction()
{
var data = new[]
{
new NameYearPath
{
Name = "Harry Potter and the Deathly Hallows",
Path = "Harry Potter and the Deathly Hallows (2007)/Chapter 1.ogg",
Year = 2007
},
new NameYearPath
{
Name = "Batman",
Path = "Batman (2020).ogg",
Year = 2020
},
new NameYearPath
{
Name = "Batman",
Path = "Batman( 2021 ).mp3",
Year = 2021
},
new NameYearPath
{
Name = "Batman(*2021*)",
Path = "Batman(*2021*).mp3",
Year = null
},
new NameYearPath
{
Name = "Batman",
Path = "Batman.mp3",
Year = null
},
new NameYearPath
{
Name = "+ Batman .",
Path = " + Batman . .mp3",
Year = null
},
new NameYearPath
{
Name = " ",
Path = " .mp3",
Year = null
}
};
var resolver = GetResolver();
var result = resolver.Resolve(data.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i.Path
})).ToList();
Assert.Equal(data.Length, result.Count);
for (int i = 0; i < data.Length; i++)
{
Assert.Equal(data[i].Name, result[i].Name);
Assert.Equal(data[i].Year, result[i].Year);
}
}
[Fact]
public void TestWithMetadata()
{
var files = new[]
{
"Harry Potter and the Deathly Hallows/Chapter 1.ogg",
"Harry Potter and the Deathly Hallows/Harry Potter and the Deathly Hallows.nfo"
};
var resolver = GetResolver();
var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
}));
Assert.Single(result);
}
[Fact]
public void TestWithExtra()
{
var files = new[]
{
"Harry Potter and the Deathly Hallows/Chapter 1.mp3",
"Harry Potter and the Deathly Hallows/Harry Potter and the Deathly Hallows trailer.mp3"
};
var resolver = GetResolver();
var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
})).ToList();
Assert.Single(result);
}
[Fact]
public void TestWithoutFolder()
{
var files = new[]
{
"Harry Potter and the Deathly Hallows trailer.mp3"
};
var resolver = GetResolver();
var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
})).ToList();
Assert.Single(result);
}
[Fact]
public void TestEmpty()
{
var files = Array.Empty<string>();
var resolver = GetResolver();
var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
{
IsDirectory = false,
FullName = i
})).ToList();
Assert.Empty(result);
}
private AudioBookListResolver GetResolver()
{
return new AudioBookListResolver(_namingOptions);
}
internal struct NameYearPath
{
public string Name;
public string Path;
public int? Year;
}
}
}
|