2014-02-06 17:43:45 -07: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
|
|
|
|
|
{
|
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType> { ImageType.Primary };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var album = (MusicAlbum)item;
|
|
|
|
|
|
2015-01-24 23:34:50 -07:00
|
|
|
|
var image = album.GetRecursiveChildren()
|
|
|
|
|
.OfType<Audio>()
|
2015-10-16 10:06:31 -07:00
|
|
|
|
.Select(i => i.GetImageInfo(type, 0))
|
|
|
|
|
.FirstOrDefault(i => i != null && i.IsLocalFile);
|
|
|
|
|
|
|
|
|
|
var imagePath = image == null ? null : image.Path;
|
2014-02-06 17:43:45 -07:00
|
|
|
|
|
|
|
|
|
return Task.FromResult(new DynamicImageResponse
|
|
|
|
|
{
|
2015-10-16 10:06:31 -07:00
|
|
|
|
Path = imagePath,
|
|
|
|
|
HasImage = !string.IsNullOrEmpty(imagePath)
|
2014-02-06 17:43:45 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
2014-02-19 11:50:37 -07:00
|
|
|
|
get { return "Image Extractor"; }
|
2014-02-06 17:43:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return item is MusicAlbum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|