PhotoAlbumResolver.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. public class PhotoAlbumResolver : FolderResolver<PhotoAlbum>
  10. {
  11. private readonly IImageProcessor _imageProcessor;
  12. private ILibraryManager _libraryManager;
  13. public PhotoAlbumResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager)
  14. {
  15. _imageProcessor = imageProcessor;
  16. _libraryManager = libraryManager;
  17. }
  18. /// <summary>
  19. /// Resolves the specified args.
  20. /// </summary>
  21. /// <param name="args">The args.</param>
  22. /// <returns>Trailer.</returns>
  23. protected override PhotoAlbum Resolve(ItemResolveArgs args)
  24. {
  25. // Must be an image file within a photo collection
  26. if (args.IsDirectory)
  27. {
  28. // Must be an image file within a photo collection
  29. var collectionType = args.GetCollectionType();
  30. if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
  31. (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos))
  32. {
  33. if (HasPhotos(args))
  34. {
  35. return new PhotoAlbum
  36. {
  37. Path = args.Path
  38. };
  39. }
  40. }
  41. }
  42. return null;
  43. }
  44. private bool HasPhotos(ItemResolveArgs args)
  45. {
  46. var files = args.FileSystemChildren;
  47. foreach (var file in files)
  48. {
  49. if (!file.IsDirectory && PhotoResolver.IsImageFile(file.FullName, _imageProcessor))
  50. {
  51. var libraryOptions = args.GetLibraryOptions();
  52. var filename = file.Name;
  53. var ownedByMedia = false;
  54. foreach (var siblingFile in files)
  55. {
  56. if (PhotoResolver.IsOwnedByMedia(_libraryManager, libraryOptions, siblingFile.FullName, filename))
  57. {
  58. ownedByMedia = true;
  59. break;
  60. }
  61. }
  62. if (!ownedByMedia)
  63. {
  64. return true;
  65. }
  66. }
  67. }
  68. return false;
  69. }
  70. public override ResolverPriority Priority => ResolverPriority.Second;
  71. }
  72. }