| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | #pragma warning disable CS1591using System.Collections.Generic;using System.IO;using System.Net.Http;using System.Text.Json;using System.Threading;using System.Threading.Tasks;using MediaBrowser.Common.Json;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;namespace MediaBrowser.Providers.Plugins.AudioDb{    public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder    {        private readonly IServerConfigurationManager _config;        private readonly IHttpClientFactory _httpClientFactory;        private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;        public AudioDbArtistImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)        {            _config = config;            _httpClientFactory = httpClientFactory;        }        /// <inheritdoc />        public string Name => "TheAudioDB";        /// <inheritdoc />        // After fanart        public int Order => 1;        /// <inheritdoc />        public IEnumerable<ImageType> GetSupportedImages(BaseItem item)        {            return new List<ImageType>            {                ImageType.Primary,                ImageType.Logo,                ImageType.Banner,                ImageType.Backdrop            };        }        /// <inheritdoc />        public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)        {            var id = item.GetProviderId(MetadataProvider.MusicBrainzArtist);            if (!string.IsNullOrWhiteSpace(id))            {                await AudioDbArtistProvider.Current.EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false);                var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);                await using FileStream jsonStream = File.OpenRead(path);                var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);                if (obj != null && obj.artists != null && obj.artists.Count > 0)                {                    return GetImages(obj.artists[0]);                }            }            return new List<RemoteImageInfo>();        }        private IEnumerable<RemoteImageInfo> GetImages(AudioDbArtistProvider.Artist item)        {            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;        }        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)            => item is MusicArtist;    }}
 |