Optimize backdrop
This commit is contained in:
parent
d7db6dbc33
commit
b01c8a4b5b
|
@ -34,9 +34,9 @@ namespace Jellyfin.Plugin.MetaShark.Test
|
|||
{
|
||||
var info = new MediaBrowser.Controller.Entities.Movies.Movie()
|
||||
{
|
||||
Name = "机动战士高达 逆袭的夏亚",
|
||||
Name = "秒速5厘米",
|
||||
PreferredMetadataLanguage = "zh",
|
||||
ProviderIds = new Dictionary<string, string> { { BaseProvider.DoubanProviderId, "1401536" }, { MetadataProvider.Tmdb.ToString(), "16157" } }
|
||||
ProviderIds = new Dictionary<string, string> { { BaseProvider.DoubanProviderId, "2043546" }, { MetadataProvider.Tmdb.ToString(), "38142" } }
|
||||
};
|
||||
var doubanApi = new DoubanApi(loggerFactory);
|
||||
var tmdbApi = new TmdbApi(loggerFactory);
|
||||
|
|
|
@ -78,9 +78,10 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
|||
Regex regNickname = new Regex(@"更多外文名: \n(.+?)\n", RegexOptions.Compiled);
|
||||
Regex regFamily = new Regex(@"家庭成员: \n(.+?)\n", RegexOptions.Compiled);
|
||||
Regex regCelebrityImdb = new Regex(@"imdb编号:\s+?(nm\d+)", RegexOptions.Compiled);
|
||||
Regex regImgHost = new Regex(@"\/\/(img\d+?)\.", RegexOptions.Compiled);
|
||||
|
||||
// 默认500毫秒请求1次
|
||||
private TimeLimiter _defaultTimeConstraint = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromMilliseconds(500));
|
||||
// 默认200毫秒请求1次
|
||||
private TimeLimiter _defaultTimeConstraint = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromMilliseconds(200));
|
||||
// 未登录最多1分钟10次请求,不然5分钟后会被封ip
|
||||
private TimeLimiter _guestTimeConstraint = TimeLimiter.Compose(new CountByIntervalAwaitableConstraint(10, TimeSpan.FromMinutes(1)), new CountByIntervalAwaitableConstraint(1, TimeSpan.FromMilliseconds(5000)));
|
||||
// 登录后最多1分钟20次请求,不然会触发机器人检验
|
||||
|
@ -635,21 +636,13 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
|||
{
|
||||
|
||||
var id = node.GetAttribute("data-id") ?? string.Empty;
|
||||
var small = $"https://img2.doubanio.com/view/photo/s/public/p{id}.jpg";
|
||||
var medium = $"https://img2.doubanio.com/view/photo/m/public/p{id}.jpg";
|
||||
var large = $"https://img2.doubanio.com/view/photo/l/public/p{id}.jpg";
|
||||
var imgUrl = node.QuerySelector("img")?.GetAttribute("src") ?? string.Empty;
|
||||
var imgHost = regImgHost.FirstMatchGroup(imgUrl, "img2");
|
||||
var small = $"https://{imgHost}.doubanio.com/view/photo/s/public/p{id}.jpg";
|
||||
var medium = $"https://{imgHost}.doubanio.com/view/photo/m/public/p{id}.jpg";
|
||||
var large = $"https://{imgHost}.doubanio.com/view/photo/l/public/p{id}.jpg";
|
||||
var raw = $"https://{imgHost}.doubanio.com/view/photo/raw/public/p{id}.jpg";
|
||||
var size = node.GetText("div.prop") ?? string.Empty;
|
||||
var width = string.Empty;
|
||||
var height = string.Empty;
|
||||
if (!string.IsNullOrEmpty(size))
|
||||
{
|
||||
var arr = size.Split('x');
|
||||
if (arr.Length == 2)
|
||||
{
|
||||
width = arr[0];
|
||||
height = arr[1];
|
||||
}
|
||||
}
|
||||
|
||||
var photo = new DoubanPhoto();
|
||||
photo.Id = id;
|
||||
|
@ -657,8 +650,16 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
|||
photo.Small = small;
|
||||
photo.Medium = medium;
|
||||
photo.Large = large;
|
||||
photo.Width = width.ToInt();
|
||||
photo.Height = height.ToInt();
|
||||
photo.Raw = raw;
|
||||
if (!string.IsNullOrEmpty(size))
|
||||
{
|
||||
var arr = size.Split('x');
|
||||
if (arr.Length == 2)
|
||||
{
|
||||
photo.Width = arr[0].ToInt();
|
||||
photo.Height = arr[1].ToInt();
|
||||
}
|
||||
}
|
||||
|
||||
list.Add(photo);
|
||||
}
|
||||
|
|
|
@ -57,8 +57,14 @@ namespace Jellyfin.Plugin.MetaShark.Controllers
|
|||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
HttpResponseMessage response;
|
||||
var httpClient = GetHttpClient();
|
||||
var response = await httpClient.GetAsync(url);
|
||||
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url))
|
||||
{
|
||||
requestMessage.Headers.Add("Referer", "https://www.douban.com/");
|
||||
|
||||
response = await httpClient.SendAsync(requestMessage);
|
||||
}
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
|
||||
Response.StatusCode = (int)response.StatusCode;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using StringMetric;
|
||||
|
||||
namespace Jellyfin.Plugin.MetaShark.Core
|
||||
{
|
||||
public static class RegexExtension
|
||||
{
|
||||
public static string FirstMatchGroup(this Regex reg, string text, string defalutVal = "")
|
||||
{
|
||||
var match = reg.Match(text);
|
||||
if (match.Success && match.Groups.Count > 1)
|
||||
{
|
||||
return match.Groups[1].Value.Trim();
|
||||
}
|
||||
|
||||
return defalutVal;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -150,8 +150,12 @@ namespace Jellyfin.Plugin.MetaShark.Model
|
|||
public string Small { get; set; }
|
||||
public string Medium { get; set; }
|
||||
public string Large { get; set; }
|
||||
/// <summary>
|
||||
/// 原始图片url,必须带referer访问
|
||||
/// </summary>
|
||||
public string Raw { get; set; }
|
||||
public string Size { get; set; }
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public int? Width { get; set; }
|
||||
public int? Height { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,11 +247,13 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
/// <summary>
|
||||
/// 浏览器来源请求,返回代理地址(no-referer对于background-image不生效),其他客户端请求,返回原始图片地址
|
||||
/// </summary>
|
||||
protected string GetProxyImageUrl(string url)
|
||||
protected string GetProxyImageUrl(string url, bool absolute = false)
|
||||
{
|
||||
var fromWeb = false;
|
||||
var domain = string.Empty;
|
||||
if (_httpContextAccessor.HttpContext != null)
|
||||
{
|
||||
domain = _httpContextAccessor.HttpContext.Request.Scheme + System.Uri.SchemeDelimiter + _httpContextAccessor.HttpContext.Request.Host;
|
||||
var clientInfo = _httpContextAccessor.HttpContext.Request.Headers.FirstOrDefault(x => x.Key == "X-Emby-Authorization").Value.FirstOrDefault() ?? string.Empty;
|
||||
fromWeb = clientInfo.Contains("Jellyfin Web");
|
||||
}
|
||||
|
@ -259,7 +261,14 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
if (fromWeb)
|
||||
{
|
||||
var encodedUrl = HttpUtility.UrlEncode(url);
|
||||
return $"/plugin/metashark/proxy/image/?url={encodedUrl}";
|
||||
if (absolute)
|
||||
{
|
||||
return $"{domain}/plugin/metashark/proxy/image/?url={encodedUrl}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"/plugin/metashark/proxy/image/?url={encodedUrl}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -153,12 +153,14 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
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 =>
|
||||
list = photo.Where(x => x.Width >= 1280 && x.Width <= 4096 && x.Width > x.Height * 1.3).Select(x =>
|
||||
{
|
||||
return new RemoteImageInfo
|
||||
{
|
||||
ProviderName = Name,
|
||||
Url = x.Large,
|
||||
Url = this.GetProxyImageUrl(x.Raw, true),
|
||||
Height = x.Height,
|
||||
Width = x.Width,
|
||||
Type = ImageType.Backdrop,
|
||||
};
|
||||
}).ToList();
|
||||
|
|
|
@ -153,12 +153,14 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
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 =>
|
||||
list = photo.Where(x => x.Width >= 1280 && x.Width <= 4096 && x.Width > x.Height * 1.3).Select(x =>
|
||||
{
|
||||
return new RemoteImageInfo
|
||||
{
|
||||
ProviderName = Name,
|
||||
Url = x.Large,
|
||||
Url = this.GetProxyImageUrl(x.Raw, true),
|
||||
Height = x.Height,
|
||||
Width = x.Width,
|
||||
Type = ImageType.Backdrop,
|
||||
};
|
||||
}).ToList();
|
||||
|
|
Loading…
Reference in New Issue