AudioBookListResolverTests.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Linq;
  3. using Emby.Naming.AudioBook;
  4. using Emby.Naming.Common;
  5. using MediaBrowser.Model.IO;
  6. using Xunit;
  7. namespace Jellyfin.Naming.Tests.AudioBook
  8. {
  9. public class AudioBookListResolverTests
  10. {
  11. private readonly NamingOptions _namingOptions = 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/Part 1.mp3",
  19. "Harry Potter and the Deathly Hallows/Part 2.mp3",
  20. "Harry Potter and the Deathly Hallows/book.nfo",
  21. "Batman/Chapter 1.mp3",
  22. "Batman/Chapter 2.mp3",
  23. "Batman/Chapter 3.mp3",
  24. };
  25. var resolver = GetResolver();
  26. var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
  27. {
  28. IsDirectory = false,
  29. FullName = i
  30. })).ToList();
  31. Assert.Equal(2, result[0].Files.Count);
  32. // Assert.Empty(result[0].Extras); FIXME: AudioBookListResolver should resolve extra files properly
  33. Assert.Equal("Harry Potter and the Deathly Hallows", result[0].Name);
  34. Assert.Equal(3, result[1].Files.Count);
  35. Assert.Empty(result[1].Extras);
  36. Assert.Equal("Batman", result[1].Name);
  37. }
  38. [Fact]
  39. public void TestAlternativeVersions()
  40. {
  41. var files = new[]
  42. {
  43. "Harry Potter and the Deathly Hallows/Chapter 1.ogg",
  44. "Harry Potter and the Deathly Hallows/Chapter 1.mp3",
  45. "Deadpool.ogg",
  46. "Deadpool.mp3",
  47. "Batman/Chapter 1.mp3"
  48. };
  49. var resolver = GetResolver();
  50. var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
  51. {
  52. IsDirectory = false,
  53. FullName = i
  54. })).ToList();
  55. Assert.Equal(3, result[0].Files.Count);
  56. Assert.NotEmpty(result[0].AlternateVersions);
  57. Assert.NotEmpty(result[1].AlternateVersions);
  58. Assert.Empty(result[2].AlternateVersions);
  59. }
  60. [Fact]
  61. public void TestYearExtraction()
  62. {
  63. var files = new[]
  64. {
  65. "Harry Potter and the Deathly Hallows (2007)/Chapter 1.ogg",
  66. "Harry Potter and the Deathly Hallows (2007)/Chapter 2.mp3",
  67. "Batman (2020).ogg",
  68. "Batman(2021).mp3",
  69. "Batman.mp3"
  70. };
  71. var resolver = GetResolver();
  72. var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
  73. {
  74. IsDirectory = false,
  75. FullName = i
  76. })).ToList();
  77. Assert.Equal(3, result[0].Files.Count);
  78. Assert.Equal(2007, result[0].Year);
  79. Assert.Equal(2020, result[1].Year);
  80. Assert.Equal(2021, result[2].Year);
  81. Assert.Null(result[2].Year);
  82. }
  83. [Fact]
  84. public void TestWithMetadata()
  85. {
  86. var files = new[]
  87. {
  88. "Harry Potter and the Deathly Hallows/Chapter 1.ogg",
  89. "Harry Potter and the Deathly Hallows/Harry Potter and the Deathly Hallows.nfo"
  90. };
  91. var resolver = GetResolver();
  92. var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
  93. {
  94. IsDirectory = false,
  95. FullName = i
  96. }));
  97. Assert.Single(result);
  98. }
  99. [Fact]
  100. public void TestWithExtra()
  101. {
  102. var files = new[]
  103. {
  104. "Harry Potter and the Deathly Hallows/Chapter 1.mp3",
  105. "Harry Potter and the Deathly Hallows/Harry Potter and the Deathly Hallows trailer.mp3"
  106. };
  107. var resolver = GetResolver();
  108. var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
  109. {
  110. IsDirectory = false,
  111. FullName = i
  112. })).ToList();
  113. Assert.Single(result);
  114. }
  115. [Fact]
  116. public void TestWithoutFolder()
  117. {
  118. var files = new[]
  119. {
  120. "Harry Potter and the Deathly Hallows trailer.mp3"
  121. };
  122. var resolver = GetResolver();
  123. var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
  124. {
  125. IsDirectory = false,
  126. FullName = i
  127. })).ToList();
  128. Assert.Single(result);
  129. }
  130. [Fact]
  131. public void TestEmpty()
  132. {
  133. var files = Array.Empty<string>();
  134. var resolver = GetResolver();
  135. var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
  136. {
  137. IsDirectory = false,
  138. FullName = i
  139. })).ToList();
  140. Assert.Empty(result);
  141. }
  142. private AudioBookListResolver GetResolver()
  143. {
  144. return new AudioBookListResolver(_namingOptions);
  145. }
  146. }
  147. }