using System;
using System.Collections.Generic;
using System.Linq;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
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 album metadata service.
///
public class AlbumMetadataService : 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 AlbumMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
///
protected override bool EnableUpdatingPremiereDateFromChildren => true;
///
protected override bool EnableUpdatingGenresFromChildren => true;
///
protected override bool EnableUpdatingStudiosFromChildren => true;
///
protected override IList GetChildrenForMetadataUpdates(MusicAlbum item)
=> item.GetRecursiveChildren(i => i is Audio);
///
protected override ItemUpdateType UpdateMetadataFromChildren(MusicAlbum item, IList children, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.UpdateMetadataFromChildren(item, children, isFullRefresh, currentUpdateType);
// don't update user-changeable metadata for locked items
if (item.IsLocked)
{
return updateType;
}
if (isFullRefresh || currentUpdateType > ItemUpdateType.None)
{
if (!item.LockedFields.Contains(MetadataField.Name))
{
var name = children.Select(i => i.Album).FirstOrDefault(i => !string.IsNullOrEmpty(i));
if (!string.IsNullOrEmpty(name)
&& !string.Equals(item.Name, name, StringComparison.Ordinal))
{
item.Name = name;
updateType |= ItemUpdateType.MetadataEdit;
}
}
var songs = children.Cast