ArtistMetadataService.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using MediaBrowser.Controller.Configuration;
  2. using MediaBrowser.Controller.Entities.Audio;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Controller.Providers;
  5. using MediaBrowser.Model.Entities;
  6. using MediaBrowser.Model.Logging;
  7. using MediaBrowser.Providers.Manager;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. using MediaBrowser.Model.IO;
  13. namespace MediaBrowser.Providers.Music
  14. {
  15. public class ArtistMetadataService : MetadataService<MusicArtist, ArtistInfo>
  16. {
  17. protected override ItemUpdateType BeforeSaveInternal(MusicArtist item, bool isFullRefresh, ItemUpdateType currentUpdateType)
  18. {
  19. var updateType = base.BeforeSaveInternal(item, isFullRefresh, currentUpdateType);
  20. if (isFullRefresh || currentUpdateType > ItemUpdateType.None)
  21. {
  22. if (!item.IsLocked && !item.LockedFields.Contains(MetadataFields.Genres))
  23. {
  24. var taggedItems = item.IsAccessedByName ?
  25. item.GetTaggedItems(new Controller.Entities.InternalItemsQuery()
  26. {
  27. Recursive = true,
  28. IsFolder = false
  29. }) :
  30. item.GetRecursiveChildren(i => i is IHasArtist && !i.IsFolder);
  31. var currentList = item.Genres;
  32. item.Genres = taggedItems.SelectMany(i => i.Genres)
  33. .DistinctNames()
  34. .ToList();
  35. if (currentList.Count != item.Genres.Count || !currentList.OrderBy(i => i).SequenceEqual(item.Genres.OrderBy(i => i), StringComparer.OrdinalIgnoreCase))
  36. {
  37. updateType = updateType | ItemUpdateType.MetadataEdit;
  38. }
  39. }
  40. }
  41. return updateType;
  42. }
  43. protected override void MergeData(MetadataResult<MusicArtist> source, MetadataResult<MusicArtist> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
  44. {
  45. ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
  46. }
  47. public ArtistMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
  48. {
  49. }
  50. }
  51. }