VideoListResolverTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. using System;
  2. using System.Linq;
  3. using Emby.Naming.Common;
  4. using Emby.Naming.Video;
  5. using MediaBrowser.Model.IO;
  6. using Xunit;
  7. namespace Jellyfin.Naming.Tests.Video
  8. {
  9. public class VideoListResolverTests
  10. {
  11. private readonly VideoListResolver _videoListResolver = new VideoListResolver(new NamingOptions());
  12. [Fact]
  13. public void TestStackAndExtras()
  14. {
  15. // No stacking here because there is no part/disc/etc
  16. var files = new[]
  17. {
  18. "Harry Potter and the Deathly Hallows-trailer.mkv",
  19. "Harry Potter and the Deathly Hallows.trailer.mkv",
  20. "Harry Potter and the Deathly Hallows part1.mkv",
  21. "Harry Potter and the Deathly Hallows part2.mkv",
  22. "Harry Potter and the Deathly Hallows part3.mkv",
  23. "Harry Potter and the Deathly Hallows part4.mkv",
  24. "Batman-deleted.mkv",
  25. "Batman-sample.mkv",
  26. "Batman-trailer.mkv",
  27. "Batman part1.mkv",
  28. "Batman part2.mkv",
  29. "Batman part3.mkv",
  30. "Avengers.mkv",
  31. "Avengers-trailer.mkv",
  32. // Despite having a keyword in the name that will return an ExtraType, there's no original video to match it to
  33. // So this is just a standalone video
  34. "trailer.mkv",
  35. // Same as above
  36. "WillyWonka-trailer.mkv"
  37. };
  38. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  39. {
  40. IsDirectory = false,
  41. FullName = i
  42. }).ToList()).ToList();
  43. Assert.Equal(5, result.Count);
  44. var batman = result.FirstOrDefault(x => string.Equals(x.Name, "Batman", StringComparison.Ordinal));
  45. Assert.NotNull(batman);
  46. Assert.Equal(3, batman!.Files.Count);
  47. Assert.Equal(3, batman!.Extras.Count);
  48. var harry = result.FirstOrDefault(x => string.Equals(x.Name, "Harry Potter and the Deathly Hallows", StringComparison.Ordinal));
  49. Assert.NotNull(harry);
  50. Assert.Equal(4, harry!.Files.Count);
  51. Assert.Equal(2, harry!.Extras.Count);
  52. }
  53. [Fact]
  54. public void TestWithMetadata()
  55. {
  56. var files = new[]
  57. {
  58. "300.mkv",
  59. "300.nfo"
  60. };
  61. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  62. {
  63. IsDirectory = false,
  64. FullName = i
  65. }).ToList()).ToList();
  66. Assert.Single(result);
  67. }
  68. [Fact]
  69. public void TestWithExtra()
  70. {
  71. var files = new[]
  72. {
  73. "300.mkv",
  74. "300 trailer.mkv"
  75. };
  76. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  77. {
  78. IsDirectory = false,
  79. FullName = i
  80. }).ToList()).ToList();
  81. Assert.Single(result);
  82. }
  83. [Fact]
  84. public void TestVariationWithFolderName()
  85. {
  86. var files = new[]
  87. {
  88. "X-Men Days of Future Past - 1080p.mkv",
  89. "X-Men Days of Future Past-trailer.mp4"
  90. };
  91. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  92. {
  93. IsDirectory = false,
  94. FullName = i
  95. }).ToList()).ToList();
  96. Assert.Single(result);
  97. }
  98. [Fact]
  99. public void TestTrailer2()
  100. {
  101. var files = new[]
  102. {
  103. "X-Men Days of Future Past - 1080p.mkv",
  104. "X-Men Days of Future Past-trailer.mp4",
  105. "X-Men Days of Future Past-trailer2.mp4"
  106. };
  107. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  108. {
  109. IsDirectory = false,
  110. FullName = i
  111. }).ToList()).ToList();
  112. Assert.Single(result);
  113. }
  114. [Fact]
  115. public void TestDifferentNames()
  116. {
  117. var files = new[]
  118. {
  119. "Looper (2012)-trailer.mkv",
  120. "Looper.2012.bluray.720p.x264.mkv"
  121. };
  122. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  123. {
  124. IsDirectory = false,
  125. FullName = i
  126. }).ToList()).ToList();
  127. Assert.Single(result);
  128. }
  129. [Fact]
  130. public void TestSeparateFiles()
  131. {
  132. // These should be considered separate, unrelated videos
  133. var files = new[]
  134. {
  135. "My video 1.mkv",
  136. "My video 2.mkv",
  137. "My video 3.mkv",
  138. "My video 4.mkv",
  139. "My video 5.mkv"
  140. };
  141. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  142. {
  143. IsDirectory = false,
  144. FullName = i
  145. }).ToList()).ToList();
  146. Assert.Equal(5, result.Count);
  147. }
  148. [Fact]
  149. public void TestMultiDisc()
  150. {
  151. var files = new[]
  152. {
  153. @"M:/Movies (DVD)/Movies (Musical)/Sound of Music (1965)/Sound of Music Disc 1",
  154. @"M:/Movies (DVD)/Movies (Musical)/Sound of Music (1965)/Sound of Music Disc 2"
  155. };
  156. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  157. {
  158. IsDirectory = true,
  159. FullName = i
  160. }).ToList()).ToList();
  161. Assert.Single(result);
  162. }
  163. [Fact]
  164. public void TestPoundSign()
  165. {
  166. // These should be considered separate, unrelated videos
  167. var files = new[]
  168. {
  169. @"My movie #1.mp4",
  170. @"My movie #2.mp4"
  171. };
  172. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  173. {
  174. IsDirectory = true,
  175. FullName = i
  176. }).ToList()).ToList();
  177. Assert.Equal(2, result.Count);
  178. }
  179. [Fact]
  180. public void TestStackedWithTrailer()
  181. {
  182. var files = new[]
  183. {
  184. @"No (2012) part1.mp4",
  185. @"No (2012) part2.mp4",
  186. @"No (2012) part1-trailer.mp4"
  187. };
  188. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  189. {
  190. IsDirectory = false,
  191. FullName = i
  192. }).ToList()).ToList();
  193. Assert.Single(result);
  194. }
  195. [Fact]
  196. public void TestStackedWithTrailer2()
  197. {
  198. var files = new[]
  199. {
  200. @"No (2012) part1.mp4",
  201. @"No (2012) part2.mp4",
  202. @"No (2012)-trailer.mp4"
  203. };
  204. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  205. {
  206. IsDirectory = false,
  207. FullName = i
  208. }).ToList()).ToList();
  209. Assert.Single(result);
  210. }
  211. [Fact]
  212. public void TestExtrasByFolderName()
  213. {
  214. var files = new[]
  215. {
  216. @"/Movies/Top Gun (1984)/movie.mp4",
  217. @"/Movies/Top Gun (1984)/Top Gun (1984)-trailer.mp4",
  218. @"/Movies/Top Gun (1984)/Top Gun (1984)-trailer2.mp4",
  219. @"trailer.mp4"
  220. };
  221. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  222. {
  223. IsDirectory = false,
  224. FullName = i
  225. }).ToList()).ToList();
  226. Assert.Single(result);
  227. }
  228. [Fact]
  229. public void TestDoubleTags()
  230. {
  231. var files = new[]
  232. {
  233. @"/MCFAMILY-PC/Private3$/Heterosexual/Breast In Class 2 Counterfeit Racks (2011)/Breast In Class 2 Counterfeit Racks (2011) Disc 1 cd1.avi",
  234. @"/MCFAMILY-PC/Private3$/Heterosexual/Breast In Class 2 Counterfeit Racks (2011)/Breast In Class 2 Counterfeit Racks (2011) Disc 1 cd2.avi",
  235. @"/MCFAMILY-PC/Private3$/Heterosexual/Breast In Class 2 Counterfeit Racks (2011)/Breast In Class 2 Disc 2 cd1.avi",
  236. @"/MCFAMILY-PC/Private3$/Heterosexual/Breast In Class 2 Counterfeit Racks (2011)/Breast In Class 2 Disc 2 cd2.avi"
  237. };
  238. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  239. {
  240. IsDirectory = false,
  241. FullName = i
  242. }).ToList()).ToList();
  243. Assert.Equal(2, result.Count);
  244. }
  245. [Fact]
  246. public void TestArgumentOutOfRangeException()
  247. {
  248. var files = new[]
  249. {
  250. @"/nas-markrobbo78/Videos/INDEX HTPC/Movies/Watched/3 - ACTION/Argo (2012)/movie.mkv"
  251. };
  252. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  253. {
  254. IsDirectory = false,
  255. FullName = i
  256. }).ToList()).ToList();
  257. Assert.Single(result);
  258. }
  259. [Fact]
  260. public void TestColony()
  261. {
  262. var files = new[]
  263. {
  264. @"The Colony.mkv"
  265. };
  266. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  267. {
  268. IsDirectory = false,
  269. FullName = i
  270. }).ToList()).ToList();
  271. Assert.Single(result);
  272. }
  273. [Fact]
  274. public void TestFourSisters()
  275. {
  276. var files = new[]
  277. {
  278. @"Four Sisters and a Wedding - A.avi",
  279. @"Four Sisters and a Wedding - B.avi"
  280. };
  281. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  282. {
  283. IsDirectory = false,
  284. FullName = i
  285. }).ToList()).ToList();
  286. Assert.Single(result);
  287. }
  288. [Fact]
  289. public void TestFourRooms()
  290. {
  291. var files = new[]
  292. {
  293. @"Four Rooms - A.avi",
  294. @"Four Rooms - A.mp4"
  295. };
  296. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  297. {
  298. IsDirectory = false,
  299. FullName = i
  300. }).ToList()).ToList();
  301. Assert.Equal(2, result.Count);
  302. }
  303. [Fact]
  304. public void TestMovieTrailer()
  305. {
  306. var files = new[]
  307. {
  308. @"/Server/Despicable Me/Despicable Me (2010).mkv",
  309. @"/Server/Despicable Me/movie-trailer.mkv"
  310. };
  311. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  312. {
  313. IsDirectory = false,
  314. FullName = i
  315. }).ToList()).ToList();
  316. Assert.Single(result);
  317. }
  318. [Fact]
  319. public void TestTrailerFalsePositives()
  320. {
  321. var files = new[]
  322. {
  323. @"/Server/Despicable Me/Skyscraper (2018) - Big Game Spot.mkv",
  324. @"/Server/Despicable Me/Skyscraper (2018) - Trailer.mkv",
  325. @"/Server/Despicable Me/Baywatch (2017) - Big Game Spot.mkv",
  326. @"/Server/Despicable Me/Baywatch (2017) - Trailer.mkv"
  327. };
  328. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  329. {
  330. IsDirectory = false,
  331. FullName = i
  332. }).ToList()).ToList();
  333. Assert.Equal(4, result.Count);
  334. }
  335. [Fact]
  336. public void TestSubfolders()
  337. {
  338. var files = new[]
  339. {
  340. @"/Movies/Despicable Me/Despicable Me.mkv",
  341. @"/Movies/Despicable Me/trailers/trailer.mkv"
  342. };
  343. var result = _videoListResolver.Resolve(files.Select(i => new FileSystemMetadata
  344. {
  345. IsDirectory = false,
  346. FullName = i
  347. }).ToList()).ToList();
  348. Assert.Single(result);
  349. }
  350. [Fact]
  351. public void TestDirectoryStack()
  352. {
  353. var stack = new FileStack();
  354. Assert.False(stack.ContainsFile("XX", true));
  355. }
  356. }
  357. }