PhotoAlbumResolver.cs 2.9 KB

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