PhotoAlbumResolver.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #nullable disable
  2. using System;
  3. using MediaBrowser.Controller.Drawing;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Controller.Resolvers;
  7. using MediaBrowser.Model.Entities;
  8. namespace Emby.Server.Implementations.Library.Resolvers
  9. {
  10. /// <summary>
  11. /// Class PhotoAlbumResolver.
  12. /// </summary>
  13. public class PhotoAlbumResolver : FolderResolver<PhotoAlbum>
  14. {
  15. private readonly IImageProcessor _imageProcessor;
  16. private readonly ILibraryManager _libraryManager;
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="PhotoAlbumResolver"/> class.
  19. /// </summary>
  20. /// <param name="imageProcessor">The image processor.</param>
  21. /// <param name="libraryManager">The library manager.</param>
  22. public PhotoAlbumResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager)
  23. {
  24. _imageProcessor = imageProcessor;
  25. _libraryManager = libraryManager;
  26. }
  27. /// <inheritdoc />
  28. public override ResolverPriority Priority => ResolverPriority.Second;
  29. /// <summary>
  30. /// Resolves the specified args.
  31. /// </summary>
  32. /// <param name="args">The args.</param>
  33. /// <returns>Trailer.</returns>
  34. protected override PhotoAlbum Resolve(ItemResolveArgs args)
  35. {
  36. // Must be an image file within a photo collection
  37. if (args.IsDirectory)
  38. {
  39. // Must be an image file within a photo collection
  40. var collectionType = args.GetCollectionType();
  41. if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase)
  42. || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.LibraryOptions.EnablePhotos))
  43. {
  44. if (HasPhotos(args))
  45. {
  46. return new PhotoAlbum
  47. {
  48. Path = args.Path
  49. };
  50. }
  51. }
  52. }
  53. return null;
  54. }
  55. private bool HasPhotos(ItemResolveArgs args)
  56. {
  57. var files = args.FileSystemChildren;
  58. foreach (var file in files)
  59. {
  60. if (!file.IsDirectory && PhotoResolver.IsImageFile(file.FullName, _imageProcessor))
  61. {
  62. var filename = file.Name;
  63. var ownedByMedia = false;
  64. foreach (var siblingFile in files)
  65. {
  66. if (PhotoResolver.IsOwnedByMedia(_libraryManager, siblingFile.FullName, filename))
  67. {
  68. ownedByMedia = true;
  69. break;
  70. }
  71. }
  72. if (!ownedByMedia)
  73. {
  74. return true;
  75. }
  76. }
  77. }
  78. return false;
  79. }
  80. }
  81. }