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
@@ -1,15 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api
|
||||
{
|
||||
public interface IKinopoiskApiProxy
|
||||
{
|
||||
Task<FilmDetails> GetSingleFilm(int filmId, CancellationToken? cancellationToken = null);
|
||||
Task<FilmDetails> GetSingleFilmImages(int filmId, CancellationToken? cancellationToken = null);
|
||||
Task<IEnumerable<StaffItem>> GetStaff(int filmId, CancellationToken? cancellationToken = null);
|
||||
Task<SearchResult> SearchByKeyword(string keyword, int page = 1, CancellationToken? cancellationToken = null);
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using MediaBrowser.Common.Net;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api
|
||||
{
|
||||
public class KinopoiskApiProxy : IKinopoiskApiProxy
|
||||
{
|
||||
private readonly string _apiToken;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
|
||||
|
||||
public KinopoiskApiProxy(string apiToken, ILogger<KinopoiskApiProxy> logger, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
if (string.IsNullOrEmpty(apiToken))
|
||||
{
|
||||
throw new ArgumentException($"'{nameof(apiToken)}' cannot be null or empty.", nameof(apiToken));
|
||||
}
|
||||
|
||||
_apiToken = apiToken;
|
||||
this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
this._httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
|
||||
this._jsonOptions.Converters.Add(new JsonStringEnumMemberConverter());
|
||||
}
|
||||
|
||||
public async Task<SearchResult> SearchByKeyword(string keyword, int page = 1, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (!cancellationToken.HasValue)
|
||||
cancellationToken = CancellationToken.None;
|
||||
var uriBuilder = new UriBuilder("https://kinopoiskapiunofficial.tech/api/v2.1/films/search-by-keyword");
|
||||
|
||||
var @params = HttpUtility.ParseQueryString(string.Empty);
|
||||
@params["keyword"] = keyword;
|
||||
@params["page"] = Convert.ToString(page);
|
||||
uriBuilder.Query = @params.ToString();
|
||||
|
||||
return await GetAsync<SearchResult>(uriBuilder.Uri, cancellationToken.Value);
|
||||
}
|
||||
|
||||
public async Task<FilmDetails> GetSingleFilm(int filmId, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (!cancellationToken.HasValue)
|
||||
cancellationToken = CancellationToken.None;
|
||||
|
||||
Uri uri = new Uri($"https://kinopoiskapiunofficial.tech/api/v2.1/films/{filmId}?append_to_response=EXTERNAL_ID&append_to_response=RATING");
|
||||
|
||||
return await GetAsync<FilmDetails>(uri, cancellationToken.Value);
|
||||
}
|
||||
|
||||
public async Task<FilmDetails> GetSingleFilmImages(int filmId, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (!cancellationToken.HasValue)
|
||||
cancellationToken = CancellationToken.None;
|
||||
|
||||
Uri uri = new Uri($"https://kinopoiskapiunofficial.tech/api/v2.1/films/{filmId}?append_to_response=POSTERS");
|
||||
|
||||
return await GetAsync<FilmDetails>(uri, cancellationToken.Value);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<StaffItem>> GetStaff(int filmId, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (!cancellationToken.HasValue)
|
||||
cancellationToken = CancellationToken.None;
|
||||
|
||||
Uri uri = new Uri($"https://kinopoiskapiunofficial.tech/api/v1/staff?filmId={filmId}");
|
||||
|
||||
return await GetAsync<IEnumerable<StaffItem>>(uri, cancellationToken.Value);
|
||||
}
|
||||
|
||||
private async Task<T> GetAsync<T>(Uri uri, CancellationToken cancellationToken) where T : class
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||
request.Headers.Add("Accept", "application/json");
|
||||
request.Headers.Add("X-API-KEY", _apiToken);
|
||||
|
||||
var client = _httpClientFactory.CreateClient(NamedClient.Default);
|
||||
using var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
_logger.LogError($"Received non-success result status code {response.StatusCode} from Kinopoisk API, response content is:\n{content}");
|
||||
return null;
|
||||
}
|
||||
|
||||
using var jsonStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
return await JsonSerializer.DeserializeAsync<T>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class CountryItem
|
||||
{
|
||||
public string Country { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class FilmDetails
|
||||
{
|
||||
public FilmData Data { get; set; }
|
||||
|
||||
public FilmExtId ExternalId { get; set; }
|
||||
|
||||
public FilmRating Rating { get; set; }
|
||||
|
||||
// "budget": {
|
||||
// "grossRu": null,
|
||||
// "grossUsa": null,
|
||||
// "grossWorld": null,
|
||||
// "budget": null,
|
||||
// "marketing": null
|
||||
// },
|
||||
|
||||
// "review": {
|
||||
// "reviewsCount": 0,
|
||||
// "ratingGoodReview": "",
|
||||
// "ratingGoodReviewVoteCount": 0
|
||||
// },
|
||||
|
||||
public FilmImages Images { get; set; }
|
||||
|
||||
public class FilmData
|
||||
{
|
||||
public int FilmId { get; set; }
|
||||
public string NameRu { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public string WebUrl { get; set; }
|
||||
public string PosterUrl { get; set; }
|
||||
public string Year { get; set; }
|
||||
public string FilmLength { get; set; }
|
||||
public string Slogan { get; set; }
|
||||
public string Description { get; set; }
|
||||
public Model.FilmType Type { get; set; }
|
||||
public string RatingMpaa { get; set; }
|
||||
public int? RatingAgeLimits { get; set; }
|
||||
public DateTime? PremiereRu { get; set; }
|
||||
public string Distributors { get; set; }
|
||||
public DateTime? PremiereWorld { get; set; }
|
||||
public DateTime? PremiereDigital { get; set; }
|
||||
public string PremiereWorldCountry { get; set; }
|
||||
public DateTime? PremiereDvd { get; set; }
|
||||
public DateTime? PremiereBluRay { get; set; }
|
||||
public string DistributorRelease { get; set; }
|
||||
public CountryItem[] Countries { get; set; }
|
||||
public GenreItem[] Genres { get; set; }
|
||||
}
|
||||
|
||||
public class FilmExtId
|
||||
{
|
||||
public string ImdbId { get; set; }
|
||||
}
|
||||
|
||||
public class FilmRating
|
||||
{
|
||||
public float Rating { get; set; }
|
||||
public int? RatingVoteCount { get; set; }
|
||||
public float? RatingImdb { get; set; }
|
||||
public int? RatingImdbVoteCount { get; set; }
|
||||
public string RatingFilmCritics { get; set; }
|
||||
public int? RatingFilmCriticsVoteCount { get; set; }
|
||||
}
|
||||
|
||||
public class FilmImages
|
||||
{
|
||||
public FilmImageRef[] Posters { get; set; }
|
||||
public FilmImageRef[] Backdrops { get; set; }
|
||||
}
|
||||
|
||||
public class FilmImageRef
|
||||
{
|
||||
public string Language { get; set; }
|
||||
public string Url { get; set; }
|
||||
public int Height { get; set; }
|
||||
public int Width { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public enum FilmType
|
||||
{
|
||||
[EnumMember(Value = "UNKNOWN")]
|
||||
Unknown,
|
||||
|
||||
[EnumMember(Value = "FILM")]
|
||||
Film,
|
||||
|
||||
[EnumMember(Value = "TV_SHOW")]
|
||||
TvShow
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class GenreItem
|
||||
{
|
||||
public string Genre { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class SearchResult
|
||||
{
|
||||
public string Keyword { get; set; }
|
||||
public int PagesCount { get; set; }
|
||||
public List<Film> Films { get; set; }
|
||||
|
||||
public class Film
|
||||
{
|
||||
public int FilmId { get; set; }
|
||||
public string NameRu { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public FilmType Type { get; set; }
|
||||
public string Year { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string FilmLength { get; set; }
|
||||
public CountryItem[] Countries { get; set; }
|
||||
public GenreItem[] Genres { get; set; }
|
||||
public string Rating { get; set; }
|
||||
public int RatingVoteCount { get; set; }
|
||||
public string PosterUrl { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class StaffItem
|
||||
{
|
||||
public int StaffId { get; set; }
|
||||
public string NameRu { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string PosterUrl { get; set; }
|
||||
public string ProfessionText { get; set; }
|
||||
public ProfessionEnum ProfessionKey { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public enum ProfessionEnum
|
||||
{
|
||||
[EnumMember(Value = "UNKNOWN")]
|
||||
Unknown,
|
||||
|
||||
[EnumMember(Value = "WRITER")]
|
||||
Writer,
|
||||
|
||||
[EnumMember(Value = "OPERATOR")]
|
||||
Operator,
|
||||
|
||||
[EnumMember(Value = "EDITOR")]
|
||||
Editor,
|
||||
|
||||
[EnumMember(Value = "COMPOSER")]
|
||||
Composer,
|
||||
|
||||
[EnumMember(Value = "PRODUCER_USSR")]
|
||||
ProducerUssr,
|
||||
|
||||
[EnumMember(Value = "TRANSLATOR")]
|
||||
Translator,
|
||||
|
||||
[EnumMember(Value = "DIRECTOR")]
|
||||
Director,
|
||||
|
||||
[EnumMember(Value = "DESIGN")]
|
||||
Design,
|
||||
|
||||
[EnumMember(Value = "PRODUCER")]
|
||||
Producer,
|
||||
|
||||
[EnumMember(Value = "ACTOR")]
|
||||
Actor,
|
||||
|
||||
[EnumMember(Value = "VOICE_DIRECTOR")]
|
||||
VoiceDirector
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using KinopoiskUnofficialInfo.ApiClient;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using static Jellyfin.Plugin.Kinopoisk.Api.Model.FilmDetails;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public static class ApiModelExtensions
|
||||
{
|
||||
public static RemoteSearchResult ToRemoteSearchResult(this FilmDetails src)
|
||||
public static RemoteSearchResult ToRemoteSearchResult(this Film src)
|
||||
{
|
||||
if (src?.Data is null)
|
||||
return null;
|
||||
@@ -30,7 +30,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IEnumerable<RemoteSearchResult> ToRemoteSearchResults(this SearchResult src)
|
||||
public static IEnumerable<RemoteSearchResult> ToRemoteSearchResults(this FilmSearchResponse src)
|
||||
{
|
||||
if (src?.Films is null)
|
||||
return Enumerable.Empty<RemoteSearchResult>();
|
||||
@@ -38,7 +38,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return src.Films.Select(s => s.ToRemoteSearchResult());
|
||||
}
|
||||
|
||||
public static RemoteSearchResult ToRemoteSearchResult(this SearchResult.Film src)
|
||||
public static RemoteSearchResult ToRemoteSearchResult(this FilmSearchResponse_films src)
|
||||
{
|
||||
if (src is null)
|
||||
return null;
|
||||
@@ -55,7 +55,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Series ToSeries(this FilmDetails src)
|
||||
public static Series ToSeries(this Film src)
|
||||
{
|
||||
if (src?.Data is null)
|
||||
return null;
|
||||
@@ -72,7 +72,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Movie ToMovie(this FilmDetails src)
|
||||
public static Movie ToMovie(this Film src)
|
||||
{
|
||||
if (src?.Data is null)
|
||||
return null;
|
||||
@@ -84,28 +84,31 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
private static void FillCommonFilmInfo(FilmDetails src, BaseItem dst)
|
||||
private static void FillCommonFilmInfo(Film src, BaseItem dst)
|
||||
{
|
||||
dst.SetProviderId(Utils.ProviderId, Convert.ToString(src.Data.FilmId));
|
||||
dst.Name = src.GetLocalName();
|
||||
dst.OriginalTitle = src.GetOriginalNameIfNotSame();
|
||||
dst.PremiereDate = src.Data.GetPremiereDate();
|
||||
if (!string.IsNullOrWhiteSpace(src.Data.Slogan))
|
||||
dst.Tagline = src.Data.Slogan;
|
||||
dst.Overview = src.Data.Description;
|
||||
if (src.Data.Countries != null)
|
||||
dst.ProductionLocations = src.Data.Countries.Select(c => c.Country).ToArray();
|
||||
dst.ProductionLocations = src.Data.Countries.Select(c => c.Country1).ToArray();
|
||||
if (src.Data.Genres != null)
|
||||
foreach(var genre in src.Data.Genres.Select(c => c.Genre))
|
||||
foreach(var genre in src.Data.Genres.Select(c => c.Genre1))
|
||||
dst.AddGenre(genre);
|
||||
if (src.Data.RatingAgeLimits.HasValue)
|
||||
if (src.Data.RatingAgeLimits > 0)
|
||||
dst.OfficialRating = $"{src.Data.RatingAgeLimits}+";
|
||||
else
|
||||
dst.OfficialRating = src.Data.RatingMpaa;
|
||||
|
||||
if (src.Rating != null)
|
||||
{
|
||||
dst.CommunityRating = src.Rating.Rating > 0
|
||||
? src.Rating.Rating
|
||||
var communityRating = src.Rating.Rating1 > 0
|
||||
? src.Rating.Rating1
|
||||
: src.Rating.RatingImdb;
|
||||
dst.CommunityRating = communityRating > 0 ? (float)communityRating : null;
|
||||
dst.CriticRating = src.Rating.GetCriticRatingAsTenPointBased();
|
||||
}
|
||||
|
||||
@@ -116,7 +119,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
}
|
||||
}
|
||||
|
||||
public static float? GetCriticRatingAsTenPointBased(this FilmDetails.FilmRating src)
|
||||
public static float? GetCriticRatingAsTenPointBased(this Rating src)
|
||||
{
|
||||
if (src is null)
|
||||
return null;
|
||||
@@ -134,7 +137,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IEnumerable<RemoteImageInfo> ToRemoteImageInfos(this FilmDetails src)
|
||||
public static IEnumerable<RemoteImageInfo> ToRemoteImageInfos(this Film src)
|
||||
{
|
||||
var res = Enumerable.Empty<RemoteImageInfo>();
|
||||
if (src is null)
|
||||
@@ -162,13 +165,13 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IEnumerable<RemoteImageInfo> ToRemoteImageInfos(this IEnumerable<FilmImageRef> src, ImageType imageType)
|
||||
public static IEnumerable<RemoteImageInfo> ToRemoteImageInfos(this IEnumerable<Images_posters> src, ImageType imageType)
|
||||
{
|
||||
return src.Select(s => s.ToRemoteImageInfo(imageType))
|
||||
.Where(s => s != null);
|
||||
}
|
||||
|
||||
public static RemoteImageInfo ToRemoteImageInfo(this FilmImageRef src, ImageType imageType)
|
||||
public static RemoteImageInfo ToRemoteImageInfo(this Images_posters src, ImageType imageType)
|
||||
{
|
||||
if (src is null)
|
||||
return null;
|
||||
@@ -183,7 +186,40 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
};
|
||||
}
|
||||
|
||||
public static PersonInfo ToPersonInfo(this StaffItem src)
|
||||
public static IReadOnlyList<MediaUrl> ToMediaUrls(this VideoResponse src)
|
||||
{
|
||||
if (src is null || src.Trailers is null || src.Trailers.Count < 1)
|
||||
return null;
|
||||
|
||||
return src.Trailers.Select(t => t.ToMediaUrl())
|
||||
.Where(mu => mu != null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static MediaUrl ToMediaUrl(this VideoResponse_trailers src) {
|
||||
if (src is null)
|
||||
return null;
|
||||
|
||||
return new MediaUrl
|
||||
{
|
||||
Name = src.Name,
|
||||
Url = src.Url
|
||||
};
|
||||
}
|
||||
|
||||
public static RemoteImageInfo ToRemoteImageInfo(this PersonResponse src)
|
||||
{
|
||||
if (src is null || string.IsNullOrEmpty(src.PosterUrl))
|
||||
return null;
|
||||
|
||||
return new RemoteImageInfo(){
|
||||
Type = ImageType.Primary,
|
||||
Url = src.PosterUrl,
|
||||
ProviderName = Utils.ProviderName
|
||||
};
|
||||
}
|
||||
|
||||
public static PersonInfo ToPersonInfo(this StaffResponse src)
|
||||
{
|
||||
if (src is null)
|
||||
return null;
|
||||
@@ -192,7 +228,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
Name = src.NameRu,
|
||||
ImageUrl = src.PosterUrl,
|
||||
Role = src.Description ?? string.Empty,
|
||||
Role = src.ProfessionText ?? string.Empty,
|
||||
Type = src.ProfessionKey.ToPersonType()
|
||||
};
|
||||
if (string.IsNullOrWhiteSpace(res.Name))
|
||||
@@ -202,7 +238,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IEnumerable<PersonInfo> ToPersonInfos(this IEnumerable<StaffItem> src)
|
||||
public static IEnumerable<PersonInfo> ToPersonInfos(this ICollection<StaffResponse> src)
|
||||
{
|
||||
var res = src.Select(s => s.ToPersonInfo())
|
||||
.Where(s => s != null)
|
||||
@@ -215,34 +251,44 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static string ToPersonType(this ProfessionEnum src)
|
||||
public static string ToPersonType(this StaffResponseProfessionKey src)
|
||||
{
|
||||
return src switch
|
||||
{
|
||||
ProfessionEnum.Actor => PersonType.Actor,
|
||||
ProfessionEnum.Director => PersonType.Director,
|
||||
ProfessionEnum.Writer => PersonType.Writer,
|
||||
ProfessionEnum.Composer => PersonType.Composer,
|
||||
ProfessionEnum.Producer or ProfessionEnum.ProducerUssr => PersonType.Producer,
|
||||
StaffResponseProfessionKey.ACTOR => PersonType.Actor,
|
||||
StaffResponseProfessionKey.DIRECTOR => PersonType.Director,
|
||||
StaffResponseProfessionKey.WRITER => PersonType.Writer,
|
||||
StaffResponseProfessionKey.COMPOSER => PersonType.Composer,
|
||||
StaffResponseProfessionKey.PRODUCER or StaffResponseProfessionKey.PRODUCER_USSR => PersonType.Producer,
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
public static DateTime? GetPremiereDate(this FilmData src)
|
||||
public static DateTime? ParseDate(this string src){
|
||||
if (src == null)
|
||||
return null;
|
||||
|
||||
if (DateTime.TryParseExact(src, "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var res))
|
||||
return res;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DateTime? GetPremiereDate(this CommonFilmData src)
|
||||
{
|
||||
var res = src.IsRussianSpokenOriginated()
|
||||
? src.PremiereRu
|
||||
: src.PremiereWorld;
|
||||
if (src.PremiereRu < res)
|
||||
res = src.PremiereRu;
|
||||
if (src.PremiereWorld < res)
|
||||
res = src.PremiereWorld;
|
||||
if (src.PremiereDigital < res)
|
||||
res = src.PremiereDigital;
|
||||
if (src.PremiereDvd < res)
|
||||
res = src.PremiereDvd;
|
||||
if (src.PremiereBluRay < res)
|
||||
res = src.PremiereBluRay;
|
||||
? src.PremiereRu.ParseDate()
|
||||
: src.PremiereWorld.ParseDate();
|
||||
if (src.PremiereRu.ParseDate() < res)
|
||||
res = src.PremiereRu.ParseDate();
|
||||
if (src.PremiereWorld.ParseDate() < res)
|
||||
res = src.PremiereWorld.ParseDate();
|
||||
if (src.PremiereDigital.ParseDate() < res)
|
||||
res = src.PremiereDigital.ParseDate();
|
||||
if (src.PremiereDvd.ParseDate() < res)
|
||||
res = src.PremiereDvd.ParseDate();
|
||||
if (src.PremiereBluRay.ParseDate() < res)
|
||||
res = src.PremiereBluRay.ParseDate();
|
||||
|
||||
if (res.HasValue)
|
||||
return res;
|
||||
@@ -254,7 +300,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DateTime? GetPremiereDate(this SearchResult.Film src)
|
||||
public static DateTime? GetPremiereDate(this FilmSearchResponse_films src)
|
||||
{
|
||||
var firstYear = GetFirstYear(src.Year);
|
||||
if (firstYear != null)
|
||||
@@ -263,7 +309,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DateTime? GetEndDate(this FilmData src)
|
||||
public static DateTime? GetEndDate(this CommonFilmData src)
|
||||
{
|
||||
var lastYear = GetLastYear(src.Year);
|
||||
if (lastYear != null)
|
||||
@@ -272,10 +318,10 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool IsContinuing(this FilmData src)
|
||||
public static bool IsContinuing(this CommonFilmData src)
|
||||
=> IsСontinuing(src?.Year);
|
||||
|
||||
public static string GetLocalName(this FilmDetails src)
|
||||
public static string GetLocalName(this Film src)
|
||||
{
|
||||
var res = src?.Data?.NameRu;
|
||||
if (string.IsNullOrWhiteSpace(res))
|
||||
@@ -283,7 +329,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static string GetLocalName(this SearchResult.Film src)
|
||||
public static string GetLocalName(this FilmSearchResponse_films src)
|
||||
{
|
||||
var res = src?.NameRu;
|
||||
if (string.IsNullOrWhiteSpace(res))
|
||||
@@ -291,12 +337,12 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
}
|
||||
|
||||
public static string GetOriginalName(this FilmDetails src)
|
||||
public static string GetOriginalName(this Film src)
|
||||
=> src.IsRussianSpokenOriginated()
|
||||
? src?.Data?.NameRu
|
||||
: src?.Data?.NameEn;
|
||||
|
||||
public static string GetOriginalNameIfNotSame(this FilmDetails src)
|
||||
public static string GetOriginalNameIfNotSame(this Film src)
|
||||
{
|
||||
var localName = src.GetLocalName();
|
||||
var originalName = src.GetOriginalName();
|
||||
@@ -306,19 +352,19 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static bool IsRussianSpokenOriginated(this FilmDetails src)
|
||||
public static bool IsRussianSpokenOriginated(this Film src)
|
||||
=> src?.Data?.IsRussianSpokenOriginated() ?? false;
|
||||
|
||||
public static bool IsRussianSpokenOriginated(this FilmData src)
|
||||
public static bool IsRussianSpokenOriginated(this CommonFilmData src)
|
||||
=> src?.Countries?.IsRussianSpokenOriginated() ?? false;
|
||||
|
||||
public static bool IsRussianSpokenOriginated(this IEnumerable<CountryItem> src)
|
||||
public static bool IsRussianSpokenOriginated(this IEnumerable<Country> src)
|
||||
{
|
||||
if (src is null)
|
||||
return false;
|
||||
|
||||
foreach(var country in src)
|
||||
switch(country.Country)
|
||||
switch(country.Country1)
|
||||
{
|
||||
case "Россия":
|
||||
return true;
|
||||
@@ -379,5 +425,32 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
? (int?)Convert.ToInt32(years[startindex()..])
|
||||
: null;
|
||||
}
|
||||
|
||||
public static Person ToPerson(this PersonResponse src)
|
||||
{
|
||||
if (src is null)
|
||||
return null;
|
||||
|
||||
var res = new Person()
|
||||
{
|
||||
Name = src.GetLocalName(),
|
||||
PremiereDate = src.Birthday.ParseDate(),
|
||||
EndDate = src.Death.ParseDate()
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(src.Birthplace))
|
||||
res.ProductionLocations = new[] { src.Birthplace };
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static string GetLocalName(this PersonResponse src)
|
||||
{
|
||||
var res = src?.NameRu;
|
||||
if (string.IsNullOrWhiteSpace(res))
|
||||
res = src?.NameEn;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,9 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KinopoiskUnofficialInfo.ApiClient\KinopoiskUnofficialInfo.ApiClient.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
@@ -1,6 +1,8 @@
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using System.Net.Http;
|
||||
using KinopoiskUnofficialInfo.ApiClient;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
@@ -11,7 +13,10 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public void RegisterServices(IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddSingleton<KinopoiskApiProxy>();
|
||||
serviceCollection.AddSingleton<IKinopoiskApiClient>((sp) => new KinopoiskApiClient(
|
||||
Plugin.Instance.Configuration.ApiToken,
|
||||
sp.GetRequiredService<ILogger<KinopoiskApiClient>>(),
|
||||
sp.GetRequiredService<IHttpClientFactory>()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -33,5 +34,37 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
|
||||
public abstract IEnumerable<ImageType> GetSupportedImages(BaseItem item);
|
||||
|
||||
protected 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);
|
||||
}
|
||||
|
||||
protected async Task<RemoteImageInfo> NullIfEmptyImage(RemoteImageInfo info, HttpClient httpClient)
|
||||
{
|
||||
if (info == null)
|
||||
return null;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public abstract class BaseMetadataProvider : IMetadataProvider
|
||||
{
|
||||
protected IHttpClientFactory _httpClientFactory;
|
||||
|
||||
protected BaseMetadataProvider(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory ?? throw new System.ArgumentNullException(nameof(httpClientFactory));
|
||||
}
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Net.Http;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using KinopoiskUnofficialInfo.ApiClient;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -9,11 +8,11 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public class MovieProvider : VideoBaseProvider<Movie, MovieInfo>
|
||||
{
|
||||
public MovieProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<MovieProvider> logger, IHttpClientFactory httpClientFactory) : base(kinopoiskApiProxy, logger, httpClientFactory)
|
||||
public MovieProvider(IKinopoiskApiClient kinopoiskApiClient, ILogger<MovieProvider> logger, IHttpClientFactory httpClientFactory) : base(kinopoiskApiClient, logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Movie ConvertResponseToItem(FilmDetails apiResponse)
|
||||
protected override Movie ConvertResponseToItem(Film apiResponse)
|
||||
=> apiResponse.ToMovie();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
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.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
@@ -12,13 +13,13 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public class PersonImageProvider : BaseImageProvider
|
||||
{
|
||||
private readonly KinopoiskApiProxy _kinopoiskApiProxy;
|
||||
private readonly IKinopoiskApiClient _apiClient;
|
||||
private readonly ILogger<PersonImageProvider> _logger;
|
||||
|
||||
public PersonImageProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<PersonImageProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
public PersonImageProvider(IKinopoiskApiClient kinopoiskApiClient, ILogger<PersonImageProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
: base(httpClientFactory)
|
||||
{
|
||||
_kinopoiskApiProxy = kinopoiskApiProxy ?? throw new System.ArgumentNullException(nameof(kinopoiskApiProxy));
|
||||
_apiClient = kinopoiskApiClient ?? throw new System.ArgumentNullException(nameof(kinopoiskApiClient));
|
||||
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
@@ -27,9 +28,15 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
public override bool Supports(BaseItem item)
|
||||
=> item is Person;
|
||||
|
||||
public override Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||||
public override async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
if (!Utils.TryGetKinopoiskId(item, _logger, out var kinopoiskId))
|
||||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
|
||||
var person = await _apiClient.GetPerson(kinopoiskId, cancellationToken);
|
||||
|
||||
var res = new[] { person.ToRemoteImageInfo() };
|
||||
return await FilterEmptyImages(res);
|
||||
}
|
||||
|
||||
public override IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk;
|
||||
using Jellyfin.Plugin.Kinopoisk.MetadataProviders;
|
||||
using KinopoiskUnofficialInfo.ApiClient;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace k.MetadataProviders
|
||||
{
|
||||
public class PersonProvider : BaseMetadataProvider, IRemoteMetadataProvider<Person, PersonLookupInfo>
|
||||
{
|
||||
private readonly IKinopoiskApiClient _apiClient;
|
||||
private readonly ILogger<PersonProvider> _logger;
|
||||
|
||||
public PersonProvider(IKinopoiskApiClient apiClient, ILogger<PersonProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
: base(httpClientFactory)
|
||||
{
|
||||
_apiClient = apiClient ?? throw new System.ArgumentNullException(nameof(apiClient));
|
||||
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public async Task<MetadataResult<Person>> GetMetadata(PersonLookupInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<Person>()
|
||||
{
|
||||
QueriedById = true,
|
||||
Provider = Utils.ProviderName,
|
||||
ResultLanguage = Utils.ProviderMetadataLanguage
|
||||
};
|
||||
|
||||
if (!Utils.TryGetKinopoiskId(info, _logger, out var kinopoiskId))
|
||||
return result;
|
||||
|
||||
var person = await _apiClient.GetPerson(kinopoiskId, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
result.Item = person.ToPerson();
|
||||
if (result.Item != null)
|
||||
result.HasMetadata = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
|
||||
=> Task.FromResult(Enumerable.Empty<RemoteSearchResult>()); // Not supported
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Net.Http;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using KinopoiskUnofficialInfo.ApiClient;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -9,11 +8,11 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public class SeriesProvider : VideoBaseProvider<Series, SeriesInfo>
|
||||
{
|
||||
public SeriesProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<SeriesProvider> logger, IHttpClientFactory httpClientFactory) : base(kinopoiskApiProxy, logger, httpClientFactory)
|
||||
public SeriesProvider(IKinopoiskApiClient kinopoiskApiClient, ILogger<SeriesProvider> logger, IHttpClientFactory httpClientFactory) : base(kinopoiskApiClient, logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Series ConvertResponseToItem(FilmDetails apiResponse)
|
||||
protected override Series ConvertResponseToItem(Film apiResponse)
|
||||
=> apiResponse.ToSeries();
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using MediaBrowser.Common.Net;
|
||||
using KinopoiskUnofficialInfo.ApiClient;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Providers;
|
||||
@@ -13,29 +11,21 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public abstract class VideoBaseProvider<TItemType, TLookupInfoType> : IRemoteMetadataProvider<TItemType, TLookupInfoType>
|
||||
public abstract class VideoBaseProvider<TItemType, TLookupInfoType> : BaseMetadataProvider, IRemoteMetadataProvider<TItemType, TLookupInfoType>
|
||||
where TItemType : BaseItem, IHasLookupInfo<TLookupInfoType>
|
||||
where TLookupInfoType : ItemLookupInfo, new()
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly KinopoiskApiProxy _apiProxy;
|
||||
private readonly IKinopoiskApiClient _apiClient;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public VideoBaseProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger logger, IHttpClientFactory httpClientFactory)
|
||||
public VideoBaseProvider(IKinopoiskApiClient kinopoiskApiClient, ILogger logger, IHttpClientFactory httpClientFactory)
|
||||
: base(httpClientFactory)
|
||||
{
|
||||
this._logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
|
||||
this._httpClientFactory = httpClientFactory ?? throw new System.ArgumentNullException(nameof(httpClientFactory));
|
||||
this._apiProxy = kinopoiskApiProxy ?? throw new System.ArgumentNullException(nameof(kinopoiskApiProxy));
|
||||
this._apiClient = kinopoiskApiClient ?? throw new System.ArgumentNullException(nameof(kinopoiskApiClient));
|
||||
}
|
||||
|
||||
protected abstract TItemType ConvertResponseToItem(FilmDetails apiResponse);
|
||||
|
||||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
||||
}
|
||||
protected abstract TItemType ConvertResponseToItem(Film apiResponse);
|
||||
|
||||
public async Task<MetadataResult<TItemType>> GetMetadata(TLookupInfoType info, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -49,19 +39,27 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
if (!Utils.TryGetKinopoiskId(info, _logger, out var kinopoiskId))
|
||||
return result;
|
||||
|
||||
var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
|
||||
var film = await _apiClient.GetSingleFilm(kinopoiskId, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
result.Item = ConvertResponseToItem(film);
|
||||
if (result.Item != null)
|
||||
result.HasMetadata = true;
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var staff = await _apiClient.GetStaff(kinopoiskId, cancellationToken);
|
||||
|
||||
var staff = await _apiProxy.GetStaff(kinopoiskId, cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
foreach (var item in staff.ToPersonInfos())
|
||||
result.AddPerson(item);
|
||||
|
||||
var trailers = await _apiClient.GetTrailers(kinopoiskId, cancellationToken);
|
||||
|
||||
var remoteTrailers = trailers.ToMediaUrls();
|
||||
if (remoteTrailers is not null)
|
||||
result.Item.RemoteTrailers = remoteTrailers;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -69,12 +67,12 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
if (Utils.TryGetKinopoiskId(searchInfo, _logger, out var kinopoiskId))
|
||||
{
|
||||
var singleResult = (await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken)).ToRemoteSearchResult();
|
||||
var singleResult = (await _apiClient.GetSingleFilm(kinopoiskId, cancellationToken)).ToRemoteSearchResult();
|
||||
return Enumerable.Repeat(singleResult, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (await _apiProxy.SearchByKeyword(searchInfo.Name, cancellationToken: cancellationToken)).ToRemoteSearchResults();
|
||||
return (await _apiClient.SearchByKeyword(searchInfo.Name, cancellationToken: cancellationToken)).ToRemoteSearchResults();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
name: "КиноПоиск"
|
||||
guid: "0c136f8a-ff77-4f2b-ade5-13462cae6216"
|
||||
imageUrl: "https://kinopoisk.userecho.com/s/attachments/28876/0/1/25f8c0315e6ccb2aa6c2642e48f2c9e9.png"
|
||||
version: "10.7.0.3"
|
||||
version: "10.7.0.4"
|
||||
targetAbi: "10.7.0"
|
||||
framework: "net5.0"
|
||||
owner: "linfor"
|
||||
|
||||
Reference in new issue
Block a user