diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2020-03-08 17:06:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-08 17:06:22 -0400 |
| commit | 623c0b6daa4c1486c336e0f7885c10e666c2f1fe (patch) | |
| tree | c888da79a32142901fcb7ba7d5da9c8ff6d5a025 /MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs | |
| parent | d8d37671ff0a009a106320c20851c78f5c666747 (diff) | |
| parent | f8b391538d9283879e962e0dbffed12dc6024a7d (diff) | |
Merge pull request #2536 from dkanada/audiodbv10.5.0
Migrate AudioDB to use plugin interface
Diffstat (limited to 'MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs')
| -rw-r--r-- | MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs new file mode 100644 index 000000000..18afd5dd5 --- /dev/null +++ b/MediaBrowser.Providers/Plugins/AudioDb/ArtistImageProvider.cs @@ -0,0 +1,149 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +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; +using MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Providers.Plugins.AudioDb +{ + public class AudioDbArtistImageProvider : IRemoteImageProvider, IHasOrder + { + private readonly IServerConfigurationManager _config; + private readonly IHttpClient _httpClient; + private readonly IJsonSerializer _json; + + public AudioDbArtistImageProvider(IServerConfigurationManager config, IJsonSerializer json, IHttpClient httpClient) + { + _config = config; + _json = json; + _httpClient = httpClient; + } + + /// <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(MetadataProviders.MusicBrainzArtist); + + if (!string.IsNullOrWhiteSpace(id)) + { + await AudioDbArtistProvider.Current.EnsureArtistInfo(id, cancellationToken).ConfigureAwait(false); + + var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id); + + var obj = _json.DeserializeFromFile<AudioDbArtistProvider.RootObject>(path); + + 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<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken) + { + return _httpClient.GetResponse(new HttpRequestOptions + { + CancellationToken = cancellationToken, + Url = url + }); + } + + /// <inheritdoc /> + public bool Supports(BaseItem item) + => Plugin.Instance.Configuration.Enable && item is MusicArtist; + } +} |
