Added people results
This commit is contained in:
1 parent
57fbc1fd79
commit
a143904a33
6 files changed
+180
-25
No files matched your search
@@ -0,0 +1,55 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||||
|
{
|
||||||
|
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,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
@@ -7,6 +8,7 @@ using MediaBrowser.Controller.Entities.Movies;
|
|||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
|
using static Jellyfin.Plugin.Kinopoisk.ApiModel.FilmDetails;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Kinopoisk
|
namespace Jellyfin.Plugin.Kinopoisk
|
||||||
{
|
{
|
||||||
@@ -109,26 +111,85 @@ namespace Jellyfin.Plugin.Kinopoisk
|
|||||||
if (src.Images != null)
|
if (src.Images != null)
|
||||||
{
|
{
|
||||||
if (src.Images.Posters != null)
|
if (src.Images.Posters != null)
|
||||||
res = res.Concat(src.Images.Posters.Select(i => new RemoteImageInfo(){
|
res = res.Concat(src.Images.Posters.ToRemoteImageInfos(ImageType.Primary));
|
||||||
Type = ImageType.Primary,
|
|
||||||
Url = i.Url,
|
|
||||||
Language = i.Language,
|
|
||||||
Height = i.Height,
|
|
||||||
Width = i.Width,
|
|
||||||
ProviderName = Utils.ProviderName
|
|
||||||
}));
|
|
||||||
if (src.Images.Backdrops != null)
|
if (src.Images.Backdrops != null)
|
||||||
res = res.Concat(src.Images.Backdrops.Select(i => new RemoteImageInfo(){
|
res = res.Concat(src.Images.Backdrops.ToRemoteImageInfos(ImageType.Backdrop));
|
||||||
Type = ImageType.Backdrop,
|
|
||||||
Url = i.Url,
|
|
||||||
Language = i.Language,
|
|
||||||
Height = i.Height,
|
|
||||||
Width = i.Width,
|
|
||||||
ProviderName = Utils.ProviderName
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<RemoteImageInfo> ToRemoteImageInfos(this IEnumerable<FilmImageRef> src, ImageType imageType)
|
||||||
|
{
|
||||||
|
return src.Select(s => s.ToRemoteImageInfo(imageType))
|
||||||
|
.Where(s => s != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RemoteImageInfo ToRemoteImageInfo(this FilmImageRef src, ImageType imageType)
|
||||||
|
{
|
||||||
|
if (src is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new RemoteImageInfo(){
|
||||||
|
Type = imageType,
|
||||||
|
Url = src.Url,
|
||||||
|
Language = src.Language,
|
||||||
|
Height = src.Height,
|
||||||
|
Width = src.Width,
|
||||||
|
ProviderName = Utils.ProviderName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PersonInfo ToPersonInfo(this StaffItem src)
|
||||||
|
{
|
||||||
|
if (src is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var res = new PersonInfo()
|
||||||
|
{
|
||||||
|
Name = src.NameRu,
|
||||||
|
ImageUrl = src.PosterUrl,
|
||||||
|
Role = src.Description,
|
||||||
|
Type = src.ProfessionKey.ToPersonType()
|
||||||
|
};
|
||||||
|
if (string.IsNullOrWhiteSpace(res.Name))
|
||||||
|
res.Name = src.NameEn;
|
||||||
|
res.SetProviderId(Utils.ProviderId, Convert.ToString(src.StaffId));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<PersonInfo> ToPersonInfos(this IEnumerable<StaffItem> src)
|
||||||
|
{
|
||||||
|
var res = src.Select(s => s.ToPersonInfo())
|
||||||
|
.Where(s => s != null)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
foreach(var item in res)
|
||||||
|
item.SortOrder = ++i;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ToPersonType(this ProfessionEnum src)
|
||||||
|
{
|
||||||
|
switch (src)
|
||||||
|
{
|
||||||
|
case ProfessionEnum.Actor:
|
||||||
|
return PersonType.Actor;
|
||||||
|
case ProfessionEnum.Director:
|
||||||
|
return PersonType.Director;
|
||||||
|
case ProfessionEnum.Writer:
|
||||||
|
return PersonType.Writer;
|
||||||
|
case ProfessionEnum.Composer:
|
||||||
|
return PersonType.Composer;
|
||||||
|
case ProfessionEnum.Producer:
|
||||||
|
case ProfessionEnum.ProducerUssr:
|
||||||
|
return PersonType.Producer;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,13 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Template</title>
|
<title>КиноПоиск</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="TemplateConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
|
<div id="KinopoiskConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
|
||||||
<div data-role="content">
|
<div data-role="content">
|
||||||
<div class="content-primary">
|
<div class="content-primary">
|
||||||
<form id="TemplateConfigForm">
|
<form id="KinopoiskConfigForm">
|
||||||
<div class="inputContainer">
|
<div class="inputContainer">
|
||||||
<label class="inputeLabel inputLabelUnfocused" for="ApiToken">ApiToken</label>
|
<label class="inputeLabel inputLabelUnfocused" for="ApiToken">ApiToken</label>
|
||||||
<input id="ApiToken" name="ApiToken" type="text" is="emby-input" />
|
<input id="ApiToken" name="ApiToken" type="text" is="emby-input" />
|
||||||
@@ -25,23 +25,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var TemplateConfig = {
|
var KinopoiskPluginConfig = {
|
||||||
pluginUniqueId: '33e6d249-648f-44cd-a9ce-497be06c08df'
|
pluginUniqueId: '33e6d249-648f-44cd-a9ce-497be06c08df'
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#TemplateConfigPage').on('pageshow', function () {
|
$('#KinopoiskConfigPage').on('pageshow', function () {
|
||||||
Dashboard.showLoadingMsg();
|
Dashboard.showLoadingMsg();
|
||||||
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
|
ApiClient.getPluginConfiguration(KinopoiskPluginConfig.pluginUniqueId).then(function (config) {
|
||||||
$('#ApiToken').val(config.ApiToken).change();
|
$('#ApiToken').val(config.ApiToken).change();
|
||||||
Dashboard.hideLoadingMsg();
|
Dashboard.hideLoadingMsg();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#TemplateConfigForm').on('submit', function () {
|
$('#KinopoiskConfigForm').on('submit', function () {
|
||||||
Dashboard.showLoadingMsg();
|
Dashboard.showLoadingMsg();
|
||||||
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
|
ApiClient.getPluginConfiguration(KinopoiskPluginConfig.pluginUniqueId).then(function (config) {
|
||||||
config.ApiToken = $('#ApiToken').val();
|
config.ApiToken = $('#ApiToken').val();
|
||||||
ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) {
|
ApiClient.updatePluginConfiguration(KinopoiskPluginConfig.pluginUniqueId, config).then(function (result) {
|
||||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -100,5 +101,29 @@ namespace Jellyfin.Plugin.Kinopoisk
|
|||||||
return await _jsonSerializer.DeserializeFromStreamAsync<FilmDetails>(jsonStream).ConfigureAwait(false);
|
return await _jsonSerializer.DeserializeFromStreamAsync<FilmDetails>(jsonStream).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<StaffItem>> GetStaff(int filmId, CancellationToken? cancellationToken = null)
|
||||||
|
{
|
||||||
|
if (!cancellationToken.HasValue)
|
||||||
|
cancellationToken = CancellationToken.None;
|
||||||
|
|
||||||
|
var uri = new Uri($"https://kinopoiskapiunofficial.tech/api/v1/staff?filmId={filmId}");
|
||||||
|
|
||||||
|
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<IEnumerable<StaffItem>>(jsonStream).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,13 @@ namespace Jellyfin.Plugin.Kinopoisk
|
|||||||
if (result.Item != null)
|
if (result.Item != null)
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
var staff = await _apiProxy.GetStaff(kinopoiskId, cancellationToken);
|
||||||
|
|
||||||
|
foreach(var item in staff.ToPersonInfos())
|
||||||
|
result.AddPerson(item);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,13 @@ namespace Jellyfin.Plugin.Kinopoisk
|
|||||||
if (result.Item != null)
|
if (result.Item != null)
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
var staff = await _apiProxy.GetStaff(kinopoiskId, cancellationToken);
|
||||||
|
|
||||||
|
foreach(var item in staff.ToPersonInfos())
|
||||||
|
result.AddPerson(item);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user