AudioResolverTests.cs 2.9 KB

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