From 5c2248048a9fd4a41bb41c08cf4d722356a7e648 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E7=8C=BF?= <1083092844@qq.com>
Date: Sat, 4 Nov 2023 21:30:37 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E8=A1=A5=E5=9B=A0=E6=8A=96=E9=9F=B3?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AF=BC=E8=87=B4webroomid=20=E8=8E=B7?=
=?UTF-8?q?=E5=8F=96=E4=B8=8D=E5=88=B0=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BarrageGrab/AppRuntime.cs | 2 +-
BarrageGrab/Modles/RoomInfo.cs | 11 ++++++++++-
BarrageGrab/Proxy/TitaniumProxy.cs | 29 ++++++++++++++++++++++++-----
3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/BarrageGrab/AppRuntime.cs b/BarrageGrab/AppRuntime.cs
index 1af34e8..b53ede1 100644
--- a/BarrageGrab/AppRuntime.cs
+++ b/BarrageGrab/AppRuntime.cs
@@ -95,7 +95,7 @@ namespace BarrageGrab
///
public long GetCachedWebRoomid(string roomid)
{
- if (RoomInfoCache.TryGetValue(roomid, out var value)) return long.Parse(value.WebRoomId);
+ if (RoomInfoCache.TryGetValue(roomid, out var value)) return long.Parse(value.WebRoomId??"-1");
return -1;
}
diff --git a/BarrageGrab/Modles/RoomInfo.cs b/BarrageGrab/Modles/RoomInfo.cs
index 2005309..b4301db 100644
--- a/BarrageGrab/Modles/RoomInfo.cs
+++ b/BarrageGrab/Modles/RoomInfo.cs
@@ -517,7 +517,11 @@ namespace BarrageGrab.Modles
{
return (-1, "无效的页面数据");
}
- var roomDataReg = new Regex(@"(?<=self\.__pace_f\.push\(\[1,""a:)\[.+?\](?=\\n?""\]\)[\s\n\r]*?<\/script>)");
+ //var roomDataReg = new Regex(@"(?<=self\.__pace_f\.push\(\[1,""a:)\[.+?\](?=\\n?""\]\)[\s\n\r]*?<\/script>)");
+ //var roomDataReg = new Regex(@"(?<=self\.__pace_f\.push\(\[1,\s*""0:)\[.+?\](?=\\n""?\]\)[\s\n\r]*?<\/script>)");
+ var roomDataReg = new Regex(@"(?<=self\.__pace_f\.push\(\[1,\s*""9:)\[.+?\](?=\\n""?\]\)[\s\n\r]*?<\/script>)");
+ //字符串转义符号版本
+
var match = roomDataReg.Match(html);
if (!match.Success)
{
@@ -535,6 +539,11 @@ namespace BarrageGrab.Modles
{
return (2, "匹配到的房间数据格式有错误");
}
+ //var root = jsonObject["children"][3];
+ //var roomInfo = root["initialState"]["roomStore"]["roomInfo"];
+ //var odin = root["initialState"]["userStore"]["odin"];
+ //var room = roomInfo["room"];
+ //var roomOwner = roomInfo["anchor"];
var roomInfo = jsonObject["state"]["roomStore"]["roomInfo"];
var odin = jsonObject["state"]["userStore"]["odin"];
diff --git a/BarrageGrab/Proxy/TitaniumProxy.cs b/BarrageGrab/Proxy/TitaniumProxy.cs
index 6fe956c..d56234c 100644
--- a/BarrageGrab/Proxy/TitaniumProxy.cs
+++ b/BarrageGrab/Proxy/TitaniumProxy.cs
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using BarrageGrab.Modles;
using BarrageGrab.Proxy.ProxyEventArgs;
using ColorConsole;
+using Org.BouncyCastle.Ocsp;
using Titanium.Web.Proxy;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Http;
@@ -77,7 +78,7 @@ namespace BarrageGrab.Proxy
string uri = e.HttpClient.Request.RequestUri.ToString();
string hostname = e.HttpClient.Request.RequestUri.Host;
var processid = e.HttpClient.ProcessId.Value;
- var processName = base.GetProcessName(processid);
+ var processName = base.GetProcessName(processid);
var contentType = e.HttpClient.Response.ContentType ?? "";
//处理弹幕
@@ -89,7 +90,7 @@ namespace BarrageGrab.Proxy
//处理脚本拦截修改
await HookScriptAsync(e);
}
-
+
private async Task HookBarrage(SessionEventArgs e)
{
string uri = e.HttpClient.Request.RequestUri.ToString();
@@ -140,7 +141,7 @@ namespace BarrageGrab.Proxy
{
string uri = e.HttpClient.Request.RequestUri.ToString();
string hostname = e.HttpClient.Request.RequestUri.Host;
- string url = e.HttpClient.Request.Url;
+ string url = e.HttpClient.Request.Url;
var urlNoQuery = url.Split('?')[0];
var processid = e.HttpClient.ProcessId.Value;
var processName = base.GetProcessName(processid);
@@ -174,6 +175,7 @@ namespace BarrageGrab.Proxy
var html = await e.GetResponseBodyAsString();
(int code, string msg) = RoomInfo.TryParseRoomPageHtml(html, out var roominfo);
+
if (code == 0)
{
Logger.LogInfo($"直播页{webrid}房间信息已采集到缓存");
@@ -181,7 +183,24 @@ namespace BarrageGrab.Proxy
roominfo.LiveUrl = url;
AppRuntime.RoomCaches.AddRoomInfoCache(roominfo);
}
-
+ else
+ {
+ roominfo = new RoomInfo();
+ roominfo.WebRoomId = webrid;
+ roominfo.LiveUrl = url;
+ //正则匹配主播标题
+ //
和平精英小夜y
+ var match = Regex.Match(html, @"(?<=live-room-nickname""\>).+(?=<\/div>)");
+ if (match.Success)
+ {
+ roominfo.Owner = new RoomInfo.RoomAnchor()
+ {
+ Nickname = match.Value,
+ UserId = "-1"
+ };
+ }
+ AppRuntime.RoomCaches.AddRoomInfoCache(roominfo);
+ }
try
{
var doc = new HtmlAgilityPack.HtmlDocument();
@@ -242,7 +261,7 @@ namespace BarrageGrab.Proxy
}
}
}
-
+
private Task ProxyServer_ServerCertificateValidationCallback(object sender, CertificateValidationEventArgs e)
{
// set IsValid to true/false based on Certificate Errors