jellyfin/MediaBrowser.Server.Implementations/Photos/PhotoAlbumImageProvider.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2015-05-10 15:06:12 +02:00
using MediaBrowser.Controller.Entities;
2014-10-29 23:01:02 +01:00
using MediaBrowser.Controller.Providers;
2015-05-10 15:06:12 +02:00
using MediaBrowser.Model.Entities;
2014-08-12 04:59:51 +02:00
using System.Collections.Generic;
using System.Linq;
2015-05-10 15:06:12 +02:00
using System.Threading;
2014-08-12 04:59:51 +02:00
using System.Threading.Tasks;
2014-10-20 05:04:45 +02:00
namespace MediaBrowser.Server.Implementations.Photos
2014-08-12 04:59:51 +02:00
{
2015-05-10 23:56:13 +02:00
public class PhotoAlbumImageProvider : IDynamicImageProvider
{
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return new List<ImageType> { ImageType.Primary };
}
2014-10-20 05:04:45 +02:00
2015-05-10 23:56:13 +02:00
public Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
{
var album = (PhotoAlbum)item;
2014-10-20 05:04:45 +02:00
2015-05-10 23:56:13 +02:00
var image = album.Children
.OfType<Photo>()
.Select(i => i.GetImagePath(type))
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
2015-05-10 15:06:12 +02:00
2015-05-10 23:56:13 +02:00
return Task.FromResult(new DynamicImageResponse
{
Path = image,
HasImage = !string.IsNullOrEmpty(image)
});
}
2015-05-10 15:06:12 +02:00
2015-05-10 23:56:13 +02:00
public string Name
{
get { return "Image Extractor"; }
}
2015-05-10 15:06:12 +02:00
2015-05-10 23:56:13 +02:00
public bool Supports(IHasImages item)
{
return item is PhotoAlbum;
}
}
2014-08-12 04:59:51 +02:00
}