diff --git a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
index 578c99b1d..9117da820 100644
--- a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
+++ b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
@@ -6,6 +6,8 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
@@ -14,13 +16,15 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
+using Mediabrowser.Model.Entities;
namespace MediaBrowser.Controller.Providers.Music
{
public class LastfmArtistProvider : LastfmBaseProvider
{
private readonly IProviderManager _providerManager;
-
+ private readonly ILibraryManager _libraryManager;
+
public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(jsonSerializer, httpClient, logManager, configurationManager)
{
@@ -28,8 +32,25 @@ namespace MediaBrowser.Controller.Providers.Music
LocalMetaFileName = LastfmHelper.LocalArtistMetaFileName;
}
+ ///
+ /// Finds the id.
+ ///
+ /// The item.
+ /// The cancellation token.
+ /// Task{System.String}.
protected override async Task FindId(BaseItem item, CancellationToken cancellationToken)
{
+ if (item is Artist)
+ {
+ // Since MusicArtists are refreshed first, try to find it from one of them
+ var id = FindIdFromMusicArtistEntity(item);
+
+ if (!string.IsNullOrEmpty(id))
+ {
+ return id;
+ }
+ }
+
// Try to find the id using last fm
var result = await FindIdFromLastFm(item, cancellationToken).ConfigureAwait(false);
@@ -61,6 +82,14 @@ namespace MediaBrowser.Controller.Providers.Music
}
}
+ private string FindIdFromMusicArtistEntity(BaseItem item)
+ {
+ var artist = _libraryManager.RootFolder.RecursiveChildren.OfType()
+ .FirstOrDefault(i => string.Equals(i.Name, item.Name, StringComparison.OrdinalIgnoreCase));
+
+ return artist != null ? artist.GetProviderId(MetadataProviders.Musicbrainz) : null;
+ }
+
private async Task> FindIdFromLastFm(BaseItem item, CancellationToken cancellationToken)
{
//Execute the Artist search against our name and assume first one is the one we want