PhotoAlbumResolver.cs 3.1 KB

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