PhotoResolver.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using MediaBrowser.Controller.Drawing;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Model.Entities;
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. namespace MediaBrowser.Server.Implementations.Library.Resolvers
  9. {
  10. public class PhotoResolver : ItemResolver<Photo>
  11. {
  12. private readonly IImageProcessor _imageProcessor;
  13. public PhotoResolver(IImageProcessor imageProcessor)
  14. {
  15. _imageProcessor = imageProcessor;
  16. }
  17. /// <summary>
  18. /// Resolves the specified args.
  19. /// </summary>
  20. /// <param name="args">The args.</param>
  21. /// <returns>Trailer.</returns>
  22. protected override Photo Resolve(ItemResolveArgs args)
  23. {
  24. // Must be an image file within a photo collection
  25. if (string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) &&
  26. !args.IsDirectory &&
  27. IsImageFile(args.Path, _imageProcessor))
  28. {
  29. return new Photo
  30. {
  31. Path = args.Path
  32. };
  33. }
  34. return null;
  35. }
  36. private static readonly string[] IgnoreFiles =
  37. {
  38. "folder",
  39. "thumb",
  40. "landscape",
  41. "fanart",
  42. "backdrop",
  43. "poster"
  44. };
  45. internal static bool IsImageFile(string path, IImageProcessor imageProcessor)
  46. {
  47. var filename = Path.GetFileNameWithoutExtension(path) ?? string.Empty;
  48. return !IgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase)
  49. && imageProcessor.SupportedInputFormats.Contains((Path.GetExtension(path) ?? string.Empty).TrimStart('.'), StringComparer.OrdinalIgnoreCase);
  50. }
  51. }
  52. }