PhotoAlbumResolver.cs 3.0 KB

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