using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; 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 MediaBrowser.Model.Serialization; using MoreLinq; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Providers.Music { public class LastfmAlbumProvider : LastfmBaseProvider { private static readonly Task BlankId = Task.FromResult(""); public LastfmAlbumProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) : base(jsonSerializer, httpClient, logManager, configurationManager) { } protected override Task FindId(BaseItem item, CancellationToken cancellationToken) { // We don't fetch by id return BlankId; } private bool HasAltMeta(BaseItem item) { return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName("album.xml"); } /// /// Needses the refresh internal. /// /// The item. /// The provider info. /// true if XXXX, false otherwise protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) { if (HasAltMeta(item)) { return false; } // If song metadata has changed and we don't have an mbid, refresh if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Musicbrainz)) && GetComparisonData(item as MusicAlbum) != providerInfo.FileStamp) { return true; } return base.NeedsRefreshInternal(item, providerInfo); } protected override async Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken) { var result = await GetAlbumResult(item, cancellationToken).ConfigureAwait(false); if (result != null && result.album != null) { LastfmHelper.ProcessAlbumData(item, result.album); } BaseProviderInfo data; if (!item.ProviderData.TryGetValue(Id, out data)) { data = new BaseProviderInfo(); item.ProviderData[Id] = data; } data.FileStamp = GetComparisonData(item as MusicAlbum); } private async Task GetAlbumResult(BaseItem item, CancellationToken cancellationToken) { var folder = (Folder)item; // Get each song, distinct by the combination of AlbumArtist and Album var songs = folder.RecursiveChildren.OfType