97 lines
3.8 KiB
C#
97 lines
3.8 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MovieImageProvider"/> class.
|
|
/// </summary>
|
|
/// <param name="httpClientFactory">Instance of the <see cref="IHttpClientFactory"/> interface.</param>
|
|
/// <param name="logger">Instance of the <see cref="ILogger{OddbImageProvider}"/> interface.</param>
|
|
/// <param name="doubanApi">Instance of <see cref="DoubanApi"/>.</param>
|
|
public PersonImageProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi)
|
|
: base(httpClientFactory, loggerFactory.CreateLogger<PersonImageProvider>(), libraryManager, httpContextAccessor, doubanApi, tmdbApi, omdbApi)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public string Name => Plugin.PluginName;
|
|
|
|
/// <inheritdoc />
|
|
public bool Supports(BaseItem item) => item is Person;
|
|
|
|
/// <inheritdoc />
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
|
{
|
|
yield return ImageType.Primary;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<IEnumerable<RemoteImageInfo>> 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<RemoteImageInfo> {
|
|
new RemoteImageInfo
|
|
{
|
|
ProviderName = celebrity.Name,
|
|
Url = celebrity.Img,
|
|
Type = ImageType.Primary
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
|
|
return new List<RemoteImageInfo>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query for a background photo
|
|
/// </summary>
|
|
/// <param name="sid">a subject/movie id</param>
|
|
/// <param name="cancellationToken">Instance of the <see cref="CancellationToken"/> interface.</param>
|
|
private async Task<IEnumerable<RemoteImageInfo>> GetBackdrop(string sid, CancellationToken cancellationToken)
|
|
{
|
|
this.Log("GetBackdrop of sid: {0}", sid);
|
|
var photo = await this._doubanApi.GetWallpaperBySidAsync(sid, cancellationToken);
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
if (photo == null)
|
|
{
|
|
return list;
|
|
}
|
|
|
|
return photo.Where(x => x.Width > x.Height * 1.3).Select(x =>
|
|
{
|
|
return new RemoteImageInfo
|
|
{
|
|
ProviderName = Name,
|
|
Url = x.Large,
|
|
Type = ImageType.Backdrop,
|
|
};
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|