2019-11-01 18:38:54 +01:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 20:54:44 +01:00
|
|
|
using System;
|
2019-02-06 21:31:41 +01:00
|
|
|
using System.Collections.Generic;
|
2014-08-29 06:06:30 +02:00
|
|
|
using System.IO;
|
2014-02-13 06:11:54 +01:00
|
|
|
using System.Linq;
|
2019-01-13 20:21:32 +01:00
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2016-08-13 22:54:29 +02:00
|
|
|
using MediaBrowser.Model.Configuration;
|
2019-01-13 20:21:32 +01:00
|
|
|
using MediaBrowser.Model.Entities;
|
2014-02-13 06:11:54 +01:00
|
|
|
|
2016-11-03 07:37:52 +01:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers
|
2014-02-13 06:11:54 +01:00
|
|
|
{
|
|
|
|
public class PhotoResolver : ItemResolver<Photo>
|
|
|
|
{
|
2015-04-08 16:38:02 +02:00
|
|
|
private readonly IImageProcessor _imageProcessor;
|
2016-07-11 06:57:22 +02:00
|
|
|
private readonly ILibraryManager _libraryManager;
|
2019-05-11 11:55:41 +02:00
|
|
|
private static readonly HashSet<string> _ignoreFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
|
|
|
{
|
|
|
|
"folder",
|
|
|
|
"thumb",
|
|
|
|
"landscape",
|
|
|
|
"fanart",
|
|
|
|
"backdrop",
|
|
|
|
"poster",
|
|
|
|
"cover",
|
|
|
|
"logo",
|
|
|
|
"default"
|
|
|
|
};
|
2016-07-11 06:57:22 +02:00
|
|
|
|
2019-02-06 20:38:42 +01:00
|
|
|
public PhotoResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager)
|
2015-04-08 16:38:02 +02:00
|
|
|
{
|
|
|
|
_imageProcessor = imageProcessor;
|
2016-07-11 06:57:22 +02:00
|
|
|
_libraryManager = libraryManager;
|
2015-04-08 16:38:02 +02:00
|
|
|
}
|
|
|
|
|
2014-02-13 06:11:54 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Resolves the specified args.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
/// <returns>Trailer.</returns>
|
|
|
|
protected override Photo Resolve(ItemResolveArgs args)
|
|
|
|
{
|
2016-07-11 06:57:22 +02:00
|
|
|
if (!args.IsDirectory)
|
2014-02-13 06:11:54 +01:00
|
|
|
{
|
2016-07-11 06:57:22 +02:00
|
|
|
// Must be an image file within a photo collection
|
2019-05-11 11:55:41 +02:00
|
|
|
var collectionType = args.CollectionType;
|
2016-07-11 06:57:22 +02:00
|
|
|
|
2019-05-11 11:55:41 +02:00
|
|
|
if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|| (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos))
|
2014-02-13 06:11:54 +01:00
|
|
|
{
|
2016-07-11 06:57:22 +02:00
|
|
|
if (IsImageFile(args.Path, _imageProcessor))
|
|
|
|
{
|
|
|
|
var filename = Path.GetFileNameWithoutExtension(args.Path);
|
|
|
|
|
|
|
|
// Make sure the image doesn't belong to a video file
|
2019-01-26 21:47:11 +01:00
|
|
|
var files = args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path));
|
2017-10-21 18:39:52 +02:00
|
|
|
var libraryOptions = args.GetLibraryOptions();
|
|
|
|
|
|
|
|
foreach (var file in files)
|
2016-07-11 06:57:22 +02:00
|
|
|
{
|
2017-10-21 18:39:52 +02:00
|
|
|
if (IsOwnedByMedia(_libraryManager, libraryOptions, file.FullName, filename))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2016-07-11 06:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Photo
|
|
|
|
{
|
|
|
|
Path = args.Path
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 06:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-10-21 18:39:52 +02:00
|
|
|
internal static bool IsOwnedByMedia(ILibraryManager libraryManager, LibraryOptions libraryOptions, string file, string imageFilename)
|
2016-07-11 06:57:22 +02:00
|
|
|
{
|
2017-10-21 18:39:52 +02:00
|
|
|
if (libraryManager.IsVideoFile(file, libraryOptions))
|
2016-07-11 06:57:22 +02:00
|
|
|
{
|
2017-10-21 18:39:52 +02:00
|
|
|
return IsOwnedByResolvedMedia(libraryManager, libraryOptions, file, imageFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static bool IsOwnedByResolvedMedia(ILibraryManager libraryManager, LibraryOptions libraryOptions, string file, string imageFilename)
|
2019-05-11 11:55:41 +02:00
|
|
|
=> imageFilename.StartsWith(Path.GetFileNameWithoutExtension(file), StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
|
2017-10-21 18:39:52 +02:00
|
|
|
{
|
2019-05-11 11:55:41 +02:00
|
|
|
if (path == null)
|
2017-10-21 18:39:52 +02:00
|
|
|
{
|
2019-05-11 11:55:41 +02:00
|
|
|
throw new ArgumentNullException(nameof(path));
|
2016-07-11 06:57:22 +02:00
|
|
|
}
|
|
|
|
|
2019-05-11 11:55:41 +02:00
|
|
|
var filename = Path.GetFileNameWithoutExtension(path);
|
2014-08-29 06:06:30 +02:00
|
|
|
|
2019-05-11 11:55:41 +02:00
|
|
|
if (_ignoreFiles.Contains(filename))
|
2016-01-27 18:34:23 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-11 11:55:41 +02:00
|
|
|
if (_ignoreFiles.Any(i => filename.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1))
|
2016-01-27 18:34:23 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-11 11:55:41 +02:00
|
|
|
string extension = Path.GetExtension(path).TrimStart('.');
|
|
|
|
return imageProcessor.SupportedInputFormats.Contains(extension, StringComparer.OrdinalIgnoreCase);
|
2014-02-13 06:11:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|