fixes #609 - Add manual image selection for Artists
This commit is contained in:
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,18 +70,34 @@ 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;
|
||||
}
|
||||
|
||||
private async Task DownloadImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var configSetting = item is MusicAlbum
|
||||
? ConfigurationManager.Configuration.DownloadMusicAlbumImages
|
||||
: ConfigurationManager.Configuration.DownloadMusicArtistImages;
|
||||
|
||||
if (configSetting.Primary && !item.HasImage(ImageType.Primary))
|
||||
{
|
||||
var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
await _providerManager.SaveImage(item, image.Url, LastfmBaseProvider.LastfmResourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
|
@ -92,36 +106,5 @@ namespace MediaBrowser.Providers.Music
|
|||
{
|
||||
get { return MetadataProviderPriority.Fifth; }
|
||||
}
|
||||
|
||||
/// <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 artistByName = item as Artist;
|
||||
|
||||
if (artistByName != null)
|
||||
{
|
||||
return artistByName.LastFmImageUrl;
|
||||
}
|
||||
|
||||
var album = item as MusicAlbum;
|
||||
|
||||
if (album != null)
|
||||
{
|
||||
return album.LastFmImageUrl;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue
Block a user