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 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 filename = file.Name;
  60. var ownedByMedia = false;
  61. foreach (var siblingFile in files)
  62. {
  63. if (PhotoResolver.IsOwnedByMedia(_libraryManager, siblingFile.FullName, filename))
  64. {
  65. ownedByMedia = true;
  66. break;
  67. }
  68. }
  69. if (!ownedByMedia)
  70. {
  71. return true;
  72. }
  73. }
  74. }
  75. return false;
  76. }
  77. /// <inheritdoc />
  78. public override ResolverPriority Priority => ResolverPriority.Second;
  79. }
  80. }