using System;
using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Providers.Manager;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Music
{
///
/// The audio metadata service.
///
public class AudioMetadataService : MetadataService
{
///
/// Initializes a new instance of the class.
///
/// Instance of the .
/// Instance of the interface.
/// Instance of the interface.
/// Instance of the interface.
/// Instance of the interface.
public AudioMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
private void SetProviderId(Audio sourceItem, Audio targetItem, bool replaceData, MetadataProvider provider)
{
var target = targetItem.GetProviderId(provider);
if (replaceData || string.IsNullOrEmpty(target))
{
var source = sourceItem.GetProviderId(provider);
if (!string.IsNullOrEmpty(source)
&& (string.IsNullOrEmpty(target)
|| !target.Equals(source, StringComparison.Ordinal)))
{
targetItem.SetProviderId(provider, source);
}
}
}
///
protected override void MergeData(MetadataResult source, MetadataResult target, MetadataField[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
base.MergeData(source, target, lockedFields, replaceData, mergeMetadataSettings);
var sourceItem = source.Item;
var targetItem = target.Item;
if (replaceData || targetItem.Artists.Count == 0)
{
targetItem.Artists = sourceItem.Artists;
}
else
{
targetItem.Artists = targetItem.Artists.Concat(sourceItem.Artists).Distinct().ToArray();
}
if (replaceData || string.IsNullOrEmpty(targetItem.Album))
{
targetItem.Album = sourceItem.Album;
}
SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzAlbumArtist);
SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzAlbum);
SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzReleaseGroup);
}
}
}