Optimize image
This commit is contained in:
parent
584d981713
commit
c9df266b99
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 开启防封禁
|
||||
/// </summary>
|
||||
public bool EnableDoubanAvoidRiskControl { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 背景图使用原图
|
||||
/// </summary>
|
||||
public bool EnableDoubanBackdropRaw { get; set; } = false;
|
||||
|
||||
public bool EnableTmdb { get; set; } = true;
|
||||
|
||||
|
|
|
@ -48,6 +48,14 @@
|
|||
</label>
|
||||
<div class="fieldDescription">勾选后,刮削会变慢,适合刮削大量影片时使用,建议搭配网站cookie一起使用</div>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label" for="EnableDoubanBackdropRaw">
|
||||
<input id="EnableDoubanBackdropRaw" name="EnableDoubanBackdropRaw" type="checkbox"
|
||||
is="emby-checkbox" />
|
||||
<span>背景图使用原图</span>
|
||||
</label>
|
||||
<div class="fieldDescription">原图豆瓣限制更严格,一般不建议开启</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="verticalSection verticalSection-extrabottompadding">
|
||||
|
@ -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;
|
||||
|
|
|
@ -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
|
|||
/// </summary>
|
||||
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);
|
||||
|
|
|
@ -133,8 +133,20 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
this.Log("GetImageResponse url: {0}", url);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query for a background photo
|
||||
|
@ -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 =>
|
||||
{
|
||||
if (config.EnableDoubanBackdropRaw)
|
||||
{
|
||||
var fromBackdropSearch = RequestPath.Contains("/RemoteImages");
|
||||
return new RemoteImageInfo
|
||||
{
|
||||
ProviderName = Name,
|
||||
Url = this.GetProxyImageUrl(x.Raw),
|
||||
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();
|
||||
|
||||
}
|
||||
|
|
|
@ -130,10 +130,22 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
public async Task<HttpResponseMessage> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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 =>
|
||||
{
|
||||
if (config.EnableDoubanBackdropRaw)
|
||||
{
|
||||
var fromBackdropSearch = RequestPath.Contains("/RemoteImages");
|
||||
return new RemoteImageInfo
|
||||
{
|
||||
ProviderName = Name,
|
||||
Url = this.GetProxyImageUrl(x.Raw),
|
||||
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();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue