mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
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 LastFmImageUrl { get; set; }
|
||||||
|
public string LastFmImageSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user data key.
|
/// Gets the user data key.
|
||||||
|
@ -17,6 +17,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string LastFmImageUrl { get; set; }
|
public string LastFmImageUrl { get; set; }
|
||||||
|
public string LastFmImageSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Songs will group into us so don't also include us in the index
|
/// Songs will group into us so don't also include us in the index
|
||||||
|
@ -11,6 +11,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The last fm image URL.</value>
|
/// <value>The last fm image URL.</value>
|
||||||
public string LastFmImageUrl { get; set; }
|
public string LastFmImageUrl { get; set; }
|
||||||
|
public string LastFmImageSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user data key.
|
/// Gets the user data key.
|
||||||
|
@ -4,7 +4,10 @@ using MediaBrowser.Controller.Entities.Audio;
|
|||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
|
using MediaBrowser.Model.Providers;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -55,11 +58,6 @@ namespace MediaBrowser.Providers.Music
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(GetImageUrl(item)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return base.NeedsRefreshInternal(item, providerInfo);
|
return base.NeedsRefreshInternal(item, providerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,18 +70,34 @@ namespace MediaBrowser.Providers.Music
|
|||||||
/// <returns>Task{System.Boolean}.</returns>
|
/// <returns>Task{System.Boolean}.</returns>
|
||||||
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
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 DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
||||||
{
|
|
||||||
await _providerManager.SaveImage(item, url, LastfmBaseProvider.LastfmResourcePool, ImageType.Primary, null, cancellationToken)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetLastRefreshed(item, DateTime.UtcNow);
|
SetLastRefreshed(item, DateTime.UtcNow);
|
||||||
|
|
||||||
return true;
|
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>
|
/// <summary>
|
||||||
/// Gets the priority.
|
/// Gets the priority.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -92,36 +106,5 @@ namespace MediaBrowser.Providers.Music
|
|||||||
{
|
{
|
||||||
get { return MetadataProviderPriority.Fifth; }
|
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
|
get
|
||||||
{
|
{
|
||||||
return "8";
|
return "9";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ namespace MediaBrowser.Providers.Music
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "8";
|
return "9";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,21 +34,27 @@ namespace MediaBrowser.Providers.Music
|
|||||||
|
|
||||||
var musicArtist = artist as MusicArtist;
|
var musicArtist = artist as MusicArtist;
|
||||||
|
|
||||||
|
string imageSize;
|
||||||
|
|
||||||
if (musicArtist != null)
|
if (musicArtist != null)
|
||||||
{
|
{
|
||||||
musicArtist.LastFmImageUrl = GetImageUrl(data);
|
musicArtist.LastFmImageUrl = GetImageUrl(data, out imageSize);
|
||||||
|
musicArtist.LastFmImageSize = imageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
var artistByName = artist as Artist;
|
var artistByName = artist as Artist;
|
||||||
|
|
||||||
if (artistByName != null)
|
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)
|
if (data.image == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@ -67,6 +73,7 @@ namespace MediaBrowser.Providers.Music
|
|||||||
|
|
||||||
if (img != null)
|
if (img != null)
|
||||||
{
|
{
|
||||||
|
size = img.size;
|
||||||
return img.url;
|
return img.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +114,11 @@ namespace MediaBrowser.Providers.Music
|
|||||||
}
|
}
|
||||||
|
|
||||||
var album = (MusicAlbum)item;
|
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)
|
private static void AddTags(BaseItem item, LastfmTags tags)
|
||||||
|
@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities.Audio;
|
|||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -13,6 +14,11 @@ namespace MediaBrowser.Providers.Music
|
|||||||
public class ManualLastFmImageProvider : IImageProvider
|
public class ManualLastFmImageProvider : IImageProvider
|
||||||
{
|
{
|
||||||
public string Name
|
public string Name
|
||||||
|
{
|
||||||
|
get { return ProviderName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ProviderName
|
||||||
{
|
{
|
||||||
get { return "last.fm"; }
|
get { return "last.fm"; }
|
||||||
}
|
}
|
||||||
@ -29,12 +35,71 @@ namespace MediaBrowser.Providers.Music
|
|||||||
return images.Where(i => i.Type == imageType);
|
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>();
|
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
|
// 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
|
public int Priority
|
||||||
|
Loading…
x
Reference in New Issue
Block a user