fix: actor exception

This commit is contained in:
cxfksword 2023-01-14 10:32:50 +08:00
parent c79bfc5bd1
commit 528be0ee1c
3 changed files with 102 additions and 75 deletions

View File

@ -243,6 +243,8 @@ namespace Jellyfin.Plugin.MetaShark.Api
EnsureLoadDoubanCookie(); EnsureLoadDoubanCookie();
await LimitRequestFrequently(); await LimitRequestFrequently();
try
{
var encodedKeyword = HttpUtility.UrlEncode(keyword); var encodedKeyword = HttpUtility.UrlEncode(keyword);
var url = $"https://www.douban.com/j/search_suggest?q={encodedKeyword}"; var url = $"https://www.douban.com/j/search_suggest?q={encodedKeyword}";
@ -278,6 +280,11 @@ namespace Jellyfin.Plugin.MetaShark.Api
} }
} }
} }
}
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,12 +617,13 @@ 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 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); var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {
return new List<DoubanPhoto>(); return list;
} }
var body = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); var body = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
@ -650,6 +664,12 @@ namespace Jellyfin.Plugin.MetaShark.Api
} }
_memoryCache.Set<List<DoubanPhoto>>(cacheKey, list, expiredOption); _memoryCache.Set<List<DoubanPhoto>>(cacheKey, list, expiredOption);
}
catch (Exception ex)
{
this._logger.LogError(ex, "GetWallpaperBySidAsync error. sid: {0}", sid);
}
return list; return list;
} }
@ -657,13 +677,20 @@ namespace Jellyfin.Plugin.MetaShark.Api
{ {
EnsureLoadDoubanCookie(); EnsureLoadDoubanCookie();
try
{
var url = "https://www.douban.com/mine/"; var url = "https://www.douban.com/mine/";
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false); var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
var requestUrl = response.RequestMessage?.RequestUri?.ToString(); var requestUrl = response.RequestMessage?.RequestUri?.ToString();
if (requestUrl == null || requestUrl.Contains("login") || requestUrl.Contains("sec.douban.com")) if (requestUrl == null || requestUrl.Contains("accounts.douban.com") || requestUrl.Contains("login") || requestUrl.Contains("sec.douban.com"))
{ {
return false; return false;
} }
}
catch (Exception ex)
{
this._logger.LogError(ex, "CheckLoginAsync error.");
}
return true; return true;
} }

View File

@ -77,7 +77,7 @@ namespace Jellyfin.Plugin.MetaShark.Controllers
} }
/// <summary> /// <summary>
/// 代理访问图片. /// 检查豆瓣cookie是否失效.
/// </summary> /// </summary>
[Route("douban/checklogin")] [Route("douban/checklogin")]
[HttpGet] [HttpGet]

View File

@ -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;
} }