diff --git a/dist/custom/README.md b/dist/custom/README.md new file mode 100644 index 0000000..97e508b --- /dev/null +++ b/dist/custom/README.md @@ -0,0 +1,17 @@ +# Форк плагина КиноПоиск: больше изображений + +Оригинал: https://github.com/LinFor/jellyfin-plugin-kinopoisk + +Что изменено: +- `coverUrl` из карточки фильма отдаётся как `Backdrop` (широкая обложка); +- `logoUrl` отдаётся как `Logo`; +- кадры из `GET /api/v2.2/films/{id}/images` отдаются как `Thumb` и `Backdrop` (до 12 штук); +- проверка доступности URL дедуплицируется, чтобы не дёргать один и тот же адрес дважды. + +Сборка: `10.10.4.0` (net9.0, targetAbi 10.10.0), файл `jellyfin-plugin-kinopoisk_10.10.4.0.zip`. + +Установка: +1. Jellyfin → Dashboard → Plugins → Repositories → добавить + `https://git.midns.ru/1xDed/jellyfin-plugin-kinopoisk/raw/branch/main/dist/custom/manifest.json` +2. Обновить «КиноПоиск» до 10.10.4.0 и перезапустить Jellyfin. +3. Для уже существующих фильмов: «Обновить метаданные» → заменить изображения (или дождаться планового обновления). diff --git a/dist/custom/jellyfin-plugin-kinopoisk_10.10.4.0.zip b/dist/custom/jellyfin-plugin-kinopoisk_10.10.4.0.zip new file mode 100644 index 0000000..a13d8ed Binary files /dev/null and b/dist/custom/jellyfin-plugin-kinopoisk_10.10.4.0.zip differ diff --git a/dist/custom/manifest.json b/dist/custom/manifest.json new file mode 100644 index 0000000..6569720 --- /dev/null +++ b/dist/custom/manifest.json @@ -0,0 +1,21 @@ +[ + { + "category": "Metadata", + "guid": "33e6d249-648f-44cd-a9ce-497be06c08df", + "name": "КиноПоиск", + "overview": "Информация о фильмах и сериалах с КиноПоиска + больше изображений", + "owner": "1xDed (fork of LinFor & skrashevich)", + "description": "Форк плагина КиноПоиск. Дополнительно забирает из API coverUrl, logoUrl и кадры из /films/{id}/images: широкие обложки (Backdrop), landscape-кадры (Thumb) и логотипы (Logo), а не только один постер.", + "imageUrl": "https://kinopoisk.userecho.com/s/attachments/28876/0/1/25f8c0315e6ccb2aa6c2642e48f2c9e9.png", + "versions": [ + { + "version": "10.10.4.0", + "checksum": "e0c9398382c7220e144d842dd31713c5", + "changelog": "Больше изображений: coverUrl как Backdrop, logoUrl как Logo, кадры из /films/{id}/images как Thumb и Backdrop (до 12 кадров). Дедупликация проверки URL.", + "targetAbi": "10.10.0", + "sourceUrl": "https://git.midns.ru/1xDed/jellyfin-plugin-kinopoisk/raw/branch/main/dist/custom/jellyfin-plugin-kinopoisk_10.10.4.0.zip", + "timestamp": "2026-11-27T10:05:00Z" + } + ] + } +] diff --git a/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs b/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs index 132b4fc..3f6033c 100644 --- a/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs +++ b/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs @@ -142,29 +142,69 @@ namespace Jellyfin.Plugin.Kinopoisk } public static IEnumerable ToRemoteImageInfos(this Film src) + => src.ToRemoteImageInfos(null); + + /// + /// Poster + cover + logo + stills from /films/{id}/images. + /// Jellyfin needs more than one Primary/Backdrop to fill the hero and the + /// "choose image" dialog, so expose every artwork the API returns. + /// + public static IEnumerable ToRemoteImageInfos(this Film src, FilmImagesResponse images) { - var res = Enumerable.Empty(); + var res = new List(); if (src is null) return res; - if (src?.PosterUrl != null) + if (!string.IsNullOrEmpty(src.PosterUrl)) { - var mainPoster = new RemoteImageInfo(){ + res.Add(new RemoteImageInfo(){ Type = ImageType.Primary, Url = src.PosterUrl, Language = Constants.ProviderMetadataLanguage, ProviderName = Constants.ProviderName - }; - res = res.Concat(Enumerable.Repeat(mainPoster, 1)); + }); } - // if (src.Images != null) - // { - // if (src.Images.Posters != null) - // res = res.Concat(src.Images.Posters.ToRemoteImageInfos(ImageType.Primary)); - // if (src.Images.Backdrops != null) - // res = res.Concat(src.Images.Backdrops.ToRemoteImageInfos(ImageType.Backdrop)); - // } + if (!string.IsNullOrEmpty(src.CoverUrl)) + { + res.Add(new RemoteImageInfo(){ + Type = ImageType.Backdrop, + Url = src.CoverUrl, + Language = Constants.ProviderMetadataLanguage, + ProviderName = Constants.ProviderName + }); + } + + if (!string.IsNullOrEmpty(src.LogoUrl)) + { + res.Add(new RemoteImageInfo(){ + Type = ImageType.Logo, + Url = src.LogoUrl, + Language = Constants.ProviderMetadataLanguage, + ProviderName = Constants.ProviderName + }); + } + + // Stills are 16:9 frames: useful both as backdrops and landscape thumbs. + // Cap the amount to keep remote-image lookups reasonably fast. + const int maxStills = 12; + var stills = images?.Items? + .Where(i => !string.IsNullOrEmpty(i.ImageUrl)) + .Take(maxStills) + ?? Enumerable.Empty(); + foreach (var still in stills) + { + foreach (var type in new[] { ImageType.Thumb, ImageType.Backdrop }) + { + res.Add(new RemoteImageInfo(){ + Type = type, + Url = still.ImageUrl, + ThumbnailUrl = still.PreviewUrl, + Language = Constants.ProviderMetadataLanguage, + ProviderName = Constants.ProviderName + }); + } + } return res; } diff --git a/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/BaseImageProvider.cs b/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/BaseImageProvider.cs index 9222484..bc4a7ae 100644 --- a/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/BaseImageProvider.cs +++ b/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/BaseImageProvider.cs @@ -38,8 +38,13 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders { using var httpClient = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }, true); var sanitizer = new RemoteImageUrlSanitizer(httpClient); + var sanitized = new Dictionary(StringComparer.Ordinal); var res = await Task.WhenAll(images.Select(async i => { - var sanitizedUrl = await sanitizer.SanitizeRemoteImageUrl(i.Url); + if (!sanitized.TryGetValue(i.Url, out var sanitizedUrl)) + { + sanitizedUrl = await sanitizer.SanitizeRemoteImageUrl(i.Url); + sanitized[i.Url] = sanitizedUrl; + } if (string.IsNullOrEmpty(sanitizedUrl)) return null; diff --git a/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/VideoImageProvider.cs b/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/VideoImageProvider.cs index 3bed52b..84a9c2d 100644 --- a/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/VideoImageProvider.cs +++ b/src/Jellyfin.Plugin.Kinopoisk/RemoteImageProviders/VideoImageProvider.cs @@ -38,7 +38,9 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders => new ImageType[] { ImageType.Primary, - ImageType.Backdrop + ImageType.Backdrop, + ImageType.Thumb, + ImageType.Logo }; public override async Task> GetImages(BaseItem item, CancellationToken cancellationToken) @@ -48,8 +50,15 @@ namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders return Enumerable.Empty(); var film = await _apiClient.GetSingleFilm(kinopoiskId, cancellationToken); + var images = await _apiClient.GetFilmImages(kinopoiskId, cancellationToken); - return await FilterEmptyImages(film.ToRemoteImageInfos()); + var all = film.ToRemoteImageInfos(images).ToArray(); + var filtered = await FilterEmptyImages(all); + _logger.LogInformation( + "Kinopoisk returned {Count} images for {Name}", + filtered.Count(), + item.Name); + return filtered; } } } diff --git a/src/KinopoiskUnofficialInfo.ApiClient/CachedApiClient.cs b/src/KinopoiskUnofficialInfo.ApiClient/CachedApiClient.cs index 77f598a..b620fd5 100644 --- a/src/KinopoiskUnofficialInfo.ApiClient/CachedApiClient.cs +++ b/src/KinopoiskUnofficialInfo.ApiClient/CachedApiClient.cs @@ -33,6 +33,9 @@ namespace KinopoiskUnofficialInfo.ApiClient public Task GetSingleFilm(int filmId, CancellationToken? cancellationToken = null) => TryGetValue(GenerateKey(nameof(GetSingleFilm), filmId), c => c.GetSingleFilm(filmId, cancellationToken)); + public Task GetFilmImages(int filmId, CancellationToken? cancellationToken = null) + => TryGetValue(GenerateKey(nameof(GetFilmImages), filmId), c => c.GetFilmImages(filmId, cancellationToken)); + public Task> GetStaff(int filmId, CancellationToken? cancellationToken = null) => TryGetValue(GenerateKey(nameof(GetStaff), filmId), c => c.GetStaff(filmId, cancellationToken)); diff --git a/src/KinopoiskUnofficialInfo.ApiClient/Film.Images.cs b/src/KinopoiskUnofficialInfo.ApiClient/Film.Images.cs new file mode 100644 index 0000000..aa4cdfc --- /dev/null +++ b/src/KinopoiskUnofficialInfo.ApiClient/Film.Images.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace KinopoiskUnofficialInfo.ApiClient +{ + /// + /// Extra image fields returned by /api/v2.2/films/{id} which are not part of + /// the generated (older) client model. + /// + public partial class Film + { + [JsonProperty("coverUrl")] + public string CoverUrl { get; set; } + + [JsonProperty("logoUrl")] + public string LogoUrl { get; set; } + } +} diff --git a/src/KinopoiskUnofficialInfo.ApiClient/FilmImagesResponse.cs b/src/KinopoiskUnofficialInfo.ApiClient/FilmImagesResponse.cs new file mode 100644 index 0000000..d12b4cf --- /dev/null +++ b/src/KinopoiskUnofficialInfo.ApiClient/FilmImagesResponse.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace KinopoiskUnofficialInfo.ApiClient +{ + /// + /// Stills/backdrops returned by /api/v2.2/films/{id}/images. + /// The endpoint does not report dimensions or the image kind, only URLs. + /// + public class FilmImagesResponse + { + [JsonProperty("total")] + public int Total { get; set; } + + [JsonProperty("totalPages")] + public int TotalPages { get; set; } + + [JsonProperty("items")] + public List Items { get; set; } = new List(); + } + + public class FilmImage + { + [JsonProperty("imageUrl")] + public string ImageUrl { get; set; } + + [JsonProperty("previewUrl")] + public string PreviewUrl { get; set; } + } +} diff --git a/src/KinopoiskUnofficialInfo.ApiClient/IKinopoiskApiClient.cs b/src/KinopoiskUnofficialInfo.ApiClient/IKinopoiskApiClient.cs index 61a0aaa..cc9fcc3 100644 --- a/src/KinopoiskUnofficialInfo.ApiClient/IKinopoiskApiClient.cs +++ b/src/KinopoiskUnofficialInfo.ApiClient/IKinopoiskApiClient.cs @@ -8,6 +8,7 @@ namespace KinopoiskUnofficialInfo.ApiClient { Task GetPerson(int personId, CancellationToken? cancellationToken = null); Task GetSingleFilm(int filmId, CancellationToken? cancellationToken = null); + Task GetFilmImages(int filmId, CancellationToken? cancellationToken = null); Task> GetStaff(int filmId, CancellationToken? cancellationToken = null); Task GetTrailers(int filmId, CancellationToken? cancellationToken = null); Task SearchByKeyword(string keyword, int page = 1, CancellationToken? cancellationToken = null); diff --git a/src/KinopoiskUnofficialInfo.ApiClient/KinopoiskApiClient.cs b/src/KinopoiskUnofficialInfo.ApiClient/KinopoiskApiClient.cs index b81821e..3f50f8a 100644 --- a/src/KinopoiskUnofficialInfo.ApiClient/KinopoiskApiClient.cs +++ b/src/KinopoiskUnofficialInfo.ApiClient/KinopoiskApiClient.cs @@ -50,6 +50,40 @@ namespace KinopoiskUnofficialInfo.ApiClient public Task GetSingleFilm(int filmId, CancellationToken? cancellationToken = null) => Invoke((ct) => _apiClient.FilmsAsync(filmId, ct), cancellationToken); + public async Task GetFilmImages(int filmId, CancellationToken? cancellationToken = null) + { + try + { + using var httpClient = _httpClientFactory.CreateClient(); + using var request = new HttpRequestMessage( + HttpMethod.Get, + $"https://kinopoiskapiunofficial.tech/api/v2.2/films/{filmId}/images"); + request.Headers.Add("X-API-KEY", _apiToken); + using var response = await httpClient.SendAsync( + request, + HttpCompletionOption.ResponseContentRead, + cancellationToken ?? CancellationToken.None); + if (!response.IsSuccessStatusCode) + { + _logger.LogWarning( + "Kinopoisk images request for film {FilmId} returned {StatusCode}", + filmId, + (int)response.StatusCode); + return new FilmImagesResponse(); + } + + var json = await response.Content.ReadAsStringAsync(); + return Newtonsoft.Json.JsonConvert.DeserializeObject(json) + ?? new FilmImagesResponse(); + } + catch (Exception ex) + { + // Extra artwork must never break metadata updates. + _logger.LogWarning(ex, "Failed to load images for film {FilmId}", filmId); + return new FilmImagesResponse(); + } + } + public Task> GetStaff(int filmId, CancellationToken? cancellationToken = null) => Invoke((ct) => _apiClient.StaffAllAsync(filmId, ct), cancellationToken);