PhotoResolver.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 (!args.IsDirectory && IsImageFile(args.Path) && string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
  20. {
  21. return new Photo
  22. {
  23. Path = args.Path
  24. };
  25. }
  26. return null;
  27. }
  28. protected static string[] ImageExtensions = { ".tiff", ".jpeg", ".jpg", ".png", ".aiff" };
  29. internal static bool IsImageFile(string path)
  30. {
  31. var filename = Path.GetFileName(path);
  32. return !string.Equals(filename, "folder.jpg", StringComparison.OrdinalIgnoreCase)
  33. && ImageExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  34. }
  35. }
  36. }