mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 03:32:20 +08:00
fix(core): changes around danmaku connection
This commit is contained in:
parent
c4c5aeb36a
commit
cf0f72e98c
|
@ -30,13 +30,16 @@ namespace BililiveRecorder.Core.Api.Danmaku
|
||||||
|
|
||||||
if (headerHashTable.GetValue(null) is not Hashtable table) return;
|
if (headerHashTable.GetValue(null) is not Hashtable table) return;
|
||||||
|
|
||||||
var info = table["User-Agent"];
|
foreach (var key in new[] { "User-Agent", "Referer", "Accept" })
|
||||||
if (info is null) return;
|
{
|
||||||
|
var info = table[key];
|
||||||
|
if (info is null) continue;
|
||||||
|
|
||||||
var isRequestRestrictedProperty = info.GetType().GetField("IsRequestRestricted", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
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);
|
isRequestRestrictedProperty.SetValue(info, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DanmakuTransportWebSocket()
|
public DanmakuTransportWebSocket()
|
||||||
|
@ -48,8 +51,12 @@ namespace BililiveRecorder.Core.Api.Danmaku
|
||||||
options.Proxy = null;
|
options.Proxy = null;
|
||||||
options.Cookies = null;
|
options.Cookies = null;
|
||||||
options.SetRequestHeader("Origin", HttpApiClient.HttpHeaderOrigin);
|
options.SetRequestHeader("Origin", HttpApiClient.HttpHeaderOrigin);
|
||||||
options.SetRequestHeader("Accept-Language", HttpApiClient.HttpHeaderAcceptLanguage);
|
options.SetRequestHeader("Referer", HttpApiClient.HttpHeaderReferer);
|
||||||
options.SetRequestHeader("User-Agent", HttpApiClient.HttpHeaderUserAgent);
|
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)
|
public async Task<PipeReader> ConnectAsync(string host, int port, CancellationToken cancellationToken)
|
||||||
|
|
|
@ -558,16 +558,24 @@ retry:
|
||||||
|
|
||||||
private string? DanmakuClient_BeforeHandshake(string json)
|
private string? DanmakuClient_BeforeHandshake(string json)
|
||||||
{
|
{
|
||||||
if (this.RoomConfig.DanmakuAuthenticateWithStreamerUid)
|
var danmakuAuthenticateWithStreamerUid = this.RoomConfig.DanmakuAuthenticateWithStreamerUid;
|
||||||
|
if (danmakuAuthenticateWithStreamerUid)
|
||||||
{
|
{
|
||||||
var obj = JObject.Parse(json);
|
var obj = JObject.Parse(json);
|
||||||
obj["uid"] = this.Uid;
|
obj["uid"] = this.Uid;
|
||||||
// delete key and buvid
|
|
||||||
obj.Remove("key");
|
obj.Remove("key");
|
||||||
obj.Remove("buvid");
|
obj.Remove("buvid");
|
||||||
json = obj.ToString(Formatting.None);
|
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)
|
private void DanmakuClient_DanmakuReceived(object? sender, Api.Danmaku.DanmakuReceivedEventArgs e)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user