Initial commit
This commit is contained in:
1 parent
3ea56ab6e0
commit
57fbc1fd79
21 files changed
+1209
No files matched your search
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
{
|
||||
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 string Type { get; set; } // FILM, TV_SHOW
|
||||
public string RatingMpaa { get; set; }
|
||||
public string RatingAgeLimits { get; set; }
|
||||
public string PremiereRu { get; set; }
|
||||
public string Distributors { get; set; }
|
||||
public string PremiereWorld { get; set; }
|
||||
public string PremiereDigital { get; set; }
|
||||
public string PremiereWorldCountry { get; set; }
|
||||
public string PremiereDvd { get; set; }
|
||||
public string PremiereBluRay { get; set; }
|
||||
public string DistributorRelease { get; set; }
|
||||
public CountryItem[] Countries { get; set; }
|
||||
public GenreItem[] Genres { get; set; }
|
||||
|
||||
public class CountryItem
|
||||
{
|
||||
public string Country { get; set; }
|
||||
}
|
||||
|
||||
public class GenreItem
|
||||
{
|
||||
public string Genre { 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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
{
|
||||
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 string Type { get; set; }
|
||||
public string Year { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string FilmLength { get; set; }
|
||||
public string Rating { get; set; }
|
||||
public string RatingVoteCount { get; set; }
|
||||
public string PosterUrl { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public static class ApiModelExtensions
|
||||
{
|
||||
public static Series ToSeries(this FilmDetails src)
|
||||
{
|
||||
if (src.Data is null)
|
||||
return null;
|
||||
|
||||
var res = new Series();
|
||||
|
||||
FillCommonFilmInfo(src, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Movie ToMovie(this FilmDetails src)
|
||||
{
|
||||
if (src.Data is null)
|
||||
return null;
|
||||
|
||||
var res = new Movie();
|
||||
|
||||
FillCommonFilmInfo(src, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private static void FillCommonFilmInfo(FilmDetails src, BaseItem dst)
|
||||
{
|
||||
dst.SetProviderId(Utils.ProviderId, Convert.ToString(src.Data.FilmId));
|
||||
dst.Name = src.Data.NameRu;
|
||||
if (string.IsNullOrWhiteSpace(dst.Name))
|
||||
dst.Name = src.Data.NameEn;
|
||||
// if (!string.IsNullOrWhiteSpace(film.Data.WebUrl))
|
||||
// result.Item.HomePageUrl = film.Data.WebUrl;
|
||||
dst.ProductionYear = Utils.GetFirstYear(src.Data.Year);
|
||||
dst.Overview = src.Data.Description;
|
||||
if (src.Data.Countries != null)
|
||||
dst.ProductionLocations = src.Data.Countries.Select(c => c.Country).ToArray();
|
||||
if (src.Data.Genres != null)
|
||||
foreach(var genre in src.Data.Genres.Select(c => c.Genre))
|
||||
dst.AddGenre(genre);
|
||||
if (!string.IsNullOrWhiteSpace(src.Data.RatingAgeLimits))
|
||||
dst.OfficialRating = $"{src.Data.RatingAgeLimits}+";
|
||||
else
|
||||
dst.OfficialRating = src.Data.RatingMpaa;
|
||||
|
||||
if (src.Rating != null)
|
||||
{
|
||||
dst.CommunityRating = src.Rating.Rating > 0
|
||||
? src.Rating.Rating
|
||||
: src.Rating.RatingImdb;
|
||||
dst.CriticRating = src.Rating.GetCriticRatingAsTenPointBased();
|
||||
}
|
||||
|
||||
if (src.ExternalId != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(src.ExternalId.ImdbId))
|
||||
dst.SetProviderId(MetadataProviders.Imdb, src.ExternalId.ImdbId);
|
||||
}
|
||||
}
|
||||
|
||||
public static float? GetCriticRatingAsTenPointBased(this FilmDetails.FilmRating src)
|
||||
{
|
||||
if (src is null)
|
||||
return null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(src.RatingFilmCritics))
|
||||
return null;
|
||||
|
||||
if (float.TryParse(src.RatingFilmCritics, out var res))
|
||||
return res;
|
||||
|
||||
var ratingStr = src.RatingFilmCritics.Replace("%", string.Empty);
|
||||
if (int.TryParse(ratingStr, out var res_pct))
|
||||
return res_pct * 0.1f;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IEnumerable<RemoteImageInfo> ToRemoteImageInfos(this FilmDetails src)
|
||||
{
|
||||
var res = Enumerable.Empty<RemoteImageInfo>();
|
||||
if (src is null)
|
||||
return res;
|
||||
|
||||
if (src?.Data?.PosterUrl != null)
|
||||
{
|
||||
var mainPoster = new RemoteImageInfo(){
|
||||
Type = ImageType.Primary,
|
||||
Url = src.Data.PosterUrl,
|
||||
Language = Utils.ProviderMetadataLanguage,
|
||||
ProviderName = Utils.ProviderName
|
||||
};
|
||||
res = res.Concat(Enumerable.Repeat(mainPoster, 1));
|
||||
}
|
||||
|
||||
if (src.Images != null)
|
||||
{
|
||||
if (src.Images.Posters != null)
|
||||
res = res.Concat(src.Images.Posters.Select(i => new RemoteImageInfo(){
|
||||
Type = ImageType.Primary,
|
||||
Url = i.Url,
|
||||
Language = i.Language,
|
||||
Height = i.Height,
|
||||
Width = i.Width,
|
||||
ProviderName = Utils.ProviderName
|
||||
}));
|
||||
if (src.Images.Backdrops != null)
|
||||
res = res.Concat(src.Images.Backdrops.Select(i => new RemoteImageInfo(){
|
||||
Type = ImageType.Backdrop,
|
||||
Url = i.Url,
|
||||
Language = i.Language,
|
||||
Height = i.Height,
|
||||
Width = i.Width,
|
||||
ProviderName = Utils.ProviderName
|
||||
}));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using MediaBrowser.Model.Plugins;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Configuration
|
||||
{
|
||||
public class PluginConfiguration : BasePluginConfiguration
|
||||
{
|
||||
// https://kinopoiskapiunofficial.tech/
|
||||
public string ApiToken { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Template</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="TemplateConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
|
||||
<div data-role="content">
|
||||
<div class="content-primary">
|
||||
<form id="TemplateConfigForm">
|
||||
<div class="inputContainer">
|
||||
<label class="inputeLabel inputLabelUnfocused" for="ApiToken">ApiToken</label>
|
||||
<input id="ApiToken" name="ApiToken" type="text" is="emby-input" />
|
||||
<div class="fieldDescription">Personal api token, you can get your own on
|
||||
<a href="https://kinopoiskapiunofficial.tech">https://kinopoiskapiunofficial.tech</a>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
||||
<span>Save</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var TemplateConfig = {
|
||||
pluginUniqueId: '33e6d249-648f-44cd-a9ce-497be06c08df'
|
||||
};
|
||||
|
||||
$('#TemplateConfigPage').on('pageshow', function () {
|
||||
Dashboard.showLoadingMsg();
|
||||
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
|
||||
$('#ApiToken').val(config.ApiToken).change();
|
||||
Dashboard.hideLoadingMsg();
|
||||
});
|
||||
});
|
||||
|
||||
$('#TemplateConfigForm').on('submit', function () {
|
||||
Dashboard.showLoadingMsg();
|
||||
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
|
||||
config.ApiToken = $('#ApiToken').val();
|
||||
ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) {
|
||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||
});
|
||||
});
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Jellyfin.Controller" Version="10.5.5" />
|
||||
<PackageReference Include="Jellyfin.Model" Version="10.5.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Configuration\configPage.html" />
|
||||
<EmbeddedResource Include="Configuration\configPage.html" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class KinopoiskApiProxy
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly string _apiToken;
|
||||
|
||||
public KinopoiskApiProxy(ILogger logger, IHttpClient httpClient, IJsonSerializer jsonSerializer)
|
||||
{
|
||||
this._logger = logger;
|
||||
this._httpClient = httpClient;
|
||||
this._jsonSerializer = jsonSerializer;
|
||||
this._apiToken = Plugin.Instance.Configuration.ApiToken;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
var requestOptions = new HttpRequestOptions
|
||||
{
|
||||
Url = uriBuilder.Uri.AbsoluteUri,
|
||||
CancellationToken = cancellationToken.Value,
|
||||
BufferContent = true,
|
||||
EnableDefaultUserAgent = true,
|
||||
AcceptHeader = "application/json"
|
||||
};
|
||||
requestOptions.RequestHeaders.Add("X-API-KEY", _apiToken);
|
||||
using(var response = await _httpClient.SendAsync(requestOptions, HttpMethod.Get).ConfigureAwait(false))
|
||||
// todo: status code!
|
||||
using(var jsonStream = response.Content)
|
||||
{
|
||||
return await _jsonSerializer.DeserializeFromStreamAsync<SearchResult>(jsonStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<FilmDetails> GetSingleFilm(int filmId, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (!cancellationToken.HasValue)
|
||||
cancellationToken = CancellationToken.None;
|
||||
|
||||
var uri = new Uri($"https://kinopoiskapiunofficial.tech/api/v2.1/films/{filmId}?append_to_response=EXTERNAL_ID&append_to_response=RATING");
|
||||
|
||||
var requestOptions = new HttpRequestOptions
|
||||
{
|
||||
Url = uri.AbsoluteUri,
|
||||
CancellationToken = cancellationToken.Value,
|
||||
BufferContent = true,
|
||||
EnableDefaultUserAgent = true,
|
||||
AcceptHeader = "application/json"
|
||||
};
|
||||
requestOptions.RequestHeaders.Add("X-API-KEY", _apiToken);
|
||||
using(var response = await _httpClient.SendAsync(requestOptions, HttpMethod.Get).ConfigureAwait(false))
|
||||
// todo: status code!
|
||||
using(var jsonStream = response.Content)
|
||||
{
|
||||
return await _jsonSerializer.DeserializeFromStreamAsync<FilmDetails>(jsonStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<FilmDetails> GetSingleFilmImages(int filmId, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (!cancellationToken.HasValue)
|
||||
cancellationToken = CancellationToken.None;
|
||||
|
||||
var uri = new Uri($"https://kinopoiskapiunofficial.tech/api/v2.1/films/{filmId}?append_to_response=POSTERS");
|
||||
|
||||
var requestOptions = new HttpRequestOptions
|
||||
{
|
||||
Url = uri.AbsoluteUri,
|
||||
CancellationToken = cancellationToken.Value,
|
||||
BufferContent = true,
|
||||
EnableDefaultUserAgent = true,
|
||||
AcceptHeader = "application/json"
|
||||
};
|
||||
requestOptions.RequestHeaders.Add("X-API-KEY", _apiToken);
|
||||
using(var response = await _httpClient.SendAsync(requestOptions, HttpMethod.Get).ConfigureAwait(false))
|
||||
// todo: status code!
|
||||
using(var jsonStream = response.Content)
|
||||
{
|
||||
return await _jsonSerializer.DeserializeFromStreamAsync<FilmDetails>(jsonStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class KinopoiskExternalId : IExternalId
|
||||
{
|
||||
public string ProviderName => Utils.ProviderName;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public string Key => Utils.ProviderId;
|
||||
|
||||
public string UrlFormatString => "https://www.kinopoisk.ru/film/{0}";
|
||||
|
||||
public bool Supports(IHasProviderIds item)
|
||||
{
|
||||
return item is Movie || item is Series;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class KinopoiskImageProvider : IRemoteImageProvider
|
||||
{
|
||||
private readonly ILogger<KinopoiskImageProvider> _logger;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly KinopoiskApiProxy _apiProxy;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public KinopoiskImageProvider(ILogger<KinopoiskImageProvider> logger,
|
||||
IHttpClient httpClient,
|
||||
IJsonSerializer jsonSerializer)
|
||||
{
|
||||
if (logger is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (httpClient is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(httpClient));
|
||||
}
|
||||
|
||||
if (jsonSerializer is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(jsonSerializer));
|
||||
}
|
||||
|
||||
this._logger = logger;
|
||||
this._httpClient = httpClient;
|
||||
this._jsonSerializer = jsonSerializer;
|
||||
this._apiProxy = new KinopoiskApiProxy(logger, httpClient, jsonSerializer);
|
||||
}
|
||||
|
||||
public bool Supports(BaseItem item)
|
||||
=> item is Movie || item is Series;
|
||||
|
||||
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||||
=> new ImageType[]
|
||||
{
|
||||
ImageType.Primary,
|
||||
ImageType.Backdrop
|
||||
};
|
||||
|
||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return _httpClient.GetResponse(new HttpRequestOptions
|
||||
{
|
||||
CancellationToken = cancellationToken,
|
||||
Url = url
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!Utils.TryGetKinopoiskId(item, _logger, out var kinopoiskId))
|
||||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
|
||||
var film = await _apiProxy.GetSingleFilmImages(kinopoiskId, cancellationToken);
|
||||
|
||||
return film.ToRemoteImageInfos();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class KinopoiskMovieProvider : IRemoteMetadataProvider<Movie, MovieInfo>
|
||||
{
|
||||
private readonly ILogger<KinopoiskMovieProvider> _logger;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly KinopoiskApiProxy _apiProxy;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public KinopoiskMovieProvider(ILogger<KinopoiskMovieProvider> logger,
|
||||
IHttpClient httpClient,
|
||||
IJsonSerializer jsonSerializer)
|
||||
{
|
||||
if (logger is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (httpClient is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(httpClient));
|
||||
}
|
||||
|
||||
if (jsonSerializer is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(jsonSerializer));
|
||||
}
|
||||
|
||||
this._logger = logger;
|
||||
this._httpClient = httpClient;
|
||||
this._jsonSerializer = jsonSerializer;
|
||||
this._apiProxy = new KinopoiskApiProxy(logger, httpClient, jsonSerializer);
|
||||
}
|
||||
|
||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return _httpClient.GetResponse(new HttpRequestOptions
|
||||
{
|
||||
CancellationToken = cancellationToken,
|
||||
Url = url
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<Movie>()
|
||||
{
|
||||
QueriedById = true,
|
||||
Provider = Utils.ProviderName,
|
||||
ResultLanguage = Utils.ProviderMetadataLanguage
|
||||
};
|
||||
|
||||
if (!Utils.TryGetKinopoiskId(info, _logger, out var kinopoiskId))
|
||||
return result;
|
||||
|
||||
var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
|
||||
|
||||
result.Item = film.ToMovie();
|
||||
if (result.Item != null)
|
||||
result.HasMetadata = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
if (Utils.TryGetKinopoiskId(searchInfo, _logger, out var kinopoiskId))
|
||||
{
|
||||
var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
|
||||
var singleResult = new RemoteSearchResult() {
|
||||
Name = film.Data.NameRu ?? film.Data.NameEn,
|
||||
ImageUrl = film.Data.PosterUrl,
|
||||
ProductionYear = Utils.GetFirstYear(film.Data.Year),
|
||||
Overview = film.Data.Description,
|
||||
SearchProviderName = Utils.ProviderName
|
||||
};
|
||||
singleResult.SetProviderId(Utils.ProviderId, Convert.ToString(film.Data.FilmId));
|
||||
return Enumerable.Repeat(singleResult, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
var searchResults = await _apiProxy.SearchByKeyword(searchInfo.Name, cancellationToken: cancellationToken);
|
||||
return searchResults.Films.Select(f => {
|
||||
var res = new RemoteSearchResult() {
|
||||
Name = f.NameRu ?? f.NameEn,
|
||||
ImageUrl = f.PosterUrl,
|
||||
ProductionYear = Utils.GetFirstYear(f.Year),
|
||||
Overview = f.Description,
|
||||
SearchProviderName = Utils.ProviderName
|
||||
};
|
||||
res.SetProviderId(Utils.ProviderId, Convert.ToString(f.FilmId));
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class KinopoiskSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>
|
||||
{
|
||||
private readonly ILogger<KinopoiskSeriesProvider> _logger;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly KinopoiskApiProxy _apiProxy;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public KinopoiskSeriesProvider(ILogger<KinopoiskSeriesProvider> logger,
|
||||
IHttpClient httpClient,
|
||||
IJsonSerializer jsonSerializer)
|
||||
{
|
||||
if (logger is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (httpClient is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(httpClient));
|
||||
}
|
||||
|
||||
if (jsonSerializer is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(jsonSerializer));
|
||||
}
|
||||
|
||||
this._logger = logger;
|
||||
this._httpClient = httpClient;
|
||||
this._jsonSerializer = jsonSerializer;
|
||||
this._apiProxy = new KinopoiskApiProxy(logger, httpClient, jsonSerializer);
|
||||
}
|
||||
|
||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return _httpClient.GetResponse(new HttpRequestOptions
|
||||
{
|
||||
CancellationToken = cancellationToken,
|
||||
Url = url
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<Series>()
|
||||
{
|
||||
QueriedById = true,
|
||||
Provider = Utils.ProviderName,
|
||||
ResultLanguage = Utils.ProviderMetadataLanguage
|
||||
};
|
||||
|
||||
if (!Utils.TryGetKinopoiskId(info, _logger, out var kinopoiskId))
|
||||
return result;
|
||||
|
||||
var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
|
||||
|
||||
result.Item = film.ToSeries();
|
||||
if (result.Item != null)
|
||||
result.HasMetadata = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
if (Utils.TryGetKinopoiskId(searchInfo, _logger, out var kinopoiskId))
|
||||
{
|
||||
var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
|
||||
var singleResult = new RemoteSearchResult() {
|
||||
Name = film.Data.NameRu ?? film.Data.NameEn,
|
||||
ImageUrl = film.Data.PosterUrl,
|
||||
ProductionYear = Utils.GetFirstYear(film.Data.Year),
|
||||
Overview = film.Data.Description,
|
||||
SearchProviderName = Utils.ProviderName
|
||||
};
|
||||
singleResult.SetProviderId(Utils.ProviderId, Convert.ToString(film.Data.FilmId));
|
||||
return Enumerable.Repeat(singleResult, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
var searchResults = await _apiProxy.SearchByKeyword(searchInfo.Name, cancellationToken: cancellationToken);
|
||||
return searchResults.Films.Select(f => {
|
||||
var res = new RemoteSearchResult() {
|
||||
Name = f.NameRu ?? f.NameEn,
|
||||
ImageUrl = f.PosterUrl,
|
||||
ProductionYear = Utils.GetFirstYear(f.Year),
|
||||
Overview = f.Description,
|
||||
SearchProviderName = Utils.ProviderName
|
||||
};
|
||||
res.SetProviderId(Utils.ProviderId, Convert.ToString(f.FilmId));
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Jellyfin.Plugin.Kinopoisk.Configuration;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Model.Plugins;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
{
|
||||
public static Plugin Instance { get; private set; }
|
||||
|
||||
public override string Name => Utils.ProviderName;
|
||||
|
||||
public override string Description => Utils.ProviderDescription;
|
||||
|
||||
public override Guid Id => Guid.Parse("33e6d249-648f-44cd-a9ce-497be06c08df");
|
||||
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public IEnumerable<PluginPageInfo> GetPages()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new PluginPageInfo
|
||||
{
|
||||
Name = this.Name,
|
||||
EmbeddedResourcePath = string.Format("{0}.Configuration.configPage.html", GetType().Namespace)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
public const string ProviderId = "kinopoisk";
|
||||
public const string ProviderName = "КиноПоиск";
|
||||
public const string ProviderDescription = "Загружает рейтинги сайта КиноПоиск";
|
||||
public const string ProviderMetadataLanguage = "ru";
|
||||
|
||||
public static int? GetFirstYear(string years)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(years))
|
||||
return null;
|
||||
|
||||
years = years.Trim();
|
||||
|
||||
if (int.TryParse(years, out var res))
|
||||
return res;
|
||||
|
||||
var i = 0;
|
||||
while (i < 4) {
|
||||
if (!char.IsDigit(years[i]))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
return Convert.ToInt32(years.Substring(0, i));
|
||||
}
|
||||
|
||||
public static bool TryGetKinopoiskId(IHasProviderIds item, ILogger logger, out int result)
|
||||
{
|
||||
var kinopoiskIdStr = item.GetProviderId(Utils.ProviderId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(kinopoiskIdStr))
|
||||
{
|
||||
logger.LogDebug("Empty ProviderId, skipping");
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!int.TryParse(kinopoiskIdStr, out result))
|
||||
{
|
||||
logger.LogDebug($"Can't parse ProviderId to int, skipping ({kinopoiskIdStr})");
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user