AudioResolverTests.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Linq;
  2. using Emby.Naming.Common;
  3. using Emby.Server.Implementations.Library.Resolvers.Audio;
  4. using MediaBrowser.Controller.Entities.Audio;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Model.IO;
  7. using Moq;
  8. using Xunit;
  9. namespace Jellyfin.Server.Implementations.Tests.Library;
  10. public class AudioResolverTests
  11. {
  12. private static readonly NamingOptions _namingOptions = new();
  13. [Theory]
  14. [InlineData("words.mp3")] // single non-tagged file
  15. [InlineData("chapter 01.mp3")]
  16. [InlineData("part 1.mp3")]
  17. [InlineData("chapter 01.mp3", "non-media.txt")]
  18. [InlineData("title.mp3", "title.epub")]
  19. [InlineData("01.mp3", "subdirectory/")] // single media file with sub-directory - note that this will hide any contents in the subdirectory
  20. public void Resolve_AudiobookDirectory_SingleResult(params string[] children)
  21. {
  22. var resolved = TestResolveChildren("/parent/title", children);
  23. Assert.NotNull(resolved);
  24. }
  25. [Theory]
  26. /* Results that can't be displayed as an audio book. */
  27. [InlineData] // no contents
  28. [InlineData("subdirectory/")]
  29. [InlineData("non-media.txt")]
  30. /* Names don't indicate parts of a single book. */
  31. [InlineData("Name.mp3", "Another Name.mp3")]
  32. /* Results that are an audio book but not currently navigable as such (multiple chapters and/or parts). */
  33. [InlineData("01.mp3", "02.mp3")]
  34. [InlineData("chapter 01.mp3", "chapter 02.mp3")]
  35. [InlineData("part 1.mp3", "part 2.mp3")]
  36. [InlineData("chapter 01 part 01.mp3", "chapter 01 part 02.mp3")]
  37. /* Mismatched chapters, parts, and named files. */
  38. [InlineData("chapter 01.mp3", "part 2.mp3")]
  39. [InlineData("book title.mp3", "chapter name.mp3")] // "book title" resolves as alternate version of book based on directory name
  40. [InlineData("01 Content.mp3", "01 Credits.mp3")] // resolves as alternate versions of chapter 1
  41. [InlineData("Chapter Name.mp3", "Part 1.mp3")]
  42. public void Resolve_AudiobookDirectory_NoResult(params string[] children)
  43. {
  44. var resolved = TestResolveChildren("/parent/book title", children);
  45. Assert.Null(resolved);
  46. }
  47. private Audio? TestResolveChildren(string parent, string[] children)
  48. {
  49. var childrenMetadata = children.Select(name => new FileSystemMetadata
  50. {
  51. FullName = parent + "/" + name,
  52. IsDirectory = name.EndsWith('/')
  53. }).ToArray();
  54. var resolver = new AudioResolver(_namingOptions);
  55. var itemResolveArgs = new ItemResolveArgs(
  56. null,
  57. Mock.Of<ILibraryManager>())
  58. {
  59. CollectionType = "books",
  60. FileInfo = new FileSystemMetadata
  61. {
  62. FullName = parent,
  63. IsDirectory = true
  64. },
  65. FileSystemChildren = childrenMetadata
  66. };
  67. return resolver.Resolve(itemResolveArgs);
  68. }
  69. }