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