fixes #609 - Add manual image selection for Artists

pull/702/head
Luke Pulverenti 11 years ago
parent a4cea5a5d3
commit 8053a05461

@ -20,6 +20,7 @@ namespace MediaBrowser.Controller.Entities.Audio
}
public string LastFmImageUrl { get; set; }
public string LastFmImageSize { get; set; }
/// <summary>
/// Gets the user data key.

@ -17,6 +17,7 @@ namespace MediaBrowser.Controller.Entities.Audio
}
public string LastFmImageUrl { get; set; }
public string LastFmImageSize { get; set; }
/// <summary>
/// Songs will group into us so don't also include us in the index

@ -11,6 +11,7 @@ namespace MediaBrowser.Controller.Entities.Audio
/// </summary>
/// <value>The last fm image URL.</value>
public string LastFmImageUrl { get; set; }
public string LastFmImageSize { get; set; }
/// <summary>
/// Gets the user data key.

@ -4,7 +4,10 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -55,11 +58,6 @@ namespace MediaBrowser.Providers.Music
return false;
}
if (string.IsNullOrWhiteSpace(GetImageUrl(item)))
{
return false;
}
return base.NeedsRefreshInternal(item, providerInfo);
}
@ -72,56 +70,41 @@ namespace MediaBrowser.Providers.Music
/// <returns>Task{System.Boolean}.</returns>
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var url = GetImageUrl(item);
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualLastFmImageProvider.ProviderName).ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(url) && !item.HasImage(ImageType.Primary))
{
await _providerManager.SaveImage(item, url, LastfmBaseProvider.LastfmResourcePool, ImageType.Primary, null, cancellationToken)
.ConfigureAwait(false);
}
await DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
SetLastRefreshed(item, DateTime.UtcNow);
return true;
}
/// <summary>
/// Gets the priority.
/// </summary>
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
private async Task DownloadImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
{
get { return MetadataProviderPriority.Fifth; }
}
cancellationToken.ThrowIfCancellationRequested();
/// <summary>
/// Gets the image URL.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
private string GetImageUrl(BaseItem item)
{
var musicArtist = item as MusicArtist;
if (musicArtist != null)
{
return musicArtist.LastFmImageUrl;
}
var configSetting = item is MusicAlbum
? ConfigurationManager.Configuration.DownloadMusicAlbumImages
: ConfigurationManager.Configuration.DownloadMusicArtistImages;
var artistByName = item as Artist;
if (artistByName != null)
if (configSetting.Primary && !item.HasImage(ImageType.Primary))
{
return artistByName.LastFmImageUrl;
}
var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
var album = item as MusicAlbum;
if (album != null)
{
return album.LastFmImageUrl;
if (image != null)
{
await _providerManager.SaveImage(item, image.Url, LastfmBaseProvider.LastfmResourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
}
}
}
return null;
/// <summary>
/// Gets the priority.
/// </summary>
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.Fifth; }
}
}
}

@ -46,7 +46,7 @@ namespace MediaBrowser.Providers.Music
{
get
{
return "8";
return "9";
}
}

@ -58,7 +58,7 @@ namespace MediaBrowser.Providers.Music
{
get
{
return "8";
return "9";
}
}

@ -34,21 +34,27 @@ namespace MediaBrowser.Providers.Music
var musicArtist = artist as MusicArtist;
string imageSize;
if (musicArtist != null)
{
musicArtist.LastFmImageUrl = GetImageUrl(data);
musicArtist.LastFmImageUrl = GetImageUrl(data, out imageSize);
musicArtist.LastFmImageSize = imageSize;
}
var artistByName = artist as Artist;
if (artistByName != null)
{
artistByName.LastFmImageUrl = GetImageUrl(data);
artistByName.LastFmImageUrl = GetImageUrl(data, out imageSize);
artistByName.LastFmImageSize = imageSize;
}
}
private static string GetImageUrl(IHasLastFmImages data)
private static string GetImageUrl(IHasLastFmImages data, out string size)
{
size = null;
if (data.image == null)
{
return null;
@ -61,12 +67,13 @@ namespace MediaBrowser.Providers.Music
var img = validImages
.FirstOrDefault(i => string.Equals(i.size, "mega", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "extralarge", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "large", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "medium", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "large", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "medium", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault();
if (img != null)
{
size = img.size;
return img.url;
}
@ -81,7 +88,7 @@ namespace MediaBrowser.Providers.Music
target.Overview = source.Overview;
target.ProductionLocations = source.ProductionLocations.ToList();
}
public static void ProcessAlbumData(BaseItem item, LastfmAlbum data)
{
if (!string.IsNullOrWhiteSpace(data.mbid)) item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
@ -107,7 +114,11 @@ namespace MediaBrowser.Providers.Music
}
var album = (MusicAlbum)item;
album.LastFmImageUrl = GetImageUrl(data);
string imageSize;
album.LastFmImageUrl = GetImageUrl(data, out imageSize);
album.LastFmImageSize = imageSize;
}
private static void AddTags(BaseItem item, LastfmTags tags)

@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -13,6 +14,11 @@ namespace MediaBrowser.Providers.Music
public class ManualLastFmImageProvider : IImageProvider
{
public string Name
{
get { return ProviderName; }
}
public static string ProviderName
{
get { return "last.fm"; }
}
@ -29,12 +35,71 @@ namespace MediaBrowser.Providers.Music
return images.Where(i => i.Type == imageType);
}
public async Task<IEnumerable<RemoteImageInfo>> GetAllImages(BaseItem item, CancellationToken cancellationToken)
public Task<IEnumerable<RemoteImageInfo>> GetAllImages(BaseItem item, CancellationToken cancellationToken)
{
var list = new List<RemoteImageInfo>();
RemoteImageInfo info = null;
var artist = item as Artist;
if (artist != null)
{
info = GetInfo(artist.LastFmImageUrl, artist.LastFmImageSize);
}
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);
}
// The only info we have is size
return list.OrderByDescending(i => i.Width ?? 0);
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;
}
public int Priority

Loading…
Cancel
Save