PhotoAlbumImageProvider.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Entities;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace MediaBrowser.Server.Implementations.Photos
  9. {
  10. public class PhotoAlbumImageProvider : IDynamicImageProvider
  11. {
  12. public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
  13. {
  14. return new List<ImageType> { ImageType.Primary };
  15. }
  16. public Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
  17. {
  18. var album = (PhotoAlbum)item;
  19. var image = album.Children
  20. .OfType<Photo>()
  21. .Select(i => i.GetImagePath(type))
  22. .FirstOrDefault(i => !string.IsNullOrEmpty(i));
  23. return Task.FromResult(new DynamicImageResponse
  24. {
  25. Path = image,
  26. HasImage = !string.IsNullOrEmpty(image)
  27. });
  28. }
  29. public string Name
  30. {
  31. get { return "Image Extractor"; }
  32. }
  33. public bool Supports(IHasImages item)
  34. {
  35. return item is PhotoAlbum;
  36. }
  37. }
  38. }