将framework版本 从4.8 降低到4.6.2;
修复控制台初始化隐藏有几率无效的BUG
This commit is contained in:
+16
-16
@@ -1,38 +1,38 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!--配置更改后重启才能生效-->
|
<!--配置更改后重启才能生效-->
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<!--过滤Websocket数据源进程,可用','进行分隔,程序将会监听以下进程的弹幕信息-->
|
<!--过滤Websocket数据源进程,可用','进行分隔,程序将会监听以下进程的弹幕信息-->
|
||||||
<add key="processFilter" value="直播伴侣,douyin,chrome,msedge,QQBrowser,360se,firefox,2345explorer,iexplore" />
|
<add key="processFilter" value="直播伴侣,douyin,chrome,msedge,QQBrowser,360se,firefox,2345explorer,iexplore"/>
|
||||||
<!--Websocket监听端口-->
|
<!--Websocket监听端口-->
|
||||||
<add key="wsListenPort" value="8888" />
|
<add key="wsListenPort" value="8888"/>
|
||||||
<!--true:监听在0.0.0.0,接受任意Ip连接,false:监听在127.0.0.1,仅接受本机连接-->
|
<!--true:监听在0.0.0.0,接受任意Ip连接,false:监听在127.0.0.1,仅接受本机连接-->
|
||||||
<add key="listenAny" value="true" />
|
<add key="listenAny" value="true"/>
|
||||||
<!--系统代理端口-->
|
<!--系统代理端口-->
|
||||||
<add key="proxyPort" value="8827" />
|
<add key="proxyPort" value="8827"/>
|
||||||
<!--上游代理地址,例如开启了系统代理,但是需要将其他无关请求转发到VPN工具中,例如:127.0.0.1:11223,不要带http://-->
|
<!--上游代理地址,例如开启了系统代理,但是需要将其他无关请求转发到VPN工具中,例如:127.0.0.1:11223,不要带http://-->
|
||||||
<add key="upstreamProxy" value=""/>
|
<add key="upstreamProxy" value=""/>
|
||||||
<!--在控制台输出弹幕-->
|
<!--在控制台输出弹幕-->
|
||||||
<add key="printBarrage" value="true" />
|
<add key="printBarrage" value="true"/>
|
||||||
<!--要在控制台打印的弹幕类型,可以用','隔开 all[全部],1[普通弹幕],2[点赞消息],3[进入直播间],4[关注消息],5[礼物消息],6[统计消息],7[粉丝团消息]-->
|
<!--要在控制台打印的弹幕类型,可以用','隔开 all[全部],1[普通弹幕],2[点赞消息],3[进入直播间],4[关注消息],5[礼物消息],6[统计消息],7[粉丝团消息]-->
|
||||||
<add key="printFilter" value="all" />
|
<add key="printFilter" value="all"/>
|
||||||
<!--是否启用系统代理,若设置为false 则需要在程序手动指定代理地址 -->
|
<!--是否启用系统代理,若设置为false 则需要在程序手动指定代理地址 -->
|
||||||
<add key="usedProxy" value="true" />
|
<add key="usedProxy" value="true"/>
|
||||||
<!--开启内置的域名过滤,设置为false会解包所有https请求,cpu占用很高,建议在无法获取弹幕数据时调整 -->
|
<!--开启内置的域名过滤,设置为false会解包所有https请求,cpu占用很高,建议在无法获取弹幕数据时调整 -->
|
||||||
<add key="filterHostName" value="true" />
|
<add key="filterHostName" value="true"/>
|
||||||
<!--已知的弹幕域名列表 ','分隔 用作过滤规则中,凡是webcast开头的域名程序都会自动列入白名单-->
|
<!--已知的弹幕域名列表 ','分隔 用作过滤规则中,凡是webcast开头的域名程序都会自动列入白名单-->
|
||||||
<add key="hostNameFilter" value="" />
|
<add key="hostNameFilter" value=""/>
|
||||||
<!--要进行过滤的房间ID,不填代表监听所有,多项使用','分隔,浏览器进入直播间 F12 控制台输入 'window.localStorage.playRoom' 即可快速看到房间ID(不是地址栏中的那个) -->
|
<!--要进行过滤的房间ID,不填代表监听所有,多项使用','分隔,浏览器进入直播间 F12 控制台输入 'window.localStorage.playRoom' 即可快速看到房间ID(不是地址栏中的那个) -->
|
||||||
<add key="roomIds" value="" />
|
<add key="roomIds" value=""/>
|
||||||
<!--隐藏控制台-->
|
<!--隐藏控制台-->
|
||||||
<add key="hideConsole" value="false" />
|
<add key="hideConsole" value="false"/>
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<runtime>
|
<runtime>
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2"/>
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
</configuration>
|
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
|
||||||
|
|||||||
@@ -37,6 +37,30 @@ namespace BarrageGrab
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 隐藏/显示 控制台
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="show"></param>
|
||||||
|
public static void DisplayConsole(bool show)
|
||||||
|
{
|
||||||
|
//var hWnd = WinApi.FindWindow(null, Console.Title);
|
||||||
|
var hWnd = WinApi.GetConsoleWindow();
|
||||||
|
if (hWnd != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
WinApi.ShowWindow(hWnd, show? WinApi.CmdShow.SW_SHOW:WinApi.CmdShow.SW_HIDE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DisplayConsoleByTitle(bool show)
|
||||||
|
{
|
||||||
|
var hWnd = WinApi.FindWindow(null, Console.Title);
|
||||||
|
//var hWnd = WinApi.GetConsoleWindow();
|
||||||
|
if (hWnd != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
WinApi.ShowWindow(hWnd, show ? WinApi.CmdShow.SW_SHOW : WinApi.CmdShow.SW_HIDE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 房间缓存管理器
|
/// 房间缓存管理器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -95,7 +119,8 @@ namespace BarrageGrab
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public long GetCachedWebRoomid(string roomid)
|
public long GetCachedWebRoomid(string roomid)
|
||||||
{
|
{
|
||||||
if (RoomInfoCache.TryGetValue(roomid, out var value)) return long.Parse(value.WebRoomId??"-1");
|
RoomInfo value;
|
||||||
|
if (RoomInfoCache.TryGetValue(roomid,out value)) return long.Parse(value.WebRoomId??"-1");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +131,8 @@ namespace BarrageGrab
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public RoomInfo GetCachedWebRoomInfo(string roomid)
|
public RoomInfo GetCachedWebRoomInfo(string roomid)
|
||||||
{
|
{
|
||||||
if (RoomInfoCache.TryGetValue(roomid, out var value)) return value;
|
RoomInfo value;
|
||||||
|
if (RoomInfoCache.TryGetValue(roomid, out value)) return value;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
private static readonly Appsetting ins = new Appsetting();
|
private static readonly Appsetting ins = new Appsetting();
|
||||||
|
|
||||||
public static Appsetting Current { get => ins; }
|
public static Appsetting Current { get { return ins; } }
|
||||||
|
|
||||||
public Appsetting()
|
public Appsetting()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -510,12 +510,12 @@ namespace BarrageGrab.Modles
|
|||||||
/// <param name="html"></param>
|
/// <param name="html"></param>
|
||||||
/// <param name="result"></param>
|
/// <param name="result"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static (int, string) TryParseRoomPageHtml(string html, out RoomInfo result)
|
public static Tuple<int,string> TryParseRoomPageHtml(string html, out RoomInfo result)
|
||||||
{
|
{
|
||||||
result = null;
|
result = null;
|
||||||
if (html.IsNullOrWhiteSpace())
|
if (html.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
return (-1, "无效的页面数据");
|
return Tuple.Create(-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*""0:)\[.+?\](?=\\n""?\]\)[\s\n\r]*?<\/script>)");
|
||||||
@@ -526,7 +526,7 @@ namespace BarrageGrab.Modles
|
|||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
{
|
{
|
||||||
//Logger.LogError("在通过正则匹配直播页房间信息时失败,可能是官方做了升级");
|
//Logger.LogError("在通过正则匹配直播页房间信息时失败,可能是官方做了升级");
|
||||||
return (1, "未能匹配到房间信息");
|
return Tuple.Create(1, "未能匹配到房间信息");
|
||||||
}
|
}
|
||||||
var matchData = Regex.Unescape(match.Value);
|
var matchData = Regex.Unescape(match.Value);
|
||||||
|
|
||||||
@@ -537,7 +537,7 @@ namespace BarrageGrab.Modles
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return (2, "匹配到的房间数据格式有错误");
|
return Tuple.Create(2, "匹配到的房间数据格式有错误");
|
||||||
}
|
}
|
||||||
//var root = jsonObject["children"][3];
|
//var root = jsonObject["children"][3];
|
||||||
//var roomInfo = root["initialState"]["roomStore"]["roomInfo"];
|
//var roomInfo = root["initialState"]["roomStore"]["roomInfo"];
|
||||||
@@ -552,7 +552,7 @@ namespace BarrageGrab.Modles
|
|||||||
|
|
||||||
if (room == null)
|
if (room == null)
|
||||||
{
|
{
|
||||||
return (3, "房间信息为空,获取失败");
|
return Tuple.Create(3, "房间信息为空,获取失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
result = new RoomInfo();
|
result = new RoomInfo();
|
||||||
@@ -579,7 +579,7 @@ namespace BarrageGrab.Modles
|
|||||||
FollowStatus = roomOwner["follow_info"]["follow_status"].Value<int>()
|
FollowStatus = roomOwner["follow_info"]["follow_status"].Value<int>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return (0, "succ");
|
return Tuple.Create(0, "succ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
return dic[key];
|
return dic[key];
|
||||||
}
|
}
|
||||||
return default;
|
return default(TValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+10
-10
@@ -23,18 +23,17 @@ namespace BarrageGrab
|
|||||||
WinApi.SetConsoleCtrlHandler(cancelHandler, true);//捕获控制台关闭
|
WinApi.SetConsoleCtrlHandler(cancelHandler, true);//捕获控制台关闭
|
||||||
WinApi.DisableQuickEditMode();//禁用控制台快速编辑模式
|
WinApi.DisableQuickEditMode();//禁用控制台快速编辑模式
|
||||||
Console.Title = "抖音弹幕监听推送";
|
Console.Title = "抖音弹幕监听推送";
|
||||||
|
AppRuntime.DisplayConsole(!Appsetting.Current.HideConsole);
|
||||||
if(Appsetting.Current.HideConsole)
|
|
||||||
{
|
|
||||||
var hWnd = WinApi.FindWindow(null, Console.Title);
|
|
||||||
if (hWnd != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
WinApi.ShowWindow(hWnd,WinApi.CmdShow.SW_HIDE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool exited = false;
|
bool exited = false;
|
||||||
AppRuntime.WssService.StartListen();
|
AppRuntime.WssService.StartListen();
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine($"{AppRuntime.WssService.ServerLocation} 弹幕服务已启动...");
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
Console.Title = $"抖音弹幕监听推送 [{AppRuntime.WssService.ServerLocation}]";
|
||||||
|
|
||||||
|
|
||||||
AppRuntime.WssService.OnClose += (s, e) =>
|
AppRuntime.WssService.OnClose += (s, e) =>
|
||||||
{
|
{
|
||||||
//退出程序
|
//退出程序
|
||||||
@@ -73,7 +72,8 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
const string mutexName = "DyBarrageGrab";
|
const string mutexName = "DyBarrageGrab";
|
||||||
// Try to create a new named mutex.
|
// Try to create a new named mutex.
|
||||||
using (Mutex mutex = new Mutex(true, mutexName, out bool createdNew))
|
bool createdNew;
|
||||||
|
using (Mutex mutex = new Mutex(true, mutexName, out createdNew))
|
||||||
{
|
{
|
||||||
return !createdNew;
|
return !createdNew;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace BarrageGrab.Proxy
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 代理端口
|
/// 代理端口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ProxyPort { get => Appsetting.Current.ProxyPort; }
|
public int ProxyPort { get { return Appsetting.Current.ProxyPort; } }
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
|
|||||||
@@ -173,8 +173,10 @@ namespace BarrageGrab.Proxy
|
|||||||
{
|
{
|
||||||
//利用 HtmlAgilityPack 在尾部注入script 标签
|
//利用 HtmlAgilityPack 在尾部注入script 标签
|
||||||
var html = await e.GetResponseBodyAsString();
|
var html = await e.GetResponseBodyAsString();
|
||||||
|
RoomInfo roominfo;
|
||||||
(int code, string msg) = RoomInfo.TryParseRoomPageHtml(html, out var roominfo);
|
var tup = RoomInfo.TryParseRoomPageHtml(html, out roominfo);
|
||||||
|
int code = tup.Item1;
|
||||||
|
string msg = tup.Item2;
|
||||||
|
|
||||||
if (code == 0)
|
if (code == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ namespace BarrageGrab
|
|||||||
[DllImport("User32.dll", EntryPoint = "ShowWindow")]
|
[DllImport("User32.dll", EntryPoint = "ShowWindow")]
|
||||||
public static extern bool ShowWindow(IntPtr hWnd, CmdShow nCmdShow);
|
public static extern bool ShowWindow(IntPtr hWnd, CmdShow nCmdShow);
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll")]
|
||||||
|
public static extern IntPtr GetConsoleWindow();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ namespace BarrageGrab
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler OnClose;
|
public event EventHandler OnClose;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WS服务器启动地址
|
||||||
|
/// </summary>
|
||||||
|
public string ServerLocation { get { return socketServer.Location; } }
|
||||||
|
|
||||||
public WsBarrageService()
|
public WsBarrageService()
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@@ -495,11 +500,7 @@ namespace BarrageGrab
|
|||||||
case CommandCode.DisplayConsole:
|
case CommandCode.DisplayConsole:
|
||||||
{
|
{
|
||||||
var display = (bool)cmdPack.Data;
|
var display = (bool)cmdPack.Data;
|
||||||
var hand = WinApi.FindWindow(null, Console.Title);
|
AppRuntime.DisplayConsole(display);
|
||||||
if (hand != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
WinApi.ShowWindow(hand, display ? WinApi.CmdShow.SW_SHOW : WinApi.CmdShow.SW_HIDE);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -551,8 +552,6 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
this.grab.Start(); //启动代理
|
this.grab.Start(); //启动代理
|
||||||
this.socketServer.Start(Listen);//启动监听
|
this.socketServer.Start(Listen);//启动监听
|
||||||
console.WriteLine($"{this.socketServer.Location} 弹幕服务已启动...", ConsoleColor.Green);
|
|
||||||
Console.Title = $"抖音弹幕监听推送 [{this.socketServer.Location}]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace BarrageGrab
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 代理
|
/// 代理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ISystemProxy Proxy { get => proxy; }
|
public ISystemProxy Proxy { get { return proxy; } }
|
||||||
|
|
||||||
public WssBarrageGrab()
|
public WssBarrageGrab()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>BarrageGrab</RootNamespace>
|
<RootNamespace>BarrageGrab</RootNamespace>
|
||||||
<AssemblyName>WssBarrageService</AssemblyName>
|
<AssemblyName>WssBarrageService</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<PublishUrl>publish\</PublishUrl>
|
<PublishUrl>publish\</PublishUrl>
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|||||||
Reference in New Issue
Block a user