using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Providers.Music { public class LastfmAlbumProvider : IRemoteMetadataProvider, IHasOrder { private readonly IJsonSerializer _json; private readonly IHttpClient _httpClient; private readonly IServerConfigurationManager _config; private readonly ILogger _logger; public LastfmAlbumProvider(IHttpClient httpClient, IJsonSerializer json, IServerConfigurationManager config, ILogger logger) { _httpClient = httpClient; _json = json; _config = config; _logger = logger; } public async Task> GetMetadata(ItemId id, CancellationToken cancellationToken) { var result = new MetadataResult(); var lastFmData = await GetAlbumResult((AlbumId)id, cancellationToken).ConfigureAwait(false); if (lastFmData != null && lastFmData.album != null) { result.HasMetadata = true; ProcessAlbumData(result.Item, lastFmData.album); } return result; } private async Task GetAlbumResult(AlbumId item, CancellationToken cancellationToken) { // Try album release Id if (!string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Musicbrainz))) { var result = await GetAlbumResult(item.GetProviderId(MetadataProviders.Musicbrainz), cancellationToken).ConfigureAwait(false); if (result != null && result.album != null) { return result; } } // Try album release group Id if (!string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup))) { var result = await GetAlbumResult(item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup), cancellationToken).ConfigureAwait(false); if (result != null && result.album != null) { return result; } } //// Get each song, distinct by the combination of AlbumArtist and Album //var songs = item.RecursiveChildren.OfType