Huge refactoring
Added person info provider Added person image provider Added trailers fetching
This commit is contained in:
1 parent
35ce5536be
commit
fce88168e8
43 files changed
+4381
-540
No files matched your search
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using KinopoiskUnofficialInfo.ApiClient;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
@@ -17,15 +17,15 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
public class VideoImageProvider : BaseImageProvider
|
||||
{
|
||||
private readonly ILogger<VideoImageProvider> _logger;
|
||||
private readonly KinopoiskApiProxy _apiProxy;
|
||||
private readonly IKinopoiskApiClient _apiClient;
|
||||
|
||||
public override string Name => Utils.ProviderName;
|
||||
|
||||
public VideoImageProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<VideoImageProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
public VideoImageProvider(IKinopoiskApiClient kinopoiskApiClient, ILogger<VideoImageProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
: base(httpClientFactory)
|
||||
{
|
||||
this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
this._apiProxy = kinopoiskApiProxy ?? throw new ArgumentNullException(nameof(kinopoiskApiProxy));
|
||||
this._apiClient = kinopoiskApiClient ?? throw new ArgumentNullException(nameof(kinopoiskApiClient));
|
||||
}
|
||||
|
||||
public override bool Supports(BaseItem item)
|
||||
@@ -43,40 +43,9 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
if (!Utils.TryGetKinopoiskId(item, _logger, out var kinopoiskId))
|
||||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
|
||||
var film = await _apiProxy.GetSingleFilmImages(kinopoiskId, cancellationToken);
|
||||
var film = await _apiClient.GetSingleFilm(kinopoiskId, cancellationToken);
|
||||
|
||||
return await FilterEmptyImages(film.ToRemoteImageInfos());
|
||||
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<RemoteImageInfo>> FilterEmptyImages(IEnumerable<RemoteImageInfo> images)
|
||||
{
|
||||
using var httpClient = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }, true);
|
||||
var res = await Task.WhenAll(images.Select(i => NullIfEmptyImage(i, httpClient)));
|
||||
|
||||
return res.Where(i => i != null);
|
||||
}
|
||||
|
||||
private async Task<RemoteImageInfo> NullIfEmptyImage(RemoteImageInfo info, HttpClient httpClient)
|
||||
{
|
||||
var currentUrl = info.Url;
|
||||
while (!currentUrl.Contains("no-poster"))
|
||||
{
|
||||
var response = await httpClient.SendAsync(
|
||||
new HttpRequestMessage(HttpMethod.Get, currentUrl), HttpCompletionOption.ResponseHeadersRead);
|
||||
|
||||
if ((int)response.StatusCode <= 299)
|
||||
return info;
|
||||
else if (response.Headers.Location != null)
|
||||
{
|
||||
currentUrl = response.Headers.Location.ToString();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
throw new InvalidOperationException("Not expected answer");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user