PhotoAlbumResolver.cs 3.1 KB

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