tweak: show douban cookie valid msg
This commit is contained in:
parent
3c054cfa2d
commit
169ce81a94
|
@ -68,6 +68,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
// 匹配除了换行符之外所有空白
|
// 匹配除了换行符之外所有空白
|
||||||
Regex regOverviewSpace = new Regex(@"\n[^\S\n]+", RegexOptions.Compiled);
|
Regex regOverviewSpace = new Regex(@"\n[^\S\n]+", RegexOptions.Compiled);
|
||||||
Regex regPhotoId = new Regex(@"/photo/(\d+?)/", RegexOptions.Compiled);
|
Regex regPhotoId = new Regex(@"/photo/(\d+?)/", RegexOptions.Compiled);
|
||||||
|
Regex regLoginName = new Regex(@"<div[^>]*?db-usr-profile[^>]*?>[\w\W]*?<h1>([^>]*?)<", RegexOptions.Compiled);
|
||||||
|
|
||||||
// 默认200毫秒请求1次
|
// 默认200毫秒请求1次
|
||||||
private TimeLimiter _defaultTimeConstraint = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromMilliseconds(200));
|
private TimeLimiter _defaultTimeConstraint = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromMilliseconds(200));
|
||||||
|
@ -802,6 +803,27 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<DoubanLoginInfo> GetLoginInfoAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var loginInfo = new DoubanLoginInfo();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var url = "https://www.douban.com/mine/";
|
||||||
|
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
||||||
|
var requestUrl = response.RequestMessage?.RequestUri?.ToString();
|
||||||
|
var body = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
var loginName = this.Match(body, regLoginName).Trim();
|
||||||
|
loginInfo.Name = loginName;
|
||||||
|
loginInfo.IsLogined = !(requestUrl == null || requestUrl.Contains("accounts.douban.com") || requestUrl.Contains("login") || requestUrl.Contains("sec.douban.com"));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this._logger.LogError(ex, "GetLoginInfoAsync error.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return loginInfo;
|
||||||
|
}
|
||||||
|
|
||||||
protected async Task LimitRequestFrequently()
|
protected async Task LimitRequestFrequently()
|
||||||
{
|
{
|
||||||
if (IsEnableAvoidRiskControl())
|
if (IsEnableAvoidRiskControl())
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
</legend>
|
</legend>
|
||||||
<div class="inputContainer">
|
<div class="inputContainer">
|
||||||
<label class="inputLabel inputLabelUnfocused" for="DoubanCookies">豆瓣网站cookie<span
|
<label class="inputLabel inputLabelUnfocused" for="DoubanCookies">豆瓣网站cookie<span
|
||||||
id="login_invalid"
|
id="login_msg"
|
||||||
style="color: red; margin-left: 8px; display: none;">(已失效)</span></label>
|
style="margin-left: 8px; display: none;"></span></label>
|
||||||
<textarea rows="5" is="emby-input" type="text" id="DoubanCookies" name="DoubanCookies"
|
<textarea rows="5" is="emby-input" type="text" id="DoubanCookies" name="DoubanCookies"
|
||||||
class="emby-input" placeholder="_vwo_uuid_v2=1; __utmv=2; ..."></textarea>
|
class="emby-input" placeholder="_vwo_uuid_v2=1; __utmv=2; ..."></textarea>
|
||||||
<div class="fieldDescription">可为空,填写可搜索到需登录访问的影片,使用(www.douban.com)分号“;”分隔格式cookie.</div>
|
<div class="fieldDescription">可为空,填写可搜索到需登录访问的影片,使用(www.douban.com)分号“;”分隔格式cookie.</div>
|
||||||
|
@ -253,16 +253,16 @@
|
||||||
function checkDoubanLogin() {
|
function checkDoubanLogin() {
|
||||||
let cookie = document.querySelector('#DoubanCookies').value
|
let cookie = document.querySelector('#DoubanCookies').value
|
||||||
if (!cookie || !$.trim(cookie)) {
|
if (!cookie || !$.trim(cookie)) {
|
||||||
$('#login_invalid').hide();
|
$('#login_msg').hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$.getJSON("/plugin/metashark/douban/checklogin", function (resp) {
|
$.getJSON("/plugin/metashark/douban/checklogin", function (resp) {
|
||||||
if (resp && resp.code != 1) {
|
if (resp && resp.code != 1) {
|
||||||
$('#login_invalid').show();
|
$('#login_msg').css("color", "red").text('(已失效)').show();
|
||||||
} else {
|
} else {
|
||||||
$('#login_invalid').hide();
|
$('#login_msg').css("color", "").text('(已生效)').show();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,10 +77,11 @@ namespace Jellyfin.Plugin.MetaShark.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ApiResult> CheckDoubanLogin()
|
public async Task<ApiResult> CheckDoubanLogin()
|
||||||
{
|
{
|
||||||
var isLogin = await _doubanApi.CheckLoginAsync(CancellationToken.None);
|
var loginInfo = await this._doubanApi.GetLoginInfoAsync(CancellationToken.None).ConfigureAwait(false);
|
||||||
return new ApiResult(isLogin ? 1 : 0, isLogin ? "logined" : "not login");
|
return new ApiResult(loginInfo.IsLogined ? 1 : 0, loginInfo.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private HttpClient GetHttpClient()
|
private HttpClient GetHttpClient()
|
||||||
{
|
{
|
||||||
var client = _httpClientFactory.CreateClient(NamedClient.Default);
|
var client = _httpClientFactory.CreateClient(NamedClient.Default);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MetaShark.Model
|
||||||
|
{
|
||||||
|
public class DoubanLoginInfo
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public bool IsLogined { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue