< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Plugins.AudioDb.AudioDbArtistImageProvider
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistImageProvider.cs
Line coverage
8%
Covered lines: 5
Uncovered lines: 55
Coverable lines: 60
Total lines: 158
Line coverage: 8.3%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%210%
get_Order()100%210%
GetSupportedImages(...)100%210%
GetImages(...)0%156120%
GetImageResponse(...)100%210%
Supports(...)100%11100%

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistImageProvider.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System.Collections.Generic;
 6using System.IO;
 7using System.Linq;
 8using System.Net.Http;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Jellyfin.Extensions.Json;
 13using MediaBrowser.Common.Net;
 14using MediaBrowser.Controller.Configuration;
 15using MediaBrowser.Controller.Entities;
 16using MediaBrowser.Controller.Entities.Audio;
 17using MediaBrowser.Controller.Providers;
 18using MediaBrowser.Model.Entities;
 19using MediaBrowser.Model.IO;
 20using MediaBrowser.Model.Providers;
 21
 22namespace MediaBrowser.Providers.Plugins.AudioDb
 23{
 24    public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder
 25    {
 26        private readonly IServerConfigurationManager _config;
 27        private readonly IHttpClientFactory _httpClientFactory;
 2228        private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
 29
 30        public AudioDbArtistImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)
 31        {
 2232            _config = config;
 2233            _httpClientFactory = httpClientFactory;
 2234        }
 35
 36        /// <inheritdoc />
 037        public string Name => "TheAudioDB";
 38
 39        /// <inheritdoc />
 40        // After fanart
 041        public int Order => 1;
 42
 43        /// <inheritdoc />
 44        public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
 45        {
 046            return new ImageType[]
 047            {
 048                ImageType.Primary,
 049                ImageType.Logo,
 050                ImageType.Banner,
 051                ImageType.Backdrop
 052            };
 53        }
 54
 55        /// <inheritdoc />
 56        public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
 57        {
 58            var id = item.GetProviderId(MetadataProvider.MusicBrainzArtist);
 59
 60            if (!string.IsNullOrWhiteSpace(id))
 61            {
 62                await AudioDbArtistProvider.Current.EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false);
 63
 64                var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);
 65
 66                FileStream jsonStream = AsyncFile.OpenRead(path);
 67                await using (jsonStream.ConfigureAwait(false))
 68                {
 69                    var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, _jsonO
 70
 71                    if (obj is not null && obj.artists is not null && obj.artists.Count > 0)
 72                    {
 73                        return GetImages(obj.artists[0]);
 74                    }
 75                }
 76            }
 77
 78            return Enumerable.Empty<RemoteImageInfo>();
 79        }
 80
 81        private List<RemoteImageInfo> GetImages(AudioDbArtistProvider.Artist item)
 82        {
 083            var list = new List<RemoteImageInfo>();
 84
 085            if (!string.IsNullOrWhiteSpace(item.strArtistThumb))
 86            {
 087                list.Add(new RemoteImageInfo
 088                {
 089                    ProviderName = Name,
 090                    Url = item.strArtistThumb,
 091                    Type = ImageType.Primary
 092                });
 93            }
 94
 095            if (!string.IsNullOrWhiteSpace(item.strArtistLogo))
 96            {
 097                list.Add(new RemoteImageInfo
 098                {
 099                    ProviderName = Name,
 0100                    Url = item.strArtistLogo,
 0101                    Type = ImageType.Logo
 0102                });
 103            }
 104
 0105            if (!string.IsNullOrWhiteSpace(item.strArtistBanner))
 106            {
 0107                list.Add(new RemoteImageInfo
 0108                {
 0109                    ProviderName = Name,
 0110                    Url = item.strArtistBanner,
 0111                    Type = ImageType.Banner
 0112                });
 113            }
 114
 0115            if (!string.IsNullOrWhiteSpace(item.strArtistFanart))
 116            {
 0117                list.Add(new RemoteImageInfo
 0118                {
 0119                    ProviderName = Name,
 0120                    Url = item.strArtistFanart,
 0121                    Type = ImageType.Backdrop
 0122                });
 123            }
 124
 0125            if (!string.IsNullOrWhiteSpace(item.strArtistFanart2))
 126            {
 0127                list.Add(new RemoteImageInfo
 0128                {
 0129                    ProviderName = Name,
 0130                    Url = item.strArtistFanart2,
 0131                    Type = ImageType.Backdrop
 0132                });
 133            }
 134
 0135            if (!string.IsNullOrWhiteSpace(item.strArtistFanart3))
 136            {
 0137                list.Add(new RemoteImageInfo
 0138                {
 0139                    ProviderName = Name,
 0140                    Url = item.strArtistFanart3,
 0141                    Type = ImageType.Backdrop
 0142                });
 143            }
 144
 0145            return list;
 146        }
 147
 148        public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
 149        {
 0150            var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
 0151            return httpClient.GetAsync(url, cancellationToken);
 152        }
 153
 154        /// <inheritdoc />
 155        public bool Supports(BaseItem item)
 46156            => item is MusicArtist;
 157    }
 158}