2013-11-06 15:46:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Providers;
|
2013-11-06 16:29:20 +00:00
|
|
|
|
using System;
|
2013-11-06 15:46:02 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Music
|
|
|
|
|
{
|
|
|
|
|
public class ManualLastFmImageProvider : IImageProvider
|
|
|
|
|
{
|
|
|
|
|
public string Name
|
2013-11-06 16:29:20 +00:00
|
|
|
|
{
|
|
|
|
|
get { return ProviderName; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProviderName
|
2013-11-06 15:46:02 +00:00
|
|
|
|
{
|
|
|
|
|
get { return "last.fm"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Supports(BaseItem item)
|
|
|
|
|
{
|
2013-11-21 20:48:26 +00:00
|
|
|
|
return item is MusicAlbum || item is MusicArtist;
|
2013-11-06 15:46:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, ImageType imageType, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var images = await GetAllImages(item, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return images.Where(i => i.Type == imageType);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 16:29:20 +00:00
|
|
|
|
public Task<IEnumerable<RemoteImageInfo>> GetAllImages(BaseItem item, CancellationToken cancellationToken)
|
2013-11-06 15:46:02 +00:00
|
|
|
|
{
|
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
2013-11-06 16:29:20 +00:00
|
|
|
|
RemoteImageInfo info = null;
|
|
|
|
|
|
|
|
|
|
var album = item as MusicAlbum;
|
|
|
|
|
if (album != null)
|
|
|
|
|
{
|
|
|
|
|
info = GetInfo(album.LastFmImageUrl, album.LastFmImageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var musicArtist = item as MusicArtist;
|
|
|
|
|
if (musicArtist != null)
|
|
|
|
|
{
|
|
|
|
|
info = GetInfo(musicArtist.LastFmImageUrl, musicArtist.LastFmImageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info != null)
|
|
|
|
|
{
|
|
|
|
|
list.Add(info);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 15:46:02 +00:00
|
|
|
|
// The only info we have is size
|
2013-11-06 16:29:20 +00:00
|
|
|
|
return Task.FromResult<IEnumerable<RemoteImageInfo>>(list.OrderByDescending(i => i.Width ?? 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RemoteImageInfo GetInfo(string url, string size)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(url))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var info = new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Url = url
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (string.Equals(size, "mega", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(size, "extralarge", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(size, "large", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(size, "medium", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
2013-11-06 15:46:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Priority
|
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|