using Jellyfin.Plugin.MetaShark.Api;
using Jellyfin.Plugin.MetaShark.Core;
using Jellyfin.Plugin.MetaShark.Model;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TMDbLib.Objects.Languages;
namespace Jellyfin.Plugin.MetaShark.Providers
{
public class PersonImageProvider : BaseProvider, IRemoteImageProvider
{
///
/// Initializes a new instance of the class.
///
/// Instance of the interface.
/// Instance of the interface.
/// Instance of .
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 = celebrity.Img,
Type = ImageType.Primary
}
};
}
}
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
return new List();
}
///
public async Task GetImageResponse(string url, CancellationToken cancellationToken)
{
this.Log("GetImageResponse url: {0}", url);
return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false);
}
///
/// Query for a background photo
///
/// a subject/movie id
/// Instance of the interface.
private async Task> GetBackdrop(string sid, CancellationToken cancellationToken)
{
this.Log("GetBackdrop of sid: {0}", sid);
var photo = await this._doubanApi.GetWallpaperBySidAsync(sid, cancellationToken);
var list = new List();
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,
};
});
}
}
}