PhotoAlbumResolver.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 readonly 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. /// <inheritdoc />
  27. public override ResolverPriority Priority => ResolverPriority.Second;
  28. /// <summary>
  29. /// Resolves the specified args.
  30. /// </summary>
  31. /// <param name="args">The args.</param>
  32. /// <returns>Trailer.</returns>
  33. protected override PhotoAlbum Resolve(ItemResolveArgs args)
  34. {
  35. // Must be an image file within a photo collection
  36. if (args.IsDirectory)
  37. {
  38. // Must be an image file within a photo collection
  39. var collectionType = args.GetCollectionType();
  40. if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase)
  41. || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.LibraryOptions.EnablePhotos))
  42. {
  43. if (HasPhotos(args))
  44. {
  45. return new PhotoAlbum
  46. {
  47. Path = args.Path
  48. };
  49. }
  50. }
  51. }
  52. return null;
  53. }
  54. private bool HasPhotos(ItemResolveArgs args)
  55. {
  56. var files = args.FileSystemChildren;
  57. foreach (var file in files)
  58. {
  59. if (!file.IsDirectory && PhotoResolver.IsImageFile(file.FullName, _imageProcessor))
  60. {
  61. var filename = file.Name;
  62. var ownedByMedia = false;
  63. foreach (var siblingFile in files)
  64. {
  65. if (PhotoResolver.IsOwnedByMedia(_libraryManager, siblingFile.FullName, filename))
  66. {
  67. ownedByMedia = true;
  68. break;
  69. }
  70. }
  71. if (!ownedByMedia)
  72. {
  73. return true;
  74. }
  75. }
  76. }
  77. return false;
  78. }
  79. }
  80. }