You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.5 KiB
109 lines
3.5 KiB
#pragma warning disable CS1591
|
|
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
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.Providers;
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
namespace MediaBrowser.Providers.Plugins.AudioDb
|
|
{
|
|
public class AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder
|
|
{
|
|
private readonly IServerConfigurationManager _config;
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly IJsonSerializer _json;
|
|
|
|
public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IJsonSerializer json)
|
|
{
|
|
_config = config;
|
|
_httpClientFactory = httpClientFactory;
|
|
_json = json;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public string Name => "TheAudioDB";
|
|
|
|
/// <inheritdoc />
|
|
// After embedded and fanart
|
|
public int Order => 2;
|
|
|
|
/// <inheritdoc />
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
|
{
|
|
return new List<ImageType>
|
|
{
|
|
ImageType.Primary,
|
|
ImageType.Disc
|
|
};
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
|
{
|
|
var id = item.GetProviderId(MetadataProvider.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;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
{
|
|
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
|
|
return httpClient.GetAsync(url, cancellationToken);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public bool Supports(BaseItem item)
|
|
=> Plugin.Instance.Configuration.Enable && item is MusicAlbum;
|
|
}
|
|
}
|