PhotoResolver.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Entities;
  4. using System;
  5. using System.IO;
  6. using System.Linq;
  7. namespace MediaBrowser.Server.Implementations.Library.Resolvers
  8. {
  9. public class PhotoResolver : ItemResolver<Photo>
  10. {
  11. /// <summary>
  12. /// Resolves the specified args.
  13. /// </summary>
  14. /// <param name="args">The args.</param>
  15. /// <returns>Trailer.</returns>
  16. protected override Photo Resolve(ItemResolveArgs args)
  17. {
  18. // Must be an image file within a photo collection
  19. if (string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) &&
  20. !args.IsDirectory &&
  21. IsImageFile(args.Path))
  22. {
  23. return new Photo
  24. {
  25. Path = args.Path
  26. };
  27. }
  28. return null;
  29. }
  30. // Some common file name extensions for RAW picture files include: .cr2, .crw, .dng, .nef, .orf, .rw2, .pef, .arw, .sr2, .srf, and .tif.
  31. protected static string[] ImageExtensions = { ".tiff", ".jpeg", ".jpg", ".png", ".aiff", ".cr2", ".crw", "dng", ".nef", ".orf", ".pef", ".arw" };
  32. private static readonly string[] IgnoreFiles =
  33. {
  34. "folder",
  35. "thumb",
  36. "landscape",
  37. "fanart",
  38. "backdrop",
  39. "poster"
  40. };
  41. internal static bool IsImageFile(string path)
  42. {
  43. var filename = Path.GetFileNameWithoutExtension(path) ?? string.Empty;
  44. return !IgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase)
  45. && ImageExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  46. }
  47. }
  48. }