diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index 18e02473fb..5d47d08134 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -126,6 +126,15 @@ namespace MediaBrowser.Api UpdateItem(request, item); await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); + + var musicArtist = Artist.FindMusicArtist(item, _libraryManager); + + if (musicArtist != null) + { + UpdateItem(request, musicArtist); + + await _libraryManager.UpdateItem(musicArtist, ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); + } } public void Post(UpdateStudio request) diff --git a/MediaBrowser.Controller/Entities/Audio/Artist.cs b/MediaBrowser.Controller/Entities/Audio/Artist.cs index e0d80527cb..07bb68b95c 100644 --- a/MediaBrowser.Controller/Entities/Audio/Artist.cs +++ b/MediaBrowser.Controller/Entities/Audio/Artist.cs @@ -1,7 +1,11 @@ -using System.Runtime.Serialization; +using System.Globalization; +using System.Linq; +using MediaBrowser.Controller.Library; using MediaBrowser.Model.Dto; using System; using System.Collections.Generic; +using System.Runtime.Serialization; +using MediaBrowser.Model.Entities; namespace MediaBrowser.Controller.Entities.Audio { @@ -28,5 +32,37 @@ namespace MediaBrowser.Controller.Entities.Audio [IgnoreDataMember] public Dictionary UserItemCounts { get; set; } + + /// + /// Finds the music artist. + /// + /// The artist. + /// The library manager. + /// MusicArtist. + public static MusicArtist FindMusicArtist(Artist artist, ILibraryManager libraryManager) + { + return FindMusicArtist(artist, libraryManager.RootFolder.RecursiveChildren.OfType()); + } + + /// + /// Finds the music artist. + /// + /// The artist. + /// All music artists. + /// MusicArtist. + public static MusicArtist FindMusicArtist(Artist artist, IEnumerable allMusicArtists) + { + var musicBrainzId = artist.GetProviderId(MetadataProviders.Musicbrainz); + + return allMusicArtists.FirstOrDefault(i => + { + if (!string.IsNullOrWhiteSpace(musicBrainzId) && string.Equals(musicBrainzId, i.GetProviderId(MetadataProviders.Musicbrainz), StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + return string.Compare(i.Name, artist.Name, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols) == 0; + }); + } } } diff --git a/MediaBrowser.Providers/Music/LastfmArtistByNameProvider.cs b/MediaBrowser.Providers/Music/LastfmArtistByNameProvider.cs index 5bc9debd3a..26ac68c3d4 100644 --- a/MediaBrowser.Providers/Music/LastfmArtistByNameProvider.cs +++ b/MediaBrowser.Providers/Music/LastfmArtistByNameProvider.cs @@ -3,11 +3,8 @@ 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.Serialization; -using System; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -77,7 +74,7 @@ namespace MediaBrowser.Providers.Music var artist = (Artist)item; // See if we can avoid an http request by finding the matching MusicArtist entity - var musicArtist = FindMusicArtist(artist, LibraryManager); + var musicArtist = Artist.FindMusicArtist(artist, LibraryManager); if (musicArtist != null && !force) { @@ -88,29 +85,5 @@ namespace MediaBrowser.Providers.Music await base.FetchLastfmData(item, musicBrainzId, force, cancellationToken).ConfigureAwait(false); } } - - - /// - /// Finds the music artist. - /// - /// The artist. - /// The library manager. - /// MusicArtist. - private static MusicArtist FindMusicArtist(Artist artist, ILibraryManager libraryManager) - { - var musicBrainzId = artist.GetProviderId(MetadataProviders.Musicbrainz); - - return libraryManager.RootFolder.RecursiveChildren - .OfType() - .FirstOrDefault(i => - { - if (!string.IsNullOrWhiteSpace(musicBrainzId) && string.Equals(musicBrainzId, i.GetProviderId(MetadataProviders.Musicbrainz), StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return false; - }); - } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs index 903fe86be8..7387b91662 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs @@ -6,9 +6,7 @@ using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using System; -using System.Collections.Concurrent; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Linq; using System.Threading; @@ -85,7 +83,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators artist.ValidateImages(); artist.ValidateBackdrops(); - var musicArtist = FindMusicArtist(artist, allMusicArtists); + var musicArtist = Artist.FindMusicArtist(artist, allMusicArtists); if (musicArtist != null) { @@ -235,26 +233,5 @@ namespace MediaBrowser.Server.Implementations.Library.Validators return returnArtists; } - - /// - /// Finds the music artist. - /// - /// The artist. - /// All music artists. - /// MusicArtist. - private static MusicArtist FindMusicArtist(Artist artist, IEnumerable allMusicArtists) - { - var musicBrainzId = artist.GetProviderId(MetadataProviders.Musicbrainz); - - return allMusicArtists.FirstOrDefault(i => - { - if (!string.IsNullOrWhiteSpace(musicBrainzId) && string.Equals(musicBrainzId, i.GetProviderId(MetadataProviders.Musicbrainz), StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return string.Compare(i.Name, artist.Name, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols) == 0; - }); - } } }