From 1b747146f9ec5b4451c037dd71ae5664dbcb4b09 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=85=E6=B5=A9=E4=B8=9C?= <1083092844@qq.com>
Date: Mon, 14 Apr 2025 16:18:49 +0800
Subject: [PATCH] =?UTF-8?q?Scripts=E7=9B=AE=E5=BD=95=E4=B8=8D=E5=86=8D?=
=?UTF-8?q?=E5=BF=85=E8=A6=81=E5=AD=98=E5=9C=A8=EF=BC=8C=E5=B9=B6=E7=A7=BB?=
=?UTF-8?q?=E9=99=A4=20livePage.js;=20=E8=B0=83=E6=95=B4=E9=A1=B9=E7=9B=AE?=
=?UTF-8?q?=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BarrageGrab/App.config | 2 +-
BarrageGrab/AppSetting.cs | 2 +-
BarrageGrab/JsEngine.cs | 2 +-
BarrageGrab/Program.cs | 1 +
BarrageGrab/Proxy/TitaniumProxy.cs | 25 ++--------
BarrageGrab/Scripts/inject/livePage.js | 26 ----------
BarrageGrab/{ => Server}/ComPortServer.cs | 6 +++
BarrageGrab/{ => Server}/WsBarrageServer.cs | 25 +---------
BarrageGrab/{ => Server}/WssBarrageGrab.cs | 0
.../{DyServer.cs => Utility/DyApiHelper.cs} | 2 +-
BarrageGrab/Utility/EmbResource.cs | 50 +++++++++++++++++++
BarrageGrab/{ => Utility}/LiveCompanHelper.cs | 0
BarrageGrab/{ => Utility}/WinApi.cs | 2 -
BarrageGrab/WssBarrageService.csproj | 21 ++++----
README.md | 22 ++------
15 files changed, 80 insertions(+), 106 deletions(-)
rename BarrageGrab/{ => Server}/ComPortServer.cs (96%)
rename BarrageGrab/{ => Server}/WsBarrageServer.cs (96%)
rename BarrageGrab/{ => Server}/WssBarrageGrab.cs (100%)
rename BarrageGrab/{DyServer.cs => Utility/DyApiHelper.cs} (99%)
create mode 100644 BarrageGrab/Utility/EmbResource.cs
rename BarrageGrab/{ => Utility}/LiveCompanHelper.cs (100%)
rename BarrageGrab/{ => Utility}/WinApi.cs (98%)
diff --git a/BarrageGrab/App.config b/BarrageGrab/App.config
index b6dd7aa..d3c6973 100644
--- a/BarrageGrab/App.config
+++ b/BarrageGrab/App.config
@@ -11,7 +11,7 @@
-
+
diff --git a/BarrageGrab/AppSetting.cs b/BarrageGrab/AppSetting.cs
index 6f30b85..ab456c9 100644
--- a/BarrageGrab/AppSetting.cs
+++ b/BarrageGrab/AppSetting.cs
@@ -29,7 +29,7 @@ namespace BarrageGrab
LogFilter = Enum.GetValues(typeof(PackMsgType)).Cast().Where(w => w > 0).ToArray();
FilterHostName = bool.Parse(AppSettings["filterHostName"].Trim());
HostNameFilter = AppSettings["hostNameFilter"].Trim().Split(',').Where(w => !string.IsNullOrWhiteSpace(w)).ToArray();
- UsedProxy = bool.Parse(AppSettings["usedProxy"].Trim());
+ UsedProxy = bool.Parse(AppSettings["sysProxy"].Trim());
ListenAny = bool.Parse(AppSettings["listenAny"].Trim());
UpstreamProxy = AppSettings["upstreamProxy"].Trim();
HideConsole = bool.Parse(AppSettings["hideConsole"].Trim());
diff --git a/BarrageGrab/JsEngine.cs b/BarrageGrab/JsEngine.cs
index 1a90262..caa955a 100644
--- a/BarrageGrab/JsEngine.cs
+++ b/BarrageGrab/JsEngine.cs
@@ -53,7 +53,7 @@ namespace BarrageGrab
public static string GetJsFile(string fileName)
{
var path = Path.Combine(AppContext.BaseDirectory, "Scripts", "engine", fileName);
- if (!File.Exists(path)) throw new FileNotFoundException("不存在的文件", path);
+ if (!File.Exists(path)) return null;
return File.ReadAllText(path, Encoding.UTF8);
}
diff --git a/BarrageGrab/Program.cs b/BarrageGrab/Program.cs
index 3cca68f..38f8646 100644
--- a/BarrageGrab/Program.cs
+++ b/BarrageGrab/Program.cs
@@ -19,6 +19,7 @@ namespace BarrageGrab
static bool formExited = false;
static WinApi.ControlCtrlDelegate controlCtr = ControlCtrlHandle;
static Mutex mutex = new Mutex(false, "DyBarrageGrab");
+
static void Main(string[] args)
{
if (!mutex.WaitOne(TimeSpan.Zero, true))
diff --git a/BarrageGrab/Proxy/TitaniumProxy.cs b/BarrageGrab/Proxy/TitaniumProxy.cs
index dd2b1af..94ce500 100644
--- a/BarrageGrab/Proxy/TitaniumProxy.cs
+++ b/BarrageGrab/Proxy/TitaniumProxy.cs
@@ -308,7 +308,7 @@ namespace BarrageGrab.Proxy
{
lock (rinfoRequestings) rinfoRequestings.Add(webroomid);
//查询后会自动缓存
- DyServer.GetRoomInfoForApi(webroomid, cookie).ContinueWith(t =>
+ DyApiHelper.GetRoomInfoForApi(webroomid, cookie).ContinueWith(t =>
{
var rinfo = t.Result;
//限制只尝试一次
@@ -333,22 +333,6 @@ namespace BarrageGrab.Proxy
}
}
- ///
- /// 获取配置的注入的js
- ///
- ///
- ///
- private string GetInjectScript(string name)
- {
- //获取exe所在目录路径
- var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts", "inject", name + ".js");
- if (File.Exists(path))
- {
- return File.ReadAllText(path);
- }
- return null;
- }
-
// Hook 直播页面
private async Task HookPageAsync(SessionEventArgs e)
{
@@ -377,8 +361,7 @@ namespace BarrageGrab.Proxy
{
string webrid = liveRoomMactch.Groups[1].Value;
//获取直播页注入js
- string liveRoomInjectScript = GetInjectScript("livePage");
-
+ string liveRoomInjectScript = EmbResource.GetFileContent("livePage.js");
//注入上下文变量;
var scriptContext = BuildContext(new Dictionary()
{
@@ -435,7 +418,7 @@ namespace BarrageGrab.Proxy
script.InnerHtml = liveRoomInjectScript;
body.AppendChild(script);
html = doc.DocumentNode.OuterHtml;
- Logger.PrintColor($"直播页{urlNoQuery},用户脚本已成功注入!\n", ConsoleColor.Green);
+ Logger.LogTrace($"直播页{urlNoQuery},用户脚本已成功注入!\n");
}
}
catch (Exception ex)
@@ -459,7 +442,7 @@ namespace BarrageGrab.Proxy
if (liveHomeMatch.Success)
{
//获取直播页注入js
- string liveHoomInjectScript = GetInjectScript("livePage");
+ string liveHoomInjectScript = EmbResource.GetFileContent("livePage.js");
//注入上下文变量;
var scriptContext = BuildContext(new Dictionary()
diff --git a/BarrageGrab/Scripts/inject/livePage.js b/BarrageGrab/Scripts/inject/livePage.js
index 0f0220d..1192a18 100644
--- a/BarrageGrab/Scripts/inject/livePage.js
+++ b/BarrageGrab/Scripts/inject/livePage.js
@@ -6,35 +6,9 @@
* 正则: @".*:\/\/live.douyin\.com\/\d+"
**/
-/*注入脚本 定时触发全局keydown,避免直播流被无操作阻断*/
-
-// 创建一个虚拟的按键事件
-const simulatedEvent = new KeyboardEvent('keydown', {
- key: 'Virtual_Alt',
- keyCode: 18, //alt
- bubbles: true,
- cancelable: true
-});
-
-// 获取要分派事件的目标元素,例如文档的根元素
-const targetElement = document.documentElement;
-
-// 设置定时器,每隔60秒模拟一次按键事件
-setInterval(() => {
- targetElement.dispatchEvent(simulatedEvent);
-}, 1000 * 60);
-
-// 订阅 keydown 事件 (Debug)
-targetElement.addEventListener('keydown', event => {
- if (event.key == "Virtual_Alt") {
- console.log('[防挂机处理] 按下了', event.key);
- }
-});
-
/*禁止关闭 Websocket*/
WebSocket.prototype.close = function () { return; }
-
/*判断是否自动关闭 */
//获取路由参数
function getQueryString(name) {
diff --git a/BarrageGrab/ComPortServer.cs b/BarrageGrab/Server/ComPortServer.cs
similarity index 96%
rename from BarrageGrab/ComPortServer.cs
rename to BarrageGrab/Server/ComPortServer.cs
index f690094..bf9ea2a 100644
--- a/BarrageGrab/ComPortServer.cs
+++ b/BarrageGrab/Server/ComPortServer.cs
@@ -25,7 +25,13 @@ namespace BarrageGrab
if (AppSetting.Current.UseComPortFilter)
{
jsEngine = JsEngine.CreateNewEngine();
+
var jsFile = JsEngine.GetJsFile("comPortFilter.js");
+ if (jsFile.IsNullOrWhiteSpace())
+ {
+ jsFile = EmbResource.GetFileContent("comPortFilter.js");
+ }
+
try
{
jsEngine.Execute(jsFile);
diff --git a/BarrageGrab/WsBarrageServer.cs b/BarrageGrab/Server/WsBarrageServer.cs
similarity index 96%
rename from BarrageGrab/WsBarrageServer.cs
rename to BarrageGrab/Server/WsBarrageServer.cs
index c8731ba..bf6e502 100644
--- a/BarrageGrab/WsBarrageServer.cs
+++ b/BarrageGrab/Server/WsBarrageServer.cs
@@ -176,6 +176,7 @@ namespace BarrageGrab
return obj.GetType().GetProperty(propertyName) != null;
}
+ //创建消息对象
private T CreateMsg(dynamic msg) where T : Msg, new()
{
var roomid = msg.Common.roomId.ToString();
@@ -580,29 +581,7 @@ namespace BarrageGrab
try
{
var cmdPack = JsonConvert.DeserializeObject(message);
- if (cmdPack == null) return;
-
- switch (cmdPack.Cmd)
- {
- case CommandCode.Close:
- this.Dispose();
- break;
- case CommandCode.EnableProxy:
- {
- var enable = (bool)cmdPack.Data;
- if (enable)
- this.grab.Proxy.RegisterSystemProxy();
- else
- this.grab.Proxy.CloseSystemProxy();
- break;
- }
- case CommandCode.DisplayConsole:
- {
- var display = (bool)cmdPack.Data;
- AppRuntime.DisplayConsole(display);
- break;
- }
- }
+ if (cmdPack == null) return;
}
catch (Exception) { }
};
diff --git a/BarrageGrab/WssBarrageGrab.cs b/BarrageGrab/Server/WssBarrageGrab.cs
similarity index 100%
rename from BarrageGrab/WssBarrageGrab.cs
rename to BarrageGrab/Server/WssBarrageGrab.cs
diff --git a/BarrageGrab/DyServer.cs b/BarrageGrab/Utility/DyApiHelper.cs
similarity index 99%
rename from BarrageGrab/DyServer.cs
rename to BarrageGrab/Utility/DyApiHelper.cs
index 6a2e732..af96ddb 100644
--- a/BarrageGrab/DyServer.cs
+++ b/BarrageGrab/Utility/DyApiHelper.cs
@@ -15,7 +15,7 @@ namespace BarrageGrab
///
/// 抖音服务
///
- internal class DyServer
+ internal class DyApiHelper
{
///
/// 获取直播礼物列表
diff --git a/BarrageGrab/Utility/EmbResource.cs b/BarrageGrab/Utility/EmbResource.cs
new file mode 100644
index 0000000..5832abc
--- /dev/null
+++ b/BarrageGrab/Utility/EmbResource.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BarrageGrab
+{
+ ///
+ /// 资源文件
+ ///
+ public static class EmbResource
+ {
+ static Dictionary cache = new Dictionary();
+
+ ///
+ /// 获取 嵌入式资源文件内容
+ ///
+ ///
+ ///
+ ///
+ public static string GetFileContent(string fileName)
+ {
+ if(cache.ContainsKey(fileName))
+ {
+ return cache[fileName];
+ }
+
+ Assembly assembly = Assembly.GetExecutingAssembly();
+ //读取嵌入式资源文件
+ var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(s => s.EndsWith(fileName));
+ if (resourceName == null)
+ {
+ throw new Exception($"{fileName} 嵌入式资源不存在");
+ }
+
+ using (Stream stream = assembly.GetManifestResourceStream(resourceName))
+ {
+ using (StreamReader reader = new StreamReader(stream,Encoding.UTF8))
+ {
+ var text = reader.ReadToEnd();
+ cache.Add(fileName, text);
+ return text;
+ }
+ }
+ }
+ }
+}
diff --git a/BarrageGrab/LiveCompanHelper.cs b/BarrageGrab/Utility/LiveCompanHelper.cs
similarity index 100%
rename from BarrageGrab/LiveCompanHelper.cs
rename to BarrageGrab/Utility/LiveCompanHelper.cs
diff --git a/BarrageGrab/WinApi.cs b/BarrageGrab/Utility/WinApi.cs
similarity index 98%
rename from BarrageGrab/WinApi.cs
rename to BarrageGrab/Utility/WinApi.cs
index 927dad2..0cb42f0 100644
--- a/BarrageGrab/WinApi.cs
+++ b/BarrageGrab/Utility/WinApi.cs
@@ -28,8 +28,6 @@ namespace BarrageGrab
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
-
- ///If the function fails, the return value is NULL.
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
diff --git a/BarrageGrab/WssBarrageService.csproj b/BarrageGrab/WssBarrageService.csproj
index 04b9793..734a80d 100644
--- a/BarrageGrab/WssBarrageService.csproj
+++ b/BarrageGrab/WssBarrageService.csproj
@@ -218,8 +218,9 @@
-
-
+
+
+
Form
@@ -234,7 +235,7 @@
RoomDetail.cs
-
+
@@ -251,10 +252,10 @@
-
-
+
+
-
+
@@ -266,12 +267,8 @@
-
- PreserveNewest
-
-
- Always
-
+
+
diff --git a/README.md b/README.md
index ecccdf3..0c76046 100644
--- a/README.md
+++ b/README.md
@@ -16,8 +16,12 @@
+ 如果好用,请捐赠个仨瓜俩枣,白某谢过各位老板
## ⛳近期更新
+2025-04-14 v2.7.9
+1. **[重要优化]** 大幅降低了程序包的体积
+2. `nlog.config` 改为内嵌
2025-04-09 v2.7.8
+
1. 修复页面无操作检测拦截失效的问题,因为更新了脚本
2. 修复弹幕日志因主播昵称的特殊字符导致无法写入的问题
@@ -58,24 +62,6 @@
2. **[破坏性更新]** `WebRoomid` 和 `Roomid` 改为String类型
3. 之前直播伴侣开播会导致`WebRoomid`为-1,现会抓取直播伴侣开播响应信息,并填充`WebRoomid`,但直播伴侣的`WebRoomid`设定为主播**抖音号**,需要根据进程名做判断,使用请注意
-2024-03-10 v2.7.2
-
-1. [**重要更新**] 支持设置为轮询模式监听(见配置项**forcePolling**,直播伴侣尚未支持),比起ws更稳定,适合长时间监听
-2. 支持进入直播间画面自动暂停
-3. 优化礼物连击判定规则,可区分出可连击的礼物,进一步避免礼物数量推送不准确的问题,并新增字段:
- 1. Combo 礼物是否可连击
- 2. ImgUrl 礼物图像地址
- 3. ToUser 送礼目标
-4. roomId过滤改为 WebRoomid 过滤(仅支持已经被缓存的直播间,对直播伴侣可能无效)
-5. 添加“关闭代理.bat” 批处理脚本,见根目录或者上方文件,便于无法上网时双击执行
-6. 更多介绍请查看底下新增配置项
-
-2023-11-23 v2.7.0
-
-1. 修复了因抖音版本升级导致的WebRoomId获取不到的问题,并更近了正则表达式尽量兼容后续的变更
-2. 添加了winfrom窗体,功能有限,默认隐藏
-3. 支持了控制台隐藏,推送器弹幕类型过滤,日志弹幕类型过滤,弹幕文件日志 (见配置文件)
-4. 支持了更多的ws命令,见 [Command.cs](./BarrageGrab/Modles/JsonEntity/Command.cs)
## 🖼️控制台截图