2021-10-26 09:49:01 -04:00
|
|
|
#nullable disable
|
|
|
|
|
2020-06-19 14:24:13 -04:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 15:03:10 -05:00
|
|
|
using System.Collections.Generic;
|
2020-12-23 07:06:29 -05:00
|
|
|
using System.IO;
|
2023-02-28 18:44:57 -05:00
|
|
|
using System.Linq;
|
2020-08-17 13:56:49 -04:00
|
|
|
using System.Net.Http;
|
2020-12-23 07:06:29 -05:00
|
|
|
using System.Text.Json;
|
2019-01-13 14:26:31 -05:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2021-06-19 12:02:33 -04:00
|
|
|
using Jellyfin.Extensions.Json;
|
2020-08-31 13:05:21 -04:00
|
|
|
using MediaBrowser.Common.Net;
|
2014-02-09 02:27:44 -05:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2021-06-12 16:20:35 -04:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-02-09 02:27:44 -05:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-03-02 12:07:31 -05:00
|
|
|
namespace MediaBrowser.Providers.Plugins.AudioDb
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
|
|
|
public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder
|
|
|
|
{
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2020-08-17 13:56:49 -04:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
2021-03-08 23:57:38 -05:00
|
|
|
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
2014-02-09 02:27:44 -05:00
|
|
|
|
2020-12-23 07:06:29 -05:00
|
|
|
public AudioDbArtistImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
|
|
|
_config = config;
|
2020-08-17 13:56:49 -04:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2014-02-09 02:27:44 -05:00
|
|
|
}
|
|
|
|
|
2019-09-10 16:37:53 -04:00
|
|
|
/// <inheritdoc />
|
|
|
|
public string Name => "TheAudioDB";
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
// After fanart
|
|
|
|
public int Order => 1;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-09-12 13:26:21 -04:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
2023-02-28 18:44:57 -05:00
|
|
|
return new ImageType[]
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
2019-01-07 18:27:46 -05:00
|
|
|
ImageType.Primary,
|
2014-02-09 02:27:44 -05:00
|
|
|
ImageType.Logo,
|
|
|
|
ImageType.Banner,
|
|
|
|
ImageType.Backdrop
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-10 16:37:53 -04:00
|
|
|
/// <inheritdoc />
|
2018-09-12 13:26:21 -04:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
2020-06-06 15:17:49 -04:00
|
|
|
var id = item.GetProviderId(MetadataProvider.MusicBrainzArtist);
|
2014-02-09 02:27:44 -05:00
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(id))
|
|
|
|
{
|
|
|
|
await AudioDbArtistProvider.Current.EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);
|
|
|
|
|
2023-01-11 04:36:18 -05:00
|
|
|
FileStream jsonStream = AsyncFile.OpenRead(path);
|
|
|
|
await using (jsonStream.ConfigureAwait(false))
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
2023-01-11 04:36:18 -05:00
|
|
|
var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
if (obj is not null && obj.artists is not null && obj.artists.Count > 0)
|
|
|
|
{
|
|
|
|
return GetImages(obj.artists[0]);
|
|
|
|
}
|
2014-02-09 02:27:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 18:44:57 -05:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-02-09 02:27:44 -05:00
|
|
|
}
|
|
|
|
|
2023-10-23 18:10:31 -04:00
|
|
|
private List<RemoteImageInfo> GetImages(AudioDbArtistProvider.Artist item)
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strArtistThumb))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strArtistThumb,
|
|
|
|
Type = ImageType.Primary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strArtistLogo))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strArtistLogo,
|
|
|
|
Type = ImageType.Logo
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strArtistBanner))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strArtistBanner,
|
|
|
|
Type = ImageType.Banner
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strArtistFanart))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strArtistFanart,
|
|
|
|
Type = ImageType.Backdrop
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strArtistFanart2))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strArtistFanart2,
|
|
|
|
Type = ImageType.Backdrop
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.strArtistFanart3))
|
|
|
|
{
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
{
|
|
|
|
ProviderName = Name,
|
|
|
|
Url = item.strArtistFanart3,
|
|
|
|
Type = ImageType.Backdrop
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-08-17 13:56:49 -04:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-02-09 02:27:44 -05:00
|
|
|
{
|
2020-08-31 13:05:21 -04:00
|
|
|
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
|
2020-08-17 13:56:49 -04:00
|
|
|
return httpClient.GetAsync(url, cancellationToken);
|
2014-02-09 02:27:44 -05:00
|
|
|
}
|
|
|
|
|
2019-09-10 16:37:53 -04:00
|
|
|
/// <inheritdoc />
|
2020-03-07 22:10:25 -05:00
|
|
|
public bool Supports(BaseItem item)
|
2020-11-28 09:55:56 -05:00
|
|
|
=> item is MusicArtist;
|
2014-02-09 02:27:44 -05:00
|
|
|
}
|
|
|
|
}
|