You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/Emby.Server.Implementations/Library/Resolvers/PhotoAlbumResolver.cs

96 lines
3.0 KiB

#nullable disable
using System;
using Emby.Naming.Common;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
10 years ago
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
10 years ago
using MediaBrowser.Model.Entities;
namespace Emby.Server.Implementations.Library.Resolvers
10 years ago
{
/// <summary>
/// Class PhotoAlbumResolver.
/// </summary>
public class PhotoAlbumResolver : GenericFolderResolver<PhotoAlbum>
10 years ago
{
private readonly IImageProcessor _imageProcessor;
private readonly NamingOptions _namingOptions;
/// <summary>
/// Initializes a new instance of the <see cref="PhotoAlbumResolver"/> class.
/// </summary>
/// <param name="imageProcessor">The image processor.</param>
/// <param name="namingOptions">The naming options.</param>
public PhotoAlbumResolver(IImageProcessor imageProcessor, NamingOptions namingOptions)
{
_imageProcessor = imageProcessor;
_namingOptions = namingOptions;
}
/// <inheritdoc />
public override ResolverPriority Priority => ResolverPriority.Second;
10 years ago
/// <summary>
/// Resolves the specified args.
/// </summary>
/// <param name="args">The args.</param>
/// <returns>Trailer.</returns>
protected override PhotoAlbum Resolve(ItemResolveArgs args)
{
// Must be an image file within a photo collection
if (args.IsDirectory)
10 years ago
{
// Must be an image file within a photo collection
var collectionType = args.GetCollectionType();
if (collectionType == CollectionType.Photos
|| (collectionType == CollectionType.HomeVideos && args.LibraryOptions.EnablePhotos))
10 years ago
{
if (HasPhotos(args))
10 years ago
{
return new PhotoAlbum
{
Path = args.Path
};
}
10 years ago
}
}
return null;
}
private bool HasPhotos(ItemResolveArgs args)
10 years ago
{
var files = args.FileSystemChildren;
foreach (var file in files)
{
if (!file.IsDirectory && PhotoResolver.IsImageFile(file.FullName, _imageProcessor))
{
var filename = file.Name;
var ownedByMedia = false;
foreach (var siblingFile in files)
{
if (PhotoResolver.IsOwnedByMedia(_namingOptions, siblingFile.FullName, filename))
{
ownedByMedia = true;
break;
}
}
if (!ownedByMedia)
{
return true;
}
}
}
return false;
10 years ago
}
}
}