jellyfin-server/Emby.Server.Implementations/Library/Resolvers/PhotoAlbumResolver.cs

92 lines
3.0 KiB
C#
Raw Normal View History

using System;
using MediaBrowser.Controller.Drawing;
2015-04-08 14:38:02 +00:00
using MediaBrowser.Controller.Entities;
2014-08-29 04:06:30 +00:00
using MediaBrowser.Controller.Library;
2014-12-20 06:06:27 +00:00
using MediaBrowser.Controller.Resolvers;
2014-08-29 04:06:30 +00:00
using MediaBrowser.Model.Entities;
namespace Emby.Server.Implementations.Library.Resolvers
2014-08-29 04:06:30 +00:00
{
2019-11-01 17:38:54 +00:00
/// <summary>
/// Class PhotoAlbumResolver.
/// </summary>
2014-08-29 04:06:30 +00:00
public class PhotoAlbumResolver : FolderResolver<PhotoAlbum>
{
2015-04-08 14:38:02 +00:00
private readonly IImageProcessor _imageProcessor;
2017-10-21 16:39:52 +00:00
private ILibraryManager _libraryManager;
2019-11-01 17:38:54 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="PhotoAlbumResolver"/> class.
/// </summary>
/// <param name="imageProcessor">The image processor.</param>
/// <param name="libraryManager">The library manager.</param>
2017-10-21 16:39:52 +00:00
public PhotoAlbumResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager)
2015-04-08 14:38:02 +00:00
{
_imageProcessor = imageProcessor;
2017-10-21 16:39:52 +00:00
_libraryManager = libraryManager;
2015-04-08 14:38:02 +00:00
}
2014-08-29 04:06:30 +00:00
/// <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
2017-10-21 16:39:52 +00:00
if (args.IsDirectory)
2014-08-29 04:06:30 +00:00
{
2017-10-23 00:43:52 +00:00
// Must be an image file within a photo collection
var collectionType = args.GetCollectionType();
if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
(string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos))
2014-08-29 04:06:30 +00:00
{
2017-10-21 16:39:52 +00:00
if (HasPhotos(args))
2014-08-29 04:06:30 +00:00
{
2017-10-21 16:39:52 +00:00
return new PhotoAlbum
{
Path = args.Path
};
}
2014-08-29 04:06:30 +00:00
}
}
return null;
}
2015-04-08 14:38:02 +00:00
private bool HasPhotos(ItemResolveArgs args)
2014-08-29 04:06:30 +00:00
{
2017-10-21 16:39:52 +00:00
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)
{
2020-02-19 20:56:35 +00:00
if (PhotoResolver.IsOwnedByMedia(_libraryManager, siblingFile.FullName, filename))
2017-10-21 16:39:52 +00:00
{
ownedByMedia = true;
break;
}
}
if (!ownedByMedia)
{
return true;
}
}
}
2019-11-01 17:38:54 +00:00
2017-10-21 16:39:52 +00:00
return false;
2014-08-29 04:06:30 +00:00
}
2014-12-20 06:06:27 +00:00
2019-11-01 17:38:54 +00:00
/// <inheritdoc />
public override ResolverPriority Priority => ResolverPriority.Second;
2014-08-29 04:06:30 +00:00
}
}