2013-08-07 17:11:02 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Music
|
|
|
|
|
{
|
|
|
|
|
public class ArtistInfoFromSongProvider : BaseMetadataProvider
|
|
|
|
|
{
|
|
|
|
|
public ArtistInfoFromSongProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
|
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item is MusicArtist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
2013-11-21 20:48:26 +00:00
|
|
|
|
var artist = (MusicArtist)item;
|
|
|
|
|
|
|
|
|
|
if (!artist.IsAccessedByName)
|
2013-08-07 17:11:02 +00:00
|
|
|
|
{
|
2013-11-21 20:48:26 +00:00
|
|
|
|
// If song metadata has changed
|
|
|
|
|
if (GetComparisonData(artist) != providerInfo.FileStamp)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-08-07 17:11:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.NeedsRefreshInternal(item, providerInfo);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="artist">The artist.</param>
|
|
|
|
|
/// <returns>Guid.</returns>
|
|
|
|
|
private Guid GetComparisonData(MusicArtist artist)
|
|
|
|
|
{
|
|
|
|
|
var songs = artist.RecursiveChildren.OfType<Audio>().ToList();
|
|
|
|
|
|
|
|
|
|
return GetComparisonData(songs);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-21 20:48:26 +00:00
|
|
|
|
private Guid GetComparisonData(IEnumerable<Audio> songs)
|
2013-08-07 17:11:02 +00:00
|
|
|
|
{
|
|
|
|
|
var genres = songs.SelectMany(i => i.Genres)
|
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return string.Join(string.Empty, genres.OrderBy(i => i).ToArray()).GetMD5();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var artist = (MusicArtist)item;
|
|
|
|
|
|
2013-11-21 20:48:26 +00:00
|
|
|
|
if (!artist.IsAccessedByName)
|
2013-08-07 17:11:02 +00:00
|
|
|
|
{
|
2013-11-21 20:48:26 +00:00
|
|
|
|
BaseProviderInfo data;
|
|
|
|
|
if (!item.ProviderData.TryGetValue(Id, out data))
|
|
|
|
|
{
|
|
|
|
|
data = new BaseProviderInfo();
|
|
|
|
|
item.ProviderData[Id] = data;
|
|
|
|
|
}
|
2013-08-07 17:11:02 +00:00
|
|
|
|
|
2013-11-21 20:48:26 +00:00
|
|
|
|
var songs = artist.RecursiveChildren.OfType<Audio>().ToList();
|
2013-08-07 17:11:02 +00:00
|
|
|
|
|
2013-11-21 20:48:26 +00:00
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Genres))
|
|
|
|
|
{
|
|
|
|
|
artist.Genres = songs.SelectMany(i => i.Genres)
|
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2013-08-07 17:11:02 +00:00
|
|
|
|
|
2013-11-21 20:48:26 +00:00
|
|
|
|
data.FileStamp = GetComparisonData(songs);
|
|
|
|
|
}
|
2013-08-07 17:11:02 +00:00
|
|
|
|
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
return TrueTaskResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.Second; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|