PhotoResolver.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using System;
  5. using System.Linq;
  6. namespace MediaBrowser.Server.Implementations.Library.Resolvers
  7. {
  8. public class PhotoResolver : ItemResolver<Photo>
  9. {
  10. private readonly IServerApplicationPaths _applicationPaths;
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="PhotoResolver" /> class.
  13. /// </summary>
  14. /// <param name="applicationPaths">The application paths.</param>
  15. public PhotoResolver(IServerApplicationPaths applicationPaths)
  16. {
  17. _applicationPaths = applicationPaths;
  18. }
  19. /// <summary>
  20. /// Resolves the specified args.
  21. /// </summary>
  22. /// <param name="args">The args.</param>
  23. /// <returns>Trailer.</returns>
  24. protected override Photo Resolve(ItemResolveArgs args)
  25. {
  26. // Must be an image file within a photo collection
  27. if (!args.IsDirectory && IsImageFile(args.Path) && string.Equals(args.GetCollectionType(), "photos", StringComparison.OrdinalIgnoreCase))
  28. {
  29. return new Photo
  30. {
  31. Path = args.Path
  32. };
  33. }
  34. return null;
  35. }
  36. protected static string[] ImageExtensions = { ".tiff", ".jpeg", ".jpg", ".png", ".aiff" };
  37. protected bool IsImageFile(string path)
  38. {
  39. return !path.EndsWith("folder.jpg", StringComparison.OrdinalIgnoreCase)
  40. && ImageExtensions.Any(p => path.EndsWith(p, StringComparison.OrdinalIgnoreCase));
  41. }
  42. }
  43. }