using Jellyfin.Plugin.MetaShark.Api; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; namespace Jellyfin.Plugin.MetaShark.Providers { public class PersonImageProvider : BaseProvider, IRemoteImageProvider { public PersonImageProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi) : base(httpClientFactory, loggerFactory.CreateLogger(), libraryManager, httpContextAccessor, doubanApi, tmdbApi, omdbApi) { } /// public string Name => Plugin.PluginName; /// public bool Supports(BaseItem item) => item is Person; /// public IEnumerable GetSupportedImages(BaseItem item) { yield return ImageType.Primary; } /// public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) { var cid = item.GetProviderId(DoubanProviderId); var metaSource = item.GetProviderId(Plugin.ProviderId); this.Log($"GetImages for item: {item.Name} [metaSource]: {metaSource}"); if (!string.IsNullOrEmpty(cid)) { var celebrity = await this._doubanApi.GetCelebrityAsync(cid, cancellationToken).ConfigureAwait(false); if (celebrity != null) { return new List { new RemoteImageInfo { ProviderName = celebrity.Name, Url = this.GetProxyImageUrl(celebrity.Img), Type = ImageType.Primary } }; } } this.Log($"Got images failed because the images of \"{item.Name}\" is empty!"); return new List(); } } }