| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using MediaBrowser.Controller.Configuration; |
| | 4 | | using MediaBrowser.Controller.Entities.Audio; |
| | 5 | | using MediaBrowser.Controller.Library; |
| | 6 | | using MediaBrowser.Controller.Providers; |
| | 7 | | using MediaBrowser.Model.Entities; |
| | 8 | | using MediaBrowser.Model.IO; |
| | 9 | | using MediaBrowser.Providers.Manager; |
| | 10 | | using Microsoft.Extensions.Logging; |
| | 11 | |
|
| | 12 | | namespace MediaBrowser.Providers.Music |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// The audio metadata service. |
| | 16 | | /// </summary> |
| | 17 | | public class AudioMetadataService : MetadataService<Audio, SongInfo> |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Initializes a new instance of the <see cref="AudioMetadataService"/> class. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/>.</param> |
| | 23 | | /// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param> |
| | 24 | | /// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param> |
| | 25 | | /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param> |
| | 26 | | /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> |
| | 27 | | public AudioMetadataService( |
| | 28 | | IServerConfigurationManager serverConfigurationManager, |
| | 29 | | ILogger<AudioMetadataService> logger, |
| | 30 | | IProviderManager providerManager, |
| | 31 | | IFileSystem fileSystem, |
| | 32 | | ILibraryManager libraryManager) |
| 21 | 33 | | : base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager) |
| | 34 | | { |
| 21 | 35 | | } |
| | 36 | |
|
| | 37 | | private void SetProviderId(Audio sourceItem, Audio targetItem, bool replaceData, MetadataProvider provider) |
| | 38 | | { |
| 0 | 39 | | var target = targetItem.GetProviderId(provider); |
| 0 | 40 | | if (replaceData || string.IsNullOrEmpty(target)) |
| | 41 | | { |
| 0 | 42 | | var source = sourceItem.GetProviderId(provider); |
| 0 | 43 | | if (!string.IsNullOrEmpty(source) |
| 0 | 44 | | && (string.IsNullOrEmpty(target) |
| 0 | 45 | | || !target.Equals(source, StringComparison.Ordinal))) |
| | 46 | | { |
| 0 | 47 | | targetItem.SetProviderId(provider, source); |
| | 48 | | } |
| | 49 | | } |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | /// <inheritdoc /> |
| | 53 | | protected override void MergeData(MetadataResult<Audio> source, MetadataResult<Audio> target, MetadataField[] lo |
| | 54 | | { |
| 0 | 55 | | base.MergeData(source, target, lockedFields, replaceData, mergeMetadataSettings); |
| | 56 | |
|
| 0 | 57 | | var sourceItem = source.Item; |
| 0 | 58 | | var targetItem = target.Item; |
| | 59 | |
|
| 0 | 60 | | if (replaceData || targetItem.Artists.Count == 0) |
| | 61 | | { |
| 0 | 62 | | targetItem.Artists = sourceItem.Artists; |
| | 63 | | } |
| | 64 | | else |
| | 65 | | { |
| 0 | 66 | | targetItem.Artists = targetItem.Artists.Concat(sourceItem.Artists).Distinct().ToArray(); |
| | 67 | | } |
| | 68 | |
|
| 0 | 69 | | if (replaceData || string.IsNullOrEmpty(targetItem.Album)) |
| | 70 | | { |
| 0 | 71 | | targetItem.Album = sourceItem.Album; |
| | 72 | | } |
| | 73 | |
|
| 0 | 74 | | SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzAlbumArtist); |
| 0 | 75 | | SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzAlbum); |
| 0 | 76 | | SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzReleaseGroup); |
| 0 | 77 | | } |
| | 78 | | } |
| | 79 | | } |