aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs
diff options
context:
space:
mode:
authordkanada <dkanada@users.noreply.github.com>2020-03-03 02:07:31 +0900
committerdkanada <dkanada@users.noreply.github.com>2020-03-03 02:07:31 +0900
commit76e49a1eb73077ce710591d46a0c7aa5d6d04812 (patch)
treee140f9a347389bbd42ea942e828ab9524a934a85 /MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs
parent1c1484389a897232db89ddd998a3925311a8c9c6 (diff)
migrate audiodb to plugin
Diffstat (limited to 'MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs')
-rw-r--r--MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs107
1 files changed, 107 insertions, 0 deletions
diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs
new file mode 100644
index 0000000000..85719fa51a
--- /dev/null
+++ b/MediaBrowser.Providers/Plugins/AudioDb/AlbumImageProvider.cs
@@ -0,0 +1,107 @@
+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 AudioDbAlbumImageProvider : IRemoteImageProvider, IHasOrder
+ {
+ private readonly IServerConfigurationManager _config;
+ private readonly IHttpClient _httpClient;
+ private readonly IJsonSerializer _json;
+
+ public AudioDbAlbumImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IJsonSerializer json)
+ {
+ _config = config;
+ _httpClient = httpClient;
+ _json = json;
+ }
+
+ /// <inheritdoc />
+ public string Name => "TheAudioDB";
+
+ /// <inheritdoc />
+ // After embedded and fanart
+ public int Order => 2;
+
+ /// <inheritdoc />
+ public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
+ {
+ return new List<ImageType>
+ {
+ ImageType.Primary,
+ ImageType.Disc
+ };
+ }
+
+ /// <inheritdoc />
+ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
+ {
+ var id = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
+
+ if (!string.IsNullOrWhiteSpace(id))
+ {
+ await AudioDbAlbumProvider.Current.EnsureInfo(id, cancellationToken).ConfigureAwait(false);
+
+ var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
+
+ var obj = _json.DeserializeFromFile<AudioDbAlbumProvider.RootObject>(path);
+
+ if (obj != null && obj.album != null && obj.album.Count > 0)
+ {
+ return GetImages(obj.album[0]);
+ }
+ }
+
+ return new List<RemoteImageInfo>();
+ }
+
+ private IEnumerable<RemoteImageInfo> GetImages(AudioDbAlbumProvider.Album item)
+ {
+ var list = new List<RemoteImageInfo>();
+
+ if (!string.IsNullOrWhiteSpace(item.strAlbumThumb))
+ {
+ list.Add(new RemoteImageInfo
+ {
+ ProviderName = Name,
+ Url = item.strAlbumThumb,
+ Type = ImageType.Primary
+ });
+ }
+
+ if (!string.IsNullOrWhiteSpace(item.strAlbumCDart))
+ {
+ list.Add(new RemoteImageInfo
+ {
+ ProviderName = Name,
+ Url = item.strAlbumCDart,
+ Type = ImageType.Disc
+ });
+ }
+
+ return list;
+ }
+
+ /// <inheritdoc />
+ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
+ {
+ return _httpClient.GetResponse(new HttpRequestOptions
+ {
+ CancellationToken = cancellationToken,
+ Url = url
+ });
+ }
+
+ /// <inheritdoc />
+ public bool Supports(BaseItem item) => item is MusicAlbum;
+ }
+}