2019-01-13 19:21:32 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2016-11-03 06:37:52 +00:00
|
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers
|
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;
|
|
|
|
|
|
|
|
|
|
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 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-29 04:06:30 +00:00
|
|
|
|
}
|
2014-12-20 06:06:27 +00:00
|
|
|
|
|
2019-01-06 20:50:43 +00:00
|
|
|
|
public override ResolverPriority Priority => ResolverPriority.Second;
|
2014-08-29 04:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|