AudioBookListResolver.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Emby.Naming.Common;
  4. using Emby.Naming.Video;
  5. using MediaBrowser.Model.IO;
  6. namespace Emby.Naming.AudioBook
  7. {
  8. public class AudioBookListResolver
  9. {
  10. private readonly NamingOptions _options;
  11. public AudioBookListResolver(NamingOptions options)
  12. {
  13. _options = options;
  14. }
  15. public IEnumerable<AudioBookInfo> Resolve(List<FileSystemMetadata> files)
  16. {
  17. var audioBookResolver = new AudioBookResolver(_options);
  18. var audiobookFileInfos = files
  19. .Select(i => audioBookResolver.Resolve(i.FullName, i.IsDirectory))
  20. .Where(i => i != null)
  21. .ToList();
  22. // Filter out all extras, otherwise they could cause stacks to not be resolved
  23. // See the unit test TestStackedWithTrailer
  24. var metadata = audiobookFileInfos
  25. .Select(i => new FileSystemMetadata
  26. {
  27. FullName = i.Path,
  28. IsDirectory = i.IsDirectory
  29. });
  30. var stackResult = new StackResolver(_options)
  31. .ResolveAudioBooks(metadata);
  32. var list = new List<AudioBookInfo>();
  33. foreach (var stack in stackResult.Stacks)
  34. {
  35. var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).ToList();
  36. stackFiles.Sort();
  37. var info = new AudioBookInfo
  38. {
  39. Files = stackFiles,
  40. Name = stack.Name
  41. };
  42. list.Add(info);
  43. }
  44. // Whatever files are left, just add them
  45. /*list.AddRange(remainingFiles.Select(i => new AudioBookInfo
  46. {
  47. Files = new List<AudioBookFileInfo> { i },
  48. Name = i.,
  49. Year = i.Year
  50. }));*/
  51. var orderedList = list.OrderBy(i => i.Name);
  52. return orderedList;
  53. }
  54. }
  55. }