fix(core): changes around danmaku connection

This commit is contained in:
genteure 2023-08-25 01:07:52 +08:00
parent c4c5aeb36a
commit cf0f72e98c
2 changed files with 24 additions and 9 deletions

View File

@ -30,14 +30,17 @@ namespace BililiveRecorder.Core.Api.Danmaku
if (headerHashTable.GetValue(null) is not Hashtable table) return;
var info = table["User-Agent"];
if (info is null) return;
foreach (var key in new[] { "User-Agent", "Referer", "Accept" })
{
var info = table[key];
if (info is null) continue;
var isRequestRestrictedProperty = info.GetType().GetField("IsRequestRestricted", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
if (isRequestRestrictedProperty is null) return;
if (isRequestRestrictedProperty is null) continue;
isRequestRestrictedProperty.SetValue(info, false);
}
}
public DanmakuTransportWebSocket()
{
@ -48,8 +51,12 @@ namespace BililiveRecorder.Core.Api.Danmaku
options.Proxy = null;
options.Cookies = null;
options.SetRequestHeader("Origin", HttpApiClient.HttpHeaderOrigin);
options.SetRequestHeader("Accept-Language", HttpApiClient.HttpHeaderAcceptLanguage);
options.SetRequestHeader("Referer", HttpApiClient.HttpHeaderReferer);
options.SetRequestHeader("User-Agent", HttpApiClient.HttpHeaderUserAgent);
options.SetRequestHeader("Accept-Language", HttpApiClient.HttpHeaderAcceptLanguage);
options.SetRequestHeader("Accept", "*/*");
options.SetRequestHeader("Pragma", "no-cache");
options.SetRequestHeader("Cache-Control", "no-cache");
}
public async Task<PipeReader> ConnectAsync(string host, int port, CancellationToken cancellationToken)

View File

@ -558,16 +558,24 @@ retry:
private string? DanmakuClient_BeforeHandshake(string json)
{
if (this.RoomConfig.DanmakuAuthenticateWithStreamerUid)
var danmakuAuthenticateWithStreamerUid = this.RoomConfig.DanmakuAuthenticateWithStreamerUid;
if (danmakuAuthenticateWithStreamerUid)
{
var obj = JObject.Parse(json);
obj["uid"] = this.Uid;
// delete key and buvid
obj.Remove("key");
obj.Remove("buvid");
json = obj.ToString(Formatting.None);
}
return this.userScriptRunner.CallOnDanmakuHandshake(this.logger, this, json);
var scriptUpdatedJson = this.userScriptRunner.CallOnDanmakuHandshake(this.logger, this, json);
if (scriptUpdatedJson is not null)
return scriptUpdatedJson;
else if (danmakuAuthenticateWithStreamerUid)
return json;
else
return null;
}
private void DanmakuClient_DanmakuReceived(object? sender, Api.Danmaku.DanmakuReceivedEventArgs e)