fix: actor exception
This commit is contained in:
parent
c79bfc5bd1
commit
528be0ee1c
|
@ -243,41 +243,48 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
EnsureLoadDoubanCookie();
|
EnsureLoadDoubanCookie();
|
||||||
await LimitRequestFrequently();
|
await LimitRequestFrequently();
|
||||||
|
|
||||||
var encodedKeyword = HttpUtility.UrlEncode(keyword);
|
try
|
||||||
var url = $"https://www.douban.com/j/search_suggest?q={encodedKeyword}";
|
|
||||||
|
|
||||||
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url))
|
|
||||||
{
|
{
|
||||||
requestMessage.Headers.Add("Origin", "https://www.douban.com");
|
var encodedKeyword = HttpUtility.UrlEncode(keyword);
|
||||||
requestMessage.Headers.Add("Referer", "https://www.douban.com/");
|
var url = $"https://www.douban.com/j/search_suggest?q={encodedKeyword}";
|
||||||
|
|
||||||
var response = await httpClient.SendAsync(requestMessage, cancellationToken).ConfigureAwait(false);
|
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url))
|
||||||
if (!response.IsSuccessStatusCode)
|
|
||||||
{
|
{
|
||||||
this._logger.LogWarning("douban suggest请求失败. keyword: {0} statusCode: {1}", keyword, response.StatusCode);
|
requestMessage.Headers.Add("Origin", "https://www.douban.com");
|
||||||
return list;
|
requestMessage.Headers.Add("Referer", "https://www.douban.com/");
|
||||||
}
|
|
||||||
|
|
||||||
JsonSerializerOptions? serializeOptions = null;
|
var response = await httpClient.SendAsync(requestMessage, cancellationToken).ConfigureAwait(false);
|
||||||
var result = await response.Content.ReadFromJsonAsync<DoubanSuggestResult>(serializeOptions, cancellationToken).ConfigureAwait(false);
|
if (!response.IsSuccessStatusCode)
|
||||||
|
|
||||||
if (result != null && result.Cards != null)
|
|
||||||
{
|
|
||||||
foreach (var suggest in result.Cards)
|
|
||||||
{
|
{
|
||||||
if (suggest.Type != "movie")
|
this._logger.LogWarning("douban suggest请求失败. keyword: {0} statusCode: {1}", keyword, response.StatusCode);
|
||||||
{
|
return list;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var movie = new DoubanSubject();
|
JsonSerializerOptions? serializeOptions = null;
|
||||||
movie.Sid = suggest.Sid;
|
var result = await response.Content.ReadFromJsonAsync<DoubanSuggestResult>(serializeOptions, cancellationToken).ConfigureAwait(false);
|
||||||
movie.Name = suggest.Title;
|
|
||||||
movie.Year = suggest.Year.ToInt();
|
if (result != null && result.Cards != null)
|
||||||
list.Add(movie);
|
{
|
||||||
|
foreach (var suggest in result.Cards)
|
||||||
|
{
|
||||||
|
if (suggest.Type != "movie")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var movie = new DoubanSubject();
|
||||||
|
movie.Sid = suggest.Sid;
|
||||||
|
movie.Name = suggest.Title;
|
||||||
|
movie.Year = suggest.Year.ToInt();
|
||||||
|
list.Add(movie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this._logger.LogError(ex, "SearchBySuggestAsync error. keyword: {0}", keyword);
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -427,7 +434,12 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
var celebrityImg = celebrityImgStr.GetMatchGroup(this.regBackgroundImage);
|
var celebrityImg = celebrityImgStr.GetMatchGroup(this.regBackgroundImage);
|
||||||
var celebrityNameStr = node.GetText("div.info a.name") ?? string.Empty;
|
var celebrityNameStr = node.GetText("div.info a.name") ?? string.Empty;
|
||||||
var arr = celebrityNameStr.Split(" ");
|
var arr = celebrityNameStr.Split(" ");
|
||||||
var celebrityName = arr.Length > 1 ? arr[0] : celebrityNameStr;
|
var celebrityName = arr.Length > 1 ? arr[0].Trim() : celebrityNameStr;
|
||||||
|
// 有时存在演员信息缺少名字的
|
||||||
|
if (string.IsNullOrEmpty(celebrityName))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var celebrityRoleStr = node.GetText("div.info span.role") ?? string.Empty;
|
var celebrityRoleStr = node.GetText("div.info span.role") ?? string.Empty;
|
||||||
var celebrityRole = celebrityRoleStr.GetMatchGroup(this.regRole);
|
var celebrityRole = celebrityRoleStr.GetMatchGroup(this.regRole);
|
||||||
var arrRole = celebrityRoleStr.Split(" ");
|
var arrRole = celebrityRoleStr.Split(" ");
|
||||||
|
@ -588,9 +600,10 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
|
|
||||||
public async Task<List<DoubanPhoto>> GetWallpaperBySidAsync(string sid, CancellationToken cancellationToken)
|
public async Task<List<DoubanPhoto>> GetWallpaperBySidAsync(string sid, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
var list = new List<DoubanPhoto>();
|
||||||
if (string.IsNullOrEmpty(sid))
|
if (string.IsNullOrEmpty(sid))
|
||||||
{
|
{
|
||||||
return new List<DoubanPhoto>();
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cacheKey = $"photo_{sid}";
|
var cacheKey = $"photo_{sid}";
|
||||||
|
@ -604,52 +617,59 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
EnsureLoadDoubanCookie();
|
EnsureLoadDoubanCookie();
|
||||||
await LimitRequestFrequently();
|
await LimitRequestFrequently();
|
||||||
|
|
||||||
var list = new List<DoubanPhoto>();
|
try
|
||||||
var url = $"https://movie.douban.com/subject/{sid}/photos?type=W&start=0&sortby=size&size=a&subtype=a";
|
|
||||||
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (!response.IsSuccessStatusCode)
|
|
||||||
{
|
{
|
||||||
return new List<DoubanPhoto>();
|
var url = $"https://movie.douban.com/subject/{sid}/photos?type=W&start=0&sortby=size&size=a&subtype=a";
|
||||||
}
|
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
var body = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
var context = BrowsingContext.New();
|
|
||||||
var doc = await context.OpenAsync(req => req.Content(body), cancellationToken).ConfigureAwait(false);
|
|
||||||
var elements = doc.QuerySelectorAll(".poster-col3>li");
|
|
||||||
|
|
||||||
foreach (var node in elements)
|
|
||||||
{
|
|
||||||
|
|
||||||
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 size = node.GetText("div.prop") ?? string.Empty;
|
|
||||||
var width = string.Empty;
|
|
||||||
var height = string.Empty;
|
|
||||||
if (!string.IsNullOrEmpty(size))
|
|
||||||
{
|
{
|
||||||
var arr = size.Split('x');
|
return list;
|
||||||
if (arr.Length == 2)
|
|
||||||
{
|
|
||||||
width = arr[0];
|
|
||||||
height = arr[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var photo = new DoubanPhoto();
|
var body = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||||
photo.Id = id;
|
var context = BrowsingContext.New();
|
||||||
photo.Size = size;
|
var doc = await context.OpenAsync(req => req.Content(body), cancellationToken).ConfigureAwait(false);
|
||||||
photo.Small = small;
|
var elements = doc.QuerySelectorAll(".poster-col3>li");
|
||||||
photo.Medium = medium;
|
|
||||||
photo.Large = large;
|
|
||||||
photo.Width = width.ToInt();
|
|
||||||
photo.Height = height.ToInt();
|
|
||||||
|
|
||||||
list.Add(photo);
|
foreach (var node in elements)
|
||||||
|
{
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
photo.Size = size;
|
||||||
|
photo.Small = small;
|
||||||
|
photo.Medium = medium;
|
||||||
|
photo.Large = large;
|
||||||
|
photo.Width = width.ToInt();
|
||||||
|
photo.Height = height.ToInt();
|
||||||
|
|
||||||
|
list.Add(photo);
|
||||||
|
}
|
||||||
|
|
||||||
|
_memoryCache.Set<List<DoubanPhoto>>(cacheKey, list, expiredOption);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this._logger.LogError(ex, "GetWallpaperBySidAsync error. sid: {0}", sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
_memoryCache.Set<List<DoubanPhoto>>(cacheKey, list, expiredOption);
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -657,12 +677,19 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
{
|
{
|
||||||
EnsureLoadDoubanCookie();
|
EnsureLoadDoubanCookie();
|
||||||
|
|
||||||
var url = "https://www.douban.com/mine/";
|
try
|
||||||
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
|
||||||
var requestUrl = response.RequestMessage?.RequestUri?.ToString();
|
|
||||||
if (requestUrl == null || requestUrl.Contains("login") || requestUrl.Contains("sec.douban.com"))
|
|
||||||
{
|
{
|
||||||
return false;
|
var url = "https://www.douban.com/mine/";
|
||||||
|
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
||||||
|
var requestUrl = response.RequestMessage?.RequestUri?.ToString();
|
||||||
|
if (requestUrl == null || requestUrl.Contains("accounts.douban.com") || requestUrl.Contains("login") || requestUrl.Contains("sec.douban.com"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this._logger.LogError(ex, "CheckLoginAsync error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace Jellyfin.Plugin.MetaShark.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 代理访问图片.
|
/// 检查豆瓣cookie是否失效.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("douban/checklogin")]
|
[Route("douban/checklogin")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|
|
@ -80,8 +80,8 @@ namespace Jellyfin.Plugin.MetaShark.Model
|
||||||
return limitCelebrities;
|
return limitCelebrities;
|
||||||
}
|
}
|
||||||
|
|
||||||
limitCelebrities.AddRange(Celebrities.Where(x => x.RoleType == MediaBrowser.Model.Entities.PersonType.Director).Take(5));
|
limitCelebrities.AddRange(Celebrities.Where(x => x.RoleType == MediaBrowser.Model.Entities.PersonType.Director && !string.IsNullOrEmpty(x.Name)).Take(5));
|
||||||
limitCelebrities.AddRange(Celebrities.Where(x => x.RoleType != MediaBrowser.Model.Entities.PersonType.Director));
|
limitCelebrities.AddRange(Celebrities.Where(x => x.RoleType != MediaBrowser.Model.Entities.PersonType.Director && !string.IsNullOrEmpty(x.Name)));
|
||||||
|
|
||||||
return limitCelebrities;
|
return limitCelebrities;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue