2019-01-13 20:03:10 +00:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 19:26:31 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Common.Net;
|
2014-02-09 21:11:11 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
2020-03-02 17:07:31 +00:00
|
|
|
namespace MediaBrowser.Providers.Plugins.AudioDb
|
2014-02-09 21:11:11 +00:00
|
|
|
{
|
|
|
|
public class AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder
|
|
|
|
{
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
private readonly IJsonSerializer _json;
|
|
|
|
|
|
|
|
public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IJsonSerializer json)
|
|
|
|
{
|
|
|
|
_config = config;
|
|
|
|
_httpClient = httpClient;
|
|
|
|
_json = json;
|
|
|
|
}
|
|
|
|
|
2019-09-10 20:37:53 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
public string Name => "TheAudioDB";
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
// After embedded and fanart
|
|
|
|
public int Order => 2;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-02-09 21:11:11 +00:00
|
|
|
{
|
|
|
|
return new List<ImageType>
|
|
|
|
{
|
2019-01-07 23:27:46 +00:00
|
|
|
ImageType.Primary,
|
2014-02-09 21:11:11 +00:00
|
|
|
ImageType.Disc
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-10 20:37:53 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-02-09 21:11:11 +00:00
|
|
|
{
|
|
|
|
var id = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(id))
|
|
|
|
{
|
|
|
|
await AudioDbAlbumProvider.Current.EnsureInfo(id, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
|
|
|
|
|
|
|
|
var obj = _json.DeserializeFromFile<AudioDbAlbumProvider.RootObject>(path);
|
|
|
|
|
|
|
|
if (obj != null && obj.album != null && obj.album.Count > 0)
|
|
|
|
{
|
|
|
|
return GetImages(obj.album[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new List<RemoteImageInfo>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<RemoteImageInfo> GetImages(AudioDbAlbumProvider.Album item)
|
|
|
|
{
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strAlbumThumb))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strAlbumThumb,
|
|
|
|
Type = ImageType.Primary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strAlbumCDart))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strAlbumCDart,
|
|
|
|
Type = ImageType.Disc
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
2019-01-07 23:27:46 +00:00
|
|
|
|
2019-09-10 20:37:53 +00:00
|
|
|
/// <inheritdoc />
|
2014-02-09 21:11:11 +00:00
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return _httpClient.GetResponse(new HttpRequestOptions
|
|
|
|
{
|
|
|
|
CancellationToken = cancellationToken,
|
2016-10-31 18:39:41 +00:00
|
|
|
Url = url
|
2014-02-09 21:11:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-10 20:37:53 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
public bool Supports(BaseItem item) => item is MusicAlbum;
|
2014-02-09 21:11:11 +00:00
|
|
|
}
|
|
|
|
}
|