From 2b078752507736b3415846cbca6cfc203001fc66 Mon Sep 17 00:00:00 2001 From: cxfksword <718792+cxfksword@users.noreply.github.com> Date: Tue, 11 Jul 2023 14:57:24 +0800 Subject: [PATCH] fix: fix download douban image. close #35 --- .../MovieImageProviderTest.cs | 21 +++++ Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs | 17 +--- .../Configuration/PluginConfiguration.cs | 24 ++--- .../Configuration/configPage.html | 11 +++ .../Controllers/MetaSharkController.cs | 16 +--- Jellyfin.Plugin.MetaShark/Plugin.cs | 28 +++++- .../Providers/BaseProvider.cs | 94 ++++++++++++++----- .../Providers/EpisodeImageProvider.cs | 6 -- .../Providers/MovieImageProvider.cs | 17 +--- .../Providers/MovieProvider.cs | 3 +- .../Providers/PersonImageProvider.cs | 35 +------ .../Providers/PersonProvider.cs | 6 -- .../Providers/SeasonImageProvider.cs | 12 +-- .../Providers/SeasonProvider.cs | 2 +- .../Providers/SeriesImageProvider.cs | 17 +--- .../Providers/SeriesProvider.cs | 3 +- 16 files changed, 154 insertions(+), 158 deletions(-) diff --git a/Jellyfin.Plugin.MetaShark.Test/MovieImageProviderTest.cs b/Jellyfin.Plugin.MetaShark.Test/MovieImageProviderTest.cs index b4d09f0..d4a8d89 100644 --- a/Jellyfin.Plugin.MetaShark.Test/MovieImageProviderTest.cs +++ b/Jellyfin.Plugin.MetaShark.Test/MovieImageProviderTest.cs @@ -82,5 +82,26 @@ namespace Jellyfin.Plugin.MetaShark.Test Console.WriteLine(result.ToJson()); }).GetAwaiter().GetResult(); } + + [TestMethod] + public void TestGetImageResponse() + { + var doubanApi = new DoubanApi(loggerFactory); + var tmdbApi = new TmdbApi(loggerFactory); + var omdbApi = new OmdbApi(loggerFactory); + var httpClientFactory = new DefaultHttpClientFactory(); + var libraryManagerStub = new Mock(); + var httpContextAccessorStub = new Mock(); + + Task.Run(async () => + { + var provider = new MovieImageProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi); + var result = await provider.GetImageResponse("https://img1.doubanio.com/view/photo/m/public/p2893270877.jpg", CancellationToken.None); + Assert.IsNotNull(result); + + var str = result.ToJson(); + Console.WriteLine(result.ToJson()); + }).GetAwaiter().GetResult(); + } } } diff --git a/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs b/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs index ec34d64..f65e5e8 100644 --- a/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs +++ b/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs @@ -2,35 +2,21 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Text; using System.Text.Json; using System.Threading.Tasks; using Jellyfin.Extensions.Json; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller; using Microsoft.Extensions.Logging; using Jellyfin.Plugin.MetaShark.Model; using System.Threading; -using MediaBrowser.Controller.Entities.Movies; -using MediaBrowser.Common.Net; using System.Net.Http.Json; -using System.Security.Cryptography; -using Microsoft.AspNetCore.Mvc.ApiExplorer; using System.Net; using Jellyfin.Plugin.MetaShark.Api.Http; using System.Web; -using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource; using Microsoft.Extensions.Caching.Memory; -using Jellyfin.Plugin.MetaShark.Providers; using AngleSharp; -using System.Net.WebSockets; -using Jellyfin.Data.Entities.Libraries; using AngleSharp.Dom; using System.Text.RegularExpressions; using Jellyfin.Plugin.MetaShark.Core; -using System.Data; -using TMDbLib.Objects.Movies; -using System.Xml.Linq; using RateLimiter; using ComposableAsync; @@ -38,7 +24,8 @@ namespace Jellyfin.Plugin.MetaShark.Api { public class DoubanApi : IDisposable { - const string HTTP_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.44"; + public const string HTTP_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.44"; + public const string HTTP_REFERER = "https://www.douban.com/"; private readonly ILogger _logger; private HttpClient httpClient; private CookieContainer _cookieContainer; diff --git a/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs index e438bb0..ad3884a 100644 --- a/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs @@ -1,24 +1,8 @@ using MediaBrowser.Model.Plugins; -using System.Net; using System.Reflection; namespace Jellyfin.Plugin.MetaShark.Configuration; -/// -/// The configuration options. -/// -public enum SomeOptions -{ - /// - /// Option one. - /// - OneOption, - - /// - /// Second option. - /// - AnotherOption -} /// /// Plugin configuration. @@ -32,13 +16,17 @@ public class PluginConfiguration : BasePluginConfiguration public string DoubanCookies { get; set; } = string.Empty; /// - /// 开启防封禁 + /// 豆瓣开启防封禁 /// public bool EnableDoubanAvoidRiskControl { get; set; } = false; /// - /// 背景图使用原图 + /// 豆瓣背景图使用原图 /// public bool EnableDoubanBackdropRaw { get; set; } = false; + /// + /// 豆瓣图片代理地址 + /// + public string DoubanImageProxyBaseUrl { get; set; } = string.Empty; public bool EnableTmdb { get; set; } = true; diff --git a/Jellyfin.Plugin.MetaShark/Configuration/configPage.html b/Jellyfin.Plugin.MetaShark/Configuration/configPage.html index d684d6e..0a38e9c 100644 --- a/Jellyfin.Plugin.MetaShark/Configuration/configPage.html +++ b/Jellyfin.Plugin.MetaShark/Configuration/configPage.html @@ -34,6 +34,13 @@ class="emby-input" placeholder="_vwo_uuid_v2=1; __utmv=2; ...">
可为空,填写可搜索到需登录访问的影片,使用(www.douban.com)分号“;”分隔格式cookie.
+
+ + +
可为空,填写jellyfin访问域名,只有使用了nginx代理或docker,且豆瓣图片没法显示时,才需要填写 +
+
public class PersonProvider : BaseProvider, IRemoteMetadataProvider { - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - /// Instance of . public PersonProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi) : base(httpClientFactory, loggerFactory.CreateLogger(), libraryManager, httpContextAccessor, doubanApi, tmdbApi, omdbApi) { diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs index 8d30da8..b12723f 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs @@ -21,12 +21,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers { public class SeasonImageProvider : BaseProvider, IRemoteImageProvider { - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - /// Instance of . public SeasonImageProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi) : base(httpClientFactory, loggerFactory.CreateLogger(), libraryManager, httpContextAccessor, doubanApi, tmdbApi, omdbApi) { @@ -66,9 +60,9 @@ namespace Jellyfin.Plugin.MetaShark.Providers new RemoteImageInfo { ProviderName = primary.Name, - Url = primary.ImgMiddle, - Type = ImageType.Primary - } + Url = this.GetProxyImageUrl(primary.ImgMiddle), + Type = ImageType.Primary, + }, }; return res; } diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs index e405823..44369bc 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs @@ -89,7 +89,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers Name = c.Name, Type = c.RoleType, Role = c.Role, - ImageUrl = c.Img, + ImageUrl = this.GetLocalProxyImageUrl(c.Img), ProviderIds = new Dictionary { { DoubanProviderId, c.Id } }, })); diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs index 6778805..7cfd877 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs @@ -21,12 +21,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers { public class SeriesImageProvider : BaseProvider, IRemoteImageProvider { - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - /// Instance of . public SeriesImageProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi) : base(httpClientFactory, loggerFactory.CreateLogger(), libraryManager, httpContextAccessor, doubanApi, tmdbApi, omdbApi) { @@ -64,9 +58,9 @@ namespace Jellyfin.Plugin.MetaShark.Providers new RemoteImageInfo { ProviderName = primary.Name, - Url = primary.ImgMiddle, - Type = ImageType.Primary - } + Url = this.GetProxyImageUrl(primary.ImgMiddle), + Type = ImageType.Primary, + }, }; res.AddRange(dropback); return res; @@ -147,11 +141,10 @@ namespace Jellyfin.Plugin.MetaShark.Providers { if (config.EnableDoubanBackdropRaw) { - var fromBackdropSearch = RequestPath.Contains("/RemoteImages"); return new RemoteImageInfo { ProviderName = Name, - Url = fromBackdropSearch ? GetAbsoluteProxyImageUrl(x.Raw) : x.Raw, + Url = this.GetProxyImageUrl(x.Raw), Height = x.Height, Width = x.Width, Type = ImageType.Backdrop, @@ -162,7 +155,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers return new RemoteImageInfo { ProviderName = Name, - Url = x.Large, + Url = this.GetProxyImageUrl(x.Large), Type = ImageType.Backdrop, }; } diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs index 5a86bc0..7800cff 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs @@ -156,7 +156,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers Name = c.Name, Type = c.RoleType, Role = c.Role, - ImageUrl = c.Img, + ImageUrl = this.GetLocalProxyImageUrl(c.Img), ProviderIds = new Dictionary { { DoubanProviderId, c.Id } }, })); @@ -168,6 +168,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers return await this.GetMetadataByTmdb(tmdbId, info, cancellationToken).ConfigureAwait(false); } + this.Log($"匹配失败!可检查下年份是否与豆瓣一致,是否需要登录访问. [name]: {info.Name} [year]: {info.Year}"); return result; }