2021-05-20 15:28:18 -04:00
|
|
|
#nullable disable
|
|
|
|
|
2019-01-13 14:54:44 -05:00
|
|
|
using System;
|
2021-11-15 09:56:02 -05:00
|
|
|
using Emby.Naming.Common;
|
2019-01-13 14:21:32 -05:00
|
|
|
using MediaBrowser.Controller.Drawing;
|
2015-04-08 10:38:02 -04:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-08-29 00:06:30 -04:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-12-20 01:06:27 -05:00
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2014-08-29 00:06:30 -04:00
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
2016-11-03 02:37:52 -04:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers
|
2014-08-29 00:06:30 -04:00
|
|
|
{
|
2019-11-01 13:38:54 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Class PhotoAlbumResolver.
|
|
|
|
/// </summary>
|
2021-10-06 05:30:45 -04:00
|
|
|
public class PhotoAlbumResolver : GenericFolderResolver<PhotoAlbum>
|
2014-08-29 00:06:30 -04:00
|
|
|
{
|
2015-04-08 10:38:02 -04:00
|
|
|
private readonly IImageProcessor _imageProcessor;
|
2021-11-15 09:56:02 -05:00
|
|
|
private readonly NamingOptions _namingOptions;
|
2017-10-21 12:39:52 -04:00
|
|
|
|
2019-11-01 13:38:54 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="PhotoAlbumResolver"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="imageProcessor">The image processor.</param>
|
2021-11-15 09:56:02 -05:00
|
|
|
/// <param name="namingOptions">The naming options.</param>
|
|
|
|
public PhotoAlbumResolver(IImageProcessor imageProcessor, NamingOptions namingOptions)
|
2015-04-08 10:38:02 -04:00
|
|
|
{
|
|
|
|
_imageProcessor = imageProcessor;
|
2021-11-15 09:56:02 -05:00
|
|
|
_namingOptions = namingOptions;
|
2015-04-08 10:38:02 -04:00
|
|
|
}
|
|
|
|
|
2021-05-05 09:30:32 -04:00
|
|
|
/// <inheritdoc />
|
|
|
|
public override ResolverPriority Priority => ResolverPriority.Second;
|
|
|
|
|
2014-08-29 00:06:30 -04: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 12:39:52 -04:00
|
|
|
if (args.IsDirectory)
|
2014-08-29 00:06:30 -04:00
|
|
|
{
|
2017-10-22 20:43:52 -04:00
|
|
|
// Must be an image file within a photo collection
|
|
|
|
var collectionType = args.GetCollectionType();
|
|
|
|
|
2021-05-05 09:30:32 -04:00
|
|
|
if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|| (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.LibraryOptions.EnablePhotos))
|
2014-08-29 00:06:30 -04:00
|
|
|
{
|
2017-10-21 12:39:52 -04:00
|
|
|
if (HasPhotos(args))
|
2014-08-29 00:06:30 -04:00
|
|
|
{
|
2017-10-21 12:39:52 -04:00
|
|
|
return new PhotoAlbum
|
|
|
|
{
|
|
|
|
Path = args.Path
|
|
|
|
};
|
|
|
|
}
|
2014-08-29 00:06:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:38:02 -04:00
|
|
|
private bool HasPhotos(ItemResolveArgs args)
|
2014-08-29 00:06:30 -04:00
|
|
|
{
|
2017-10-21 12:39:52 -04: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)
|
|
|
|
{
|
2021-11-15 09:56:02 -05:00
|
|
|
if (PhotoResolver.IsOwnedByMedia(_namingOptions, siblingFile.FullName, filename))
|
2017-10-21 12:39:52 -04:00
|
|
|
{
|
|
|
|
ownedByMedia = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ownedByMedia)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-01 13:38:54 -04:00
|
|
|
|
2017-10-21 12:39:52 -04:00
|
|
|
return false;
|
2014-08-29 00:06:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|