jellyfin/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs

69 lines
2 KiB
C#
Raw Normal View History

2015-04-08 16:38:02 +02:00
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
2014-02-13 06:11:54 +01:00
using MediaBrowser.Controller.Library;
2014-08-29 06:06:30 +02:00
using MediaBrowser.Model.Entities;
2014-02-13 06:11:54 +01:00
using System;
2014-08-29 06:06:30 +02:00
using System.IO;
2014-02-13 06:11:54 +01:00
using System.Linq;
namespace MediaBrowser.Server.Implementations.Library.Resolvers
{
public class PhotoResolver : ItemResolver<Photo>
{
2015-04-08 16:38:02 +02:00
private readonly IImageProcessor _imageProcessor;
public PhotoResolver(IImageProcessor imageProcessor)
{
_imageProcessor = imageProcessor;
}
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)
{
// Must be an image file within a photo collection
2014-12-28 07:21:39 +01:00
if (string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) &&
!args.IsDirectory &&
2015-04-08 16:38:02 +02:00
IsImageFile(args.Path, _imageProcessor))
2014-02-13 06:11:54 +01:00
{
return new Photo
{
Path = args.Path
};
}
return null;
}
2014-10-12 03:46:02 +02:00
private static readonly string[] IgnoreFiles =
{
"folder",
"thumb",
"landscape",
"fanart",
"backdrop",
"poster"
};
2015-04-08 16:38:02 +02:00
internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
2014-02-13 06:11:54 +01:00
{
2014-10-12 03:46:02 +02:00
var filename = Path.GetFileNameWithoutExtension(path) ?? string.Empty;
2014-08-29 06:06:30 +02:00
if (IgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase))
{
return false;
}
if (IgnoreFiles.Any(i => filename.IndexOf("-" + i, StringComparison.OrdinalIgnoreCase) != -1))
{
return false;
}
return imageProcessor.SupportedInputFormats.Contains((Path.GetExtension(path) ?? string.Empty).TrimStart('.'), StringComparer.OrdinalIgnoreCase);
2014-02-13 06:11:54 +01:00
}
}
}