2014-08-29 00:06:30 -04:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-02-13 00:11:54 -05:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-08-29 00:06:30 -04:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-02-13 00:11:54 -05:00
|
|
|
|
using System;
|
2014-08-29 00:06:30 -04:00
|
|
|
|
using System.IO;
|
2014-02-13 00:11:54 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
|
|
|
|
{
|
|
|
|
|
public class PhotoResolver : ItemResolver<Photo>
|
|
|
|
|
{
|
|
|
|
|
/// <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 01:21:39 -05:00
|
|
|
|
if (string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
|
!args.IsDirectory &&
|
2014-12-04 00:24:41 -05:00
|
|
|
|
IsImageFile(args.Path))
|
2014-02-13 00:11:54 -05:00
|
|
|
|
{
|
|
|
|
|
return new Photo
|
|
|
|
|
{
|
|
|
|
|
Path = args.Path
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 12:50:14 -04:00
|
|
|
|
// Some common file name extensions for RAW picture files include: .cr2, .crw, .dng, .nef, .orf, .rw2, .pef, .arw, .sr2, .srf, and .tif.
|
2015-03-08 13:34:02 -04:00
|
|
|
|
protected static string[] ImageExtensions = { ".tiff", ".jpeg", ".jpg", ".png", ".aiff", ".cr2", ".crw", ".dng", ".nef", ".orf", ".pef", ".arw", ".webp" };
|
2014-10-11 21:46:02 -04:00
|
|
|
|
|
|
|
|
|
private static readonly string[] IgnoreFiles =
|
|
|
|
|
{
|
|
|
|
|
"folder",
|
|
|
|
|
"thumb",
|
|
|
|
|
"landscape",
|
|
|
|
|
"fanart",
|
|
|
|
|
"backdrop",
|
|
|
|
|
"poster"
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-29 00:06:30 -04:00
|
|
|
|
internal static bool IsImageFile(string path)
|
2014-02-13 00:11:54 -05:00
|
|
|
|
{
|
2014-10-11 21:46:02 -04:00
|
|
|
|
var filename = Path.GetFileNameWithoutExtension(path) ?? string.Empty;
|
2014-08-29 00:06:30 -04:00
|
|
|
|
|
2014-10-11 21:46:02 -04:00
|
|
|
|
return !IgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase)
|
2014-08-29 00:06:30 -04:00
|
|
|
|
&& ImageExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
2014-02-13 00:11:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|