2014-02-07 01:43:45 +01:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Music
|
|
|
|
|
{
|
|
|
|
|
public class AlbumImageFromSongProvider : IDynamicImageProvider
|
|
|
|
|
{
|
2017-08-07 23:06:13 +02:00
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasMetadata item)
|
2014-02-07 01:43:45 +01:00
|
|
|
|
{
|
|
|
|
|
return new List<ImageType> { ImageType.Primary };
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 23:06:13 +02:00
|
|
|
|
public Task<DynamicImageResponse> GetImage(IHasMetadata item, ImageType type, CancellationToken cancellationToken)
|
2014-02-07 01:43:45 +01:00
|
|
|
|
{
|
|
|
|
|
var album = (MusicAlbum)item;
|
|
|
|
|
|
2017-04-27 20:12:44 +02:00
|
|
|
|
var image = album.GetRecursiveChildren(i => !i.IsFolder)
|
2015-10-16 19:06:31 +02:00
|
|
|
|
.Select(i => i.GetImageInfo(type, 0))
|
|
|
|
|
.FirstOrDefault(i => i != null && i.IsLocalFile);
|
|
|
|
|
|
|
|
|
|
var imagePath = image == null ? null : image.Path;
|
2014-02-07 01:43:45 +01:00
|
|
|
|
|
|
|
|
|
return Task.FromResult(new DynamicImageResponse
|
|
|
|
|
{
|
2015-10-16 19:06:31 +02:00
|
|
|
|
Path = imagePath,
|
|
|
|
|
HasImage = !string.IsNullOrEmpty(imagePath)
|
2014-02-07 01:43:45 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
2014-02-19 19:50:37 +01:00
|
|
|
|
get { return "Image Extractor"; }
|
2014-02-07 01:43:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 23:06:13 +02:00
|
|
|
|
public bool Supports(IHasMetadata item)
|
2014-02-07 01:43:45 +01:00
|
|
|
|
{
|
|
|
|
|
return item is MusicAlbum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|