| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | #pragma warning disable CS1591 |
| | | 4 | | |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Net.Http; |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using MediaBrowser.Common.Net; |
| | | 10 | | using MediaBrowser.Controller.Entities; |
| | | 11 | | using MediaBrowser.Controller.Entities.Audio; |
| | | 12 | | using MediaBrowser.Controller.Providers; |
| | | 13 | | using MediaBrowser.Model.Entities; |
| | | 14 | | using MediaBrowser.Model.Providers; |
| | | 15 | | |
| | | 16 | | namespace MediaBrowser.Providers.Plugins.AudioDb |
| | | 17 | | { |
| | | 18 | | public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder |
| | | 19 | | { |
| | | 20 | | private readonly IHttpClientFactory _httpClientFactory; |
| | | 21 | | |
| | | 22 | | public AudioDbArtistImageProvider(IHttpClientFactory httpClientFactory) |
| | | 23 | | { |
| | 22 | 24 | | _httpClientFactory = httpClientFactory; |
| | 22 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | 0 | 28 | | public string Name => "TheAudioDB"; |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | // After fanart |
| | 0 | 32 | | public int Order => 1; |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | | 35 | | public IEnumerable<ImageType> GetSupportedImages(BaseItem item) |
| | | 36 | | { |
| | 0 | 37 | | return |
| | 0 | 38 | | [ |
| | 0 | 39 | | ImageType.Primary, |
| | 0 | 40 | | ImageType.Logo, |
| | 0 | 41 | | ImageType.Banner, |
| | 0 | 42 | | ImageType.Backdrop |
| | 0 | 43 | | ]; |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <inheritdoc /> |
| | | 47 | | public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) |
| | | 48 | | { |
| | 0 | 49 | | item.TryGetProviderId(MetadataProvider.MusicBrainzArtist, out var musicBrainzId); |
| | 0 | 50 | | item.TryGetProviderId(MetadataProvider.AudioDbArtist, out var audioDbId); |
| | | 51 | | |
| | 0 | 52 | | var artist = await AudioDbArtistProvider.Current.GetArtist(musicBrainzId, audioDbId, cancellationToken).Conf |
| | | 53 | | |
| | 0 | 54 | | if (artist is not null) |
| | | 55 | | { |
| | 0 | 56 | | return GetImages(artist); |
| | | 57 | | } |
| | | 58 | | |
| | 0 | 59 | | return []; |
| | 0 | 60 | | } |
| | | 61 | | |
| | | 62 | | private List<RemoteImageInfo> GetImages(AudioDbArtistProvider.Artist item) |
| | | 63 | | { |
| | 0 | 64 | | var list = new List<RemoteImageInfo>(); |
| | | 65 | | |
| | 0 | 66 | | if (!string.IsNullOrWhiteSpace(item.strArtistThumb)) |
| | | 67 | | { |
| | 0 | 68 | | list.Add(new RemoteImageInfo |
| | 0 | 69 | | { |
| | 0 | 70 | | ProviderName = Name, |
| | 0 | 71 | | Url = item.strArtistThumb, |
| | 0 | 72 | | Type = ImageType.Primary |
| | 0 | 73 | | }); |
| | | 74 | | } |
| | | 75 | | |
| | 0 | 76 | | if (!string.IsNullOrWhiteSpace(item.strArtistLogo)) |
| | | 77 | | { |
| | 0 | 78 | | list.Add(new RemoteImageInfo |
| | 0 | 79 | | { |
| | 0 | 80 | | ProviderName = Name, |
| | 0 | 81 | | Url = item.strArtistLogo, |
| | 0 | 82 | | Type = ImageType.Logo |
| | 0 | 83 | | }); |
| | | 84 | | } |
| | | 85 | | |
| | 0 | 86 | | if (!string.IsNullOrWhiteSpace(item.strArtistBanner)) |
| | | 87 | | { |
| | 0 | 88 | | list.Add(new RemoteImageInfo |
| | 0 | 89 | | { |
| | 0 | 90 | | ProviderName = Name, |
| | 0 | 91 | | Url = item.strArtistBanner, |
| | 0 | 92 | | Type = ImageType.Banner |
| | 0 | 93 | | }); |
| | | 94 | | } |
| | | 95 | | |
| | 0 | 96 | | if (!string.IsNullOrWhiteSpace(item.strArtistFanart)) |
| | | 97 | | { |
| | 0 | 98 | | list.Add(new RemoteImageInfo |
| | 0 | 99 | | { |
| | 0 | 100 | | ProviderName = Name, |
| | 0 | 101 | | Url = item.strArtistFanart, |
| | 0 | 102 | | Type = ImageType.Backdrop |
| | 0 | 103 | | }); |
| | | 104 | | } |
| | | 105 | | |
| | 0 | 106 | | if (!string.IsNullOrWhiteSpace(item.strArtistFanart2)) |
| | | 107 | | { |
| | 0 | 108 | | list.Add(new RemoteImageInfo |
| | 0 | 109 | | { |
| | 0 | 110 | | ProviderName = Name, |
| | 0 | 111 | | Url = item.strArtistFanart2, |
| | 0 | 112 | | Type = ImageType.Backdrop |
| | 0 | 113 | | }); |
| | | 114 | | } |
| | | 115 | | |
| | 0 | 116 | | if (!string.IsNullOrWhiteSpace(item.strArtistFanart3)) |
| | | 117 | | { |
| | 0 | 118 | | list.Add(new RemoteImageInfo |
| | 0 | 119 | | { |
| | 0 | 120 | | ProviderName = Name, |
| | 0 | 121 | | Url = item.strArtistFanart3, |
| | 0 | 122 | | Type = ImageType.Backdrop |
| | 0 | 123 | | }); |
| | | 124 | | } |
| | | 125 | | |
| | 0 | 126 | | return list; |
| | | 127 | | } |
| | | 128 | | |
| | | 129 | | public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) |
| | | 130 | | { |
| | 0 | 131 | | var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); |
| | 0 | 132 | | return httpClient.GetAsync(url, cancellationToken); |
| | | 133 | | } |
| | | 134 | | |
| | | 135 | | /// <inheritdoc /> |
| | | 136 | | public bool Supports(BaseItem item) |
| | 61 | 137 | | => item is MusicArtist; |
| | | 138 | | } |
| | | 139 | | } |