< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Plugins.AudioDb.AudioDbAlbumImageProvider
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Plugins/AudioDb/AudioDbAlbumImageProvider.cs
Line coverage
20%
Covered lines: 5
Uncovered lines: 20
Coverable lines: 25
Total lines: 111
Line coverage: 20%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
GetImages(...)0%2040%
GetImageResponse(...)100%210%
Supports(...)100%11100%

File(s)

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

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System.Collections.Generic;
 6using System.IO;
 7using System.Net.Http;
 8using System.Text.Json;
 9using System.Threading;
 10using System.Threading.Tasks;
 11using Jellyfin.Extensions.Json;
 12using MediaBrowser.Common.Net;
 13using MediaBrowser.Controller.Configuration;
 14using MediaBrowser.Controller.Entities;
 15using MediaBrowser.Controller.Entities.Audio;
 16using MediaBrowser.Controller.Providers;
 17using MediaBrowser.Model.Entities;
 18using MediaBrowser.Model.IO;
 19using MediaBrowser.Model.Providers;
 20
 21namespace MediaBrowser.Providers.Plugins.AudioDb
 22{
 23    public class AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder
 24    {
 25        private readonly IServerConfigurationManager _config;
 26        private readonly IHttpClientFactory _httpClientFactory;
 2127        private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
 28
 29        public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory)
 30        {
 2131            _config = config;
 2132            _httpClientFactory = httpClientFactory;
 2133        }
 34
 35        /// <inheritdoc />
 036        public string Name => "TheAudioDB";
 37
 38        /// <inheritdoc />
 39        // After embedded and fanart
 040        public int Order => 2;
 41
 42        /// <inheritdoc />
 43        public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
 44        {
 45            yield return ImageType.Primary;
 46            yield return ImageType.Disc;
 47        }
 48
 49        /// <inheritdoc />
 50        public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
 51        {
 52            if (item.TryGetProviderId(MetadataProvider.MusicBrainzReleaseGroup, out var id))
 53            {
 54                await AudioDbAlbumProvider.Current.EnsureInfo(id, cancellationToken).ConfigureAwait(false);
 55
 56                var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
 57
 58                FileStream jsonStream = AsyncFile.OpenRead(path);
 59                await using (jsonStream.ConfigureAwait(false))
 60                {
 61                    var obj = await JsonSerializer.DeserializeAsync<AudioDbAlbumProvider.RootObject>(jsonStream, _jsonOp
 62
 63                    if (obj is not null && obj.album is not null && obj.album.Count > 0)
 64                    {
 65                        return GetImages(obj.album[0]);
 66                    }
 67                }
 68            }
 69
 70            return [];
 71        }
 72
 73        private List<RemoteImageInfo> GetImages(AudioDbAlbumProvider.Album item)
 74        {
 075            var list = new List<RemoteImageInfo>();
 76
 077            if (!string.IsNullOrWhiteSpace(item.strAlbumThumb))
 78            {
 079                list.Add(new RemoteImageInfo
 080                {
 081                    ProviderName = Name,
 082                    Url = item.strAlbumThumb,
 083                    Type = ImageType.Primary
 084                });
 85            }
 86
 087            if (!string.IsNullOrWhiteSpace(item.strAlbumCDart))
 88            {
 089                list.Add(new RemoteImageInfo
 090                {
 091                    ProviderName = Name,
 092                    Url = item.strAlbumCDart,
 093                    Type = ImageType.Disc
 094                });
 95            }
 96
 097            return list;
 98        }
 99
 100        /// <inheritdoc />
 101        public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
 102        {
 0103            var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
 0104            return httpClient.GetAsync(url, cancellationToken);
 105        }
 106
 107        /// <inheritdoc />
 108        public bool Supports(BaseItem item)
 53109            => item is MusicAlbum;
 110    }
 111}