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

83 lines
2.8 KiB
C#
Raw Normal View History

using System;
using MediaBrowser.Controller.Drawing;
2015-04-08 07:38:02 -07:00
using MediaBrowser.Controller.Entities;
2014-08-28 21:06:30 -07:00
using MediaBrowser.Controller.Library;
2014-12-19 23:06:27 -07:00
using MediaBrowser.Controller.Resolvers;
2014-08-28 21:06:30 -07:00
using MediaBrowser.Model.Entities;
namespace Emby.Server.Implementations.Library.Resolvers
2014-08-28 21:06:30 -07:00
{
public class PhotoAlbumResolver : FolderResolver<PhotoAlbum>
{
2015-04-08 07:38:02 -07:00
private readonly IImageProcessor _imageProcessor;
2017-10-21 09:39:52 -07:00
private ILibraryManager _libraryManager;
public PhotoAlbumResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager)
2015-04-08 07:38:02 -07:00
{
_imageProcessor = imageProcessor;
2017-10-21 09:39:52 -07:00
_libraryManager = libraryManager;
2015-04-08 07:38:02 -07:00
}
2014-08-28 21:06:30 -07: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 09:39:52 -07:00
if (args.IsDirectory)
2014-08-28 21:06:30 -07:00
{
2017-10-22 17:43:52 -07: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-28 21:06:30 -07:00
{
2017-10-21 09:39:52 -07:00
if (HasPhotos(args))
2014-08-28 21:06:30 -07:00
{
2017-10-21 09:39:52 -07:00
return new PhotoAlbum
{
Path = args.Path
};
}
2014-08-28 21:06:30 -07:00
}
}
return null;
}
2015-04-08 07:38:02 -07:00
private bool HasPhotos(ItemResolveArgs args)
2014-08-28 21:06:30 -07:00
{
2017-10-21 09:39:52 -07:00
var files = args.FileSystemChildren;
foreach (var file in files)
{
if (!file.IsDirectory && PhotoResolver.IsImageFile(file.FullName, _imageProcessor))
{
var libraryOptions = args.GetLibraryOptions();
var filename = file.Name;
var ownedByMedia = false;
foreach (var siblingFile in files)
{
if (PhotoResolver.IsOwnedByMedia(_libraryManager, libraryOptions, siblingFile.FullName, filename))
{
ownedByMedia = true;
break;
}
}
if (!ownedByMedia)
{
return true;
}
}
}
return false;
2014-08-28 21:06:30 -07:00
}
2014-12-19 23:06:27 -07:00
public override ResolverPriority Priority => ResolverPriority.Second;
2014-08-28 21:06:30 -07:00
}
}