2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2019-02-06 20:31:41 +00:00
|
|
|
using System.Collections.Generic;
|
2014-08-29 04:06:30 +00:00
|
|
|
using System.IO;
|
2014-02-13 05:11:54 +00:00
|
|
|
using System.Linq;
|
2019-01-13 19:21:32 +00:00
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2016-08-13 20:54:29 +00:00
|
|
|
using MediaBrowser.Model.Configuration;
|
2019-01-13 19:21:32 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2017-05-04 18:14:45 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-02-13 05:11:54 +00:00
|
|
|
|
2016-11-03 06:37:52 +00:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers
|
2014-02-13 05:11:54 +00:00
|
|
|
{
|
|
|
|
public class PhotoResolver : ItemResolver<Photo>
|
|
|
|
{
|
2015-04-08 14:38:02 +00:00
|
|
|
private readonly IImageProcessor _imageProcessor;
|
2016-07-11 04:57:22 +00:00
|
|
|
private readonly ILibraryManager _libraryManager;
|
2017-05-04 18:14:45 +00:00
|
|
|
private readonly IFileSystem _fileSystem;
|
2016-07-11 04:57:22 +00:00
|
|
|
|
2017-05-04 18:14:45 +00:00
|
|
|
public PhotoResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager, IFileSystem fileSystem)
|
2015-04-08 14:38:02 +00:00
|
|
|
{
|
|
|
|
_imageProcessor = imageProcessor;
|
2016-07-11 04:57:22 +00:00
|
|
|
_libraryManager = libraryManager;
|
2017-05-04 18:14:45 +00:00
|
|
|
_fileSystem = fileSystem;
|
2015-04-08 14:38:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 05:11:54 +00: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 04:57:22 +00:00
|
|
|
if (!args.IsDirectory)
|
2014-02-13 05:11:54 +00:00
|
|
|
{
|
2016-07-11 04:57:22 +00:00
|
|
|
// Must be an image file within a photo collection
|
|
|
|
var collectionType = args.GetCollectionType();
|
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
|
2016-08-15 04:36:17 +00:00
|
|
|
(string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos))
|
2014-02-13 05:11:54 +00:00
|
|
|
{
|
2016-07-11 04:57:22 +00: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 20:47:11 +00:00
|
|
|
var files = args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path));
|
2017-10-21 16:39:52 +00:00
|
|
|
var libraryOptions = args.GetLibraryOptions();
|
|
|
|
|
|
|
|
foreach (var file in files)
|
2016-07-11 04:57:22 +00:00
|
|
|
{
|
2017-10-21 16:39:52 +00:00
|
|
|
if (IsOwnedByMedia(_libraryManager, libraryOptions, file.FullName, filename))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2016-07-11 04:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Photo
|
|
|
|
{
|
|
|
|
Path = args.Path
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 05:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-10-21 16:39:52 +00:00
|
|
|
internal static bool IsOwnedByMedia(ILibraryManager libraryManager, LibraryOptions libraryOptions, string file, string imageFilename)
|
2016-07-11 04:57:22 +00:00
|
|
|
{
|
2017-10-21 16:39:52 +00:00
|
|
|
if (libraryManager.IsVideoFile(file, libraryOptions))
|
2016-07-11 04:57:22 +00:00
|
|
|
{
|
2017-10-21 16:39:52 +00:00
|
|
|
return IsOwnedByResolvedMedia(libraryManager, libraryOptions, file, imageFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static bool IsOwnedByResolvedMedia(ILibraryManager libraryManager, LibraryOptions libraryOptions, string file, string imageFilename)
|
|
|
|
{
|
|
|
|
if (imageFilename.StartsWith(Path.GetFileNameWithoutExtension(file), StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return true;
|
2016-07-11 04:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-06 20:31:41 +00:00
|
|
|
private static readonly HashSet<string> IgnoreFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
2014-10-12 01:46:02 +00:00
|
|
|
{
|
|
|
|
"folder",
|
|
|
|
"thumb",
|
|
|
|
"landscape",
|
|
|
|
"fanart",
|
|
|
|
"backdrop",
|
2016-07-11 04:57:22 +00:00
|
|
|
"poster",
|
2017-10-21 16:39:52 +00:00
|
|
|
"cover",
|
2018-09-12 17:26:21 +00:00
|
|
|
"logo",
|
|
|
|
"default"
|
2014-10-12 01:46:02 +00:00
|
|
|
};
|
|
|
|
|
2015-04-08 14:38:02 +00:00
|
|
|
internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
|
2014-02-13 05:11:54 +00:00
|
|
|
{
|
2014-10-12 01:46:02 +00:00
|
|
|
var filename = Path.GetFileNameWithoutExtension(path) ?? string.Empty;
|
2014-08-29 04:06:30 +00:00
|
|
|
|
2019-02-06 20:31:41 +00:00
|
|
|
if (IgnoreFiles.Contains(filename))
|
2016-01-27 17:34:23 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-20 15:22:00 +00:00
|
|
|
if (IgnoreFiles.Any(i => filename.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1))
|
2016-01-27 17:34:23 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-06 20:31:41 +00:00
|
|
|
return imageProcessor.SupportedInputFormats.Contains((Path.GetExtension(path) ?? string.Empty).TrimStart('.'));
|
2014-02-13 05:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|