PhotoAlbumResolver.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. if (string.Equals(args.GetCollectionType(), CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) ||
  31. string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
  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
  71. {
  72. get
  73. {
  74. // Behind special folder resolver
  75. return ResolverPriority.Second;
  76. }
  77. }
  78. }
  79. }