2013-09-10 18:56:00 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Music
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MusicAlbumDynamicInfoProvider
|
|
|
|
|
/// </summary>
|
2013-10-14 15:08:33 +00:00
|
|
|
|
public class AlbumDynamicInfoProvider : BaseMetadataProvider, IDynamicInfoProvider
|
2013-09-10 18:56:00 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="BaseMetadataProvider" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logManager">The log manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
2013-10-14 15:08:33 +00:00
|
|
|
|
public AlbumDynamicInfoProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
|
2013-09-10 18:56:00 +00:00
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item is MusicAlbum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Needses the refresh internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="providerInfo">The provider info.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="force">if set to <c>true</c> [force].</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
|
|
|
|
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var album = (MusicAlbum)item;
|
|
|
|
|
|
|
|
|
|
var songs = album.RecursiveChildren
|
|
|
|
|
.OfType<Audio>()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
album.AlbumArtist = songs
|
|
|
|
|
.Select(i => i.AlbumArtist)
|
|
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
|
|
|
|
|
|
album.Artists = songs.SelectMany(i => i.Artists)
|
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
2013-09-11 17:54:59 +00:00
|
|
|
|
.ToList();
|
2013-09-10 18:56:00 +00:00
|
|
|
|
|
2013-11-15 15:10:56 +00:00
|
|
|
|
var date = songs.Select(i => i.PremiereDate)
|
|
|
|
|
.FirstOrDefault(i => i.HasValue);
|
|
|
|
|
|
|
|
|
|
if (date.HasValue)
|
|
|
|
|
{
|
|
|
|
|
album.PremiereDate = date.Value;
|
|
|
|
|
album.ProductionYear = date.Value.Year;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var year = songs.Select(i => i.ProductionYear ?? 1800).FirstOrDefault(i => i != 1800);
|
|
|
|
|
|
|
|
|
|
if (year != 1800)
|
|
|
|
|
{
|
|
|
|
|
album.ProductionYear = year;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:56:00 +00:00
|
|
|
|
// Don't save to the db
|
|
|
|
|
return FalseTaskResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.Last; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|