diff --git a/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs index 06e9650..4b47352 100644 --- a/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.MetaShark/Configuration/PluginConfiguration.cs @@ -28,8 +28,14 @@ public class PluginConfiguration : BasePluginConfiguration public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? string.Empty; public string DoubanCookies { get; set; } = string.Empty; - + /// + /// 开启防封禁 + /// public bool EnableDoubanAvoidRiskControl { get; set; } = false; + /// + /// 背景图使用原图 + /// + public bool EnableDoubanBackdropRaw { get; set; } = false; public bool EnableTmdb { get; set; } = true; diff --git a/Jellyfin.Plugin.MetaShark/Configuration/configPage.html b/Jellyfin.Plugin.MetaShark/Configuration/configPage.html index a3214ea..dc91c5d 100644 --- a/Jellyfin.Plugin.MetaShark/Configuration/configPage.html +++ b/Jellyfin.Plugin.MetaShark/Configuration/configPage.html @@ -48,6 +48,14 @@
勾选后,刮削会变慢,适合刮削大量影片时使用,建议搭配网站cookie一起使用
+
+ +
原图豆瓣限制更严格,一般不建议开启
+
@@ -110,6 +118,7 @@ document.querySelector('#DoubanCookies').value = config.DoubanCookies; document.querySelector('#EnableDoubanAvoidRiskControl').checked = config.EnableDoubanAvoidRiskControl; + document.querySelector('#EnableDoubanBackdropRaw').checked = config.EnableDoubanBackdropRaw; document.querySelector('#EnableTmdb').checked = config.EnableTmdb; document.querySelector('#EnableTmdbSearch').checked = config.EnableTmdbSearch; document.querySelector('#EnableTmdbBackdrop').checked = config.EnableTmdbBackdrop; @@ -128,6 +137,7 @@ ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) { config.DoubanCookies = document.querySelector('#DoubanCookies').value; config.EnableDoubanAvoidRiskControl = document.querySelector('#EnableDoubanAvoidRiskControl').checked; + config.EnableDoubanBackdropRaw = document.querySelector('#EnableDoubanBackdropRaw').checked; config.EnableTmdb = document.querySelector('#EnableTmdb').checked; config.EnableTmdbSearch = document.querySelector('#EnableTmdbSearch').checked; config.EnableTmdbBackdrop = document.querySelector('#EnableTmdbBackdrop').checked; diff --git a/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs index 128bb4a..f059d75 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs @@ -61,6 +61,38 @@ namespace Jellyfin.Plugin.MetaShark.Providers } } + protected string RequestDomain + { + get + { + if (_httpContextAccessor.HttpContext != null) + { + return _httpContextAccessor.HttpContext.Request.Scheme + System.Uri.SchemeDelimiter + _httpContextAccessor.HttpContext.Request.Host; + } + else + { + return string.Empty; + } + + } + } + + protected string RequestPath + { + get + { + if (_httpContextAccessor.HttpContext != null) + { + return _httpContextAccessor.HttpContext.Request.Path.ToString(); + } + else + { + return string.Empty; + } + + } + } + protected BaseProvider(IHttpClientFactory httpClientFactory, ILogger logger, ILibraryManager libraryManager, IHttpContextAccessor httpContextAccessor, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi) { this._doubanApi = doubanApi; @@ -250,11 +282,17 @@ namespace Jellyfin.Plugin.MetaShark.Providers /// protected string GetProxyImageUrl(string url) { + var fromWeb = false; if (_httpContextAccessor.HttpContext != null) { - var domain = _httpContextAccessor.HttpContext.Request.Scheme + System.Uri.SchemeDelimiter + _httpContextAccessor.HttpContext.Request.Host; + var userAgent = _httpContextAccessor.HttpContext.Request.Headers.UserAgent.ToString(); + fromWeb = userAgent.Contains("Chrome") || userAgent.Contains("Safari"); + } + + if (fromWeb) + { var encodedUrl = HttpUtility.UrlEncode(url); - return $"{domain}/plugin/metashark/proxy/image/?url={encodedUrl}"; + return $"/plugin/metashark/proxy/image/?url={encodedUrl}"; } else { @@ -262,6 +300,13 @@ namespace Jellyfin.Plugin.MetaShark.Providers } } + + protected string GetAbsoluteProxyImageUrl(string url) + { + var encodedUrl = HttpUtility.UrlEncode(url); + return $"{this.RequestDomain}/plugin/metashark/proxy/image/?url={encodedUrl}"; + } + protected void Log(string? message, params object?[] args) { this._logger.LogInformation($"[MetaShark] {message}", args); diff --git a/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs index 17cf0f6..eac72c7 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs @@ -133,7 +133,19 @@ namespace Jellyfin.Plugin.MetaShark.Providers public async Task GetImageResponse(string url, CancellationToken cancellationToken) { this.Log("GetImageResponse url: {0}", url); - return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); + + if (url.Contains("doubanio.com")) + {// 豆瓣图,带referer下载 + using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) + { + requestMessage.Headers.Add("Referer", "https://www.douban.com/"); + return await this._httpClientFactory.CreateClient().SendAsync(requestMessage, cancellationToken).ConfigureAwait(false); + } + } + else + { + return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); + } } /// @@ -155,14 +167,27 @@ namespace Jellyfin.Plugin.MetaShark.Providers this.Log("GetBackdrop from douban sid: {0}", sid); list = photo.Where(x => x.Width >= 1280 && x.Width <= 4096 && x.Width > x.Height * 1.3).Select(x => { - return new RemoteImageInfo + if (config.EnableDoubanBackdropRaw) { - ProviderName = Name, - Url = this.GetProxyImageUrl(x.Raw), - Height = x.Height, - Width = x.Width, - Type = ImageType.Backdrop, - }; + var fromBackdropSearch = RequestPath.Contains("/RemoteImages"); + return new RemoteImageInfo + { + ProviderName = Name, + Url = fromBackdropSearch ? GetAbsoluteProxyImageUrl(x.Raw) : x.Raw, + Height = x.Height, + Width = x.Width, + Type = ImageType.Backdrop, + }; + } + else + { + return new RemoteImageInfo + { + ProviderName = Name, + Url = x.Large, + Type = ImageType.Backdrop, + }; + } }).ToList(); } diff --git a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs index 2aae377..b359bc5 100644 --- a/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs +++ b/Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs @@ -130,10 +130,22 @@ namespace Jellyfin.Plugin.MetaShark.Providers } /// - public Task GetImageResponse(string url, CancellationToken cancellationToken) + public async Task GetImageResponse(string url, CancellationToken cancellationToken) { this.Log("GetImageResponse url: {0}", url); - return this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken); + + if (url.Contains("doubanio.com")) + {// 豆瓣图,带referer下载 + using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) + { + requestMessage.Headers.Add("Referer", "https://www.douban.com/"); + return await this._httpClientFactory.CreateClient().SendAsync(requestMessage, cancellationToken).ConfigureAwait(false); + } + } + else + { + return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); + } } /// @@ -155,14 +167,27 @@ namespace Jellyfin.Plugin.MetaShark.Providers this.Log("GetBackdrop from douban sid: {0}", sid); list = photo.Where(x => x.Width >= 1280 && x.Width <= 4096 && x.Width > x.Height * 1.3).Select(x => { - return new RemoteImageInfo + if (config.EnableDoubanBackdropRaw) { - ProviderName = Name, - Url = this.GetProxyImageUrl(x.Raw), - Height = x.Height, - Width = x.Width, - Type = ImageType.Backdrop, - }; + var fromBackdropSearch = RequestPath.Contains("/RemoteImages"); + return new RemoteImageInfo + { + ProviderName = Name, + Url = fromBackdropSearch ? GetAbsoluteProxyImageUrl(x.Raw) : x.Raw, + Height = x.Height, + Width = x.Width, + Type = ImageType.Backdrop, + }; + } + else + { + return new RemoteImageInfo + { + ProviderName = Name, + Url = x.Large, + Type = ImageType.Backdrop, + }; + } }).ToList(); }