From d7db6dbc335b9fe4b28f2d049e6378e8617818b1 Mon Sep 17 00:00:00 2001 From: cxfksword <718792+cxfksword@users.noreply.github.com> Date: Tue, 17 Jan 2023 15:37:37 +0800 Subject: [PATCH] feat: add tmdb backdrop --- .../Providers/SeriesImageProvider.cs | 56 ++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs index 349d20a..857b5c1 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs @@ -62,7 +62,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers { return Enumerable.Empty(); } - var dropback = await GetBackdrop(sid, cancellationToken); + var dropback = await GetBackdrop(item, cancellationToken); var res = new List { new RemoteImageInfo @@ -139,28 +139,58 @@ namespace Jellyfin.Plugin.MetaShark.Providers /// /// Query for a background photo /// - /// a subject/movie id /// Instance of the interface. - private async Task> GetBackdrop(string sid, CancellationToken cancellationToken) + private async Task> GetBackdrop(BaseItem item, CancellationToken cancellationToken) { - this.Log("GetBackdrop of sid: {0}", sid); - var photo = await this._doubanApi.GetWallpaperBySidAsync(sid, cancellationToken); + var sid = item.GetProviderId(DoubanProviderId); + var tmdbId = item.GetProviderId(MetadataProvider.Tmdb); var list = new List(); - if (photo == null) + // 从豆瓣获取背景图 + if (!string.IsNullOrEmpty(sid)) + { + var photo = await this._doubanApi.GetWallpaperBySidAsync(sid, cancellationToken); + if (photo != null && photo.Count > 0) + { + this.Log("GetBackdrop from douban sid: {0}", sid); + list = photo.Where(x => x.Width > x.Height * 1.3).Select(x => + { + return new RemoteImageInfo + { + ProviderName = Name, + Url = x.Large, + Type = ImageType.Backdrop, + }; + }).ToList(); + + } + } + if (list.Count > 0) { return list; } - return photo.Where(x => x.Width > x.Height * 1.3 && !string.IsNullOrEmpty(x.Large)).Select(x => + // 从TheMovieDb获取背景图 + if (config.EnableTmdbBackdrop && !string.IsNullOrEmpty(tmdbId)) { - return new RemoteImageInfo + var language = item.GetPreferredMetadataLanguage(); + var movie = await _tmdbApi + .GetSeriesAsync(tmdbId.ToInt(), language, language, cancellationToken) + .ConfigureAwait(false); + + if (movie != null && !string.IsNullOrEmpty(movie.BackdropPath)) { - ProviderName = Name, - Url = x.Large, - Type = ImageType.Backdrop, - }; - }); + this.Log("GetBackdrop from tmdb id: {0}", tmdbId); + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = _tmdbApi.GetBackdropUrl(movie.BackdropPath), + Type = ImageType.Backdrop, + }); + } + } + + return list; } }