From 4c46258763d24a6789d8c72852945884f47ae896 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Mon, 4 Mar 2013 18:24:41 -0500 Subject: [PATCH] Have FanArtArtistProvider retrieve album covers --- .../Entities/Audio/MusicArtist.cs | 9 +++++ .../Providers/Music/FanArtArtistProvider.cs | 37 ++++++++++++++++--- .../Music/MusicArtistProviderFromJson.cs | 3 ++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index b2fc04873f..b5627e061f 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -1,4 +1,6 @@  +using System.Collections.Generic; + namespace MediaBrowser.Controller.Entities.Audio { /// @@ -6,5 +8,12 @@ namespace MediaBrowser.Controller.Entities.Audio /// public class MusicArtist : Folder { + public Dictionary AlbumCovers { get; set; } + + public override void ClearMetaValues() + { + AlbumCovers = null; + base.ClearMetaValues(); + } } } diff --git a/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs index 011c2b611a..3834bff912 100644 --- a/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs @@ -61,15 +61,16 @@ namespace MediaBrowser.Controller.Providers.Music /// true if XXXX, false otherwise protected override bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo) { - var baseItem = item; - if (item.Path == null || item.DontFetchMeta || string.IsNullOrEmpty(baseItem.GetProviderId(MetadataProviders.Musicbrainz))) return false; //nothing to do + var artist = (MusicArtist)item; + if (item.Path == null || item.DontFetchMeta || string.IsNullOrEmpty(artist.GetProviderId(MetadataProviders.Musicbrainz))) return false; //nothing to do var artExists = item.ResolveArgs.ContainsMetaFileByName(ART_FILE); var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE); var discExists = item.ResolveArgs.ContainsMetaFileByName(DISC_FILE); return (!artExists && ConfigurationManager.Configuration.DownloadMusicArtistImages.Art) || (!logoExists && ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo) - || (!discExists && ConfigurationManager.Configuration.DownloadMusicArtistImages.Disc); + || (!discExists && ConfigurationManager.Configuration.DownloadMusicArtistImages.Disc) + || ((artist.AlbumCovers == null || artist.AlbumCovers.Count == 0) && ConfigurationManager.Configuration.DownloadMusicAlbumImages.Primary); } /// @@ -83,7 +84,7 @@ namespace MediaBrowser.Controller.Providers.Music { cancellationToken.ThrowIfCancellationRequested(); - var artist = item; + var artist = (MusicArtist)item; if (ShouldFetch(artist, artist.ProviderData.GetValueOrDefault(Id, new BaseProviderInfo { ProviderId = Id }))) { var url = string.Format(FanArtBaseUrl, APIKey, artist.GetProviderId(MetadataProviders.Musicbrainz)); @@ -136,6 +137,7 @@ namespace MediaBrowser.Controller.Providers.Music if (nodes != null) { var numBackdrops = 0; + artist.BackdropImagePaths = new List(); foreach (XmlNode node in nodes) { path = node.Value; @@ -144,7 +146,6 @@ namespace MediaBrowser.Controller.Providers.Music Logger.Debug("FanArtProvider getting Backdrop for " + artist.Name); try { - artist.BackdropImagePaths = new List(); artist.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(artist, path, ("Backdrop"+(numBackdrops > 0 ? numBackdrops.ToString() : "")+".jpg"), FanArtResourcePool, cancellationToken).ConfigureAwait(false)); numBackdrops++; if (numBackdrops >= ConfigurationManager.Configuration.MaxBackdrops) break; @@ -165,6 +166,32 @@ namespace MediaBrowser.Controller.Providers.Music cancellationToken.ThrowIfCancellationRequested(); + if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Primary) + { + var nodes = doc.SelectNodes("//fanart/music/albums/*"); + if (nodes != null) + { + artist.AlbumCovers = new Dictionary(); + foreach (XmlNode node in nodes) + { + + var key = node.Attributes["id"] != null ? node.Attributes["id"].Value : null; + var cover = node.SelectSingleNode("albumcover/@url"); + path = cover != null ? cover.Value : null; + + if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(key)) + { + Logger.Debug("FanArtProvider getting Album Cover for " + artist.Name); + artist.AlbumCovers[key] = path; + } + } + + } + + } + + cancellationToken.ThrowIfCancellationRequested(); + if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE)) { var node = diff --git a/MediaBrowser.Controller/Providers/Music/MusicArtistProviderFromJson.cs b/MediaBrowser.Controller/Providers/Music/MusicArtistProviderFromJson.cs index 6008074895..fab4684927 100644 --- a/MediaBrowser.Controller/Providers/Music/MusicArtistProviderFromJson.cs +++ b/MediaBrowser.Controller/Providers/Music/MusicArtistProviderFromJson.cs @@ -9,6 +9,7 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -49,6 +50,8 @@ namespace MediaBrowser.Controller.Providers.Music LastfmHelper.ProcessArtistData(item, data); + item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid); + SetLastRefreshed(item, DateTime.UtcNow); return true; }