From 873608f53474100462f06cf43b4c97e8a6745380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=85=E6=B5=A9=E4=B8=9C?= <1083092844@qq.com> Date: Thu, 23 Nov 2023 16:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=AA=97=E4=BD=93=E9=80=BB?= =?UTF-8?q?=E8=BE=91;=20=E6=B7=BB=E5=8A=A0=E5=BC=B9=E5=B9=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97;=20=E4=BF=AE=E5=A4=8D=E6=88=BF=E9=97=B4=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=8E=B7=E5=8F=96=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BarrageGrab/App.config | 16 +- BarrageGrab/AppRuntime.cs | 47 ++- BarrageGrab/Appsetting.cs | 90 +++- BarrageGrab/FormView.Designer.cs | 394 ------------------ BarrageGrab/FormView.cs | 20 - BarrageGrab/Forms/FormView.Designer.cs | 373 +++++++++++++++++ BarrageGrab/Forms/FormView.cs | 238 +++++++++++ BarrageGrab/{ => Forms}/FormView.resx | 0 BarrageGrab/Forms/Models/RoomCacheItem.cs | 27 ++ BarrageGrab/Forms/RoomDetail.Designer.cs | 80 ++++ BarrageGrab/Forms/RoomDetail.cs | 41 ++ BarrageGrab/Forms/RoomDetail.resx | 120 ++++++ BarrageGrab/Logger.cs | 61 ++- .../Modles/JsonEntity/BarrageMessages.cs | 16 +- BarrageGrab/Modles/RoomInfo.cs | 7 +- BarrageGrab/Program.cs | 36 +- BarrageGrab/Proxy/ISystemProxy.cs | 17 + .../HttpResponseEventArgs.cs | 0 .../SystemProxyChangeEventArgs.cs | 16 + .../WsMessageEventArgs.cs | 0 BarrageGrab/Proxy/SystemProxy.cs | 42 +- BarrageGrab/Proxy/TitaniumProxy.cs | 35 +- BarrageGrab/WsBarrageService.cs | 60 ++- BarrageGrab/WssBarrageGrab.cs | 2 +- BarrageGrab/WssBarrageService.csproj | 21 +- 25 files changed, 1278 insertions(+), 481 deletions(-) delete mode 100644 BarrageGrab/FormView.Designer.cs delete mode 100644 BarrageGrab/FormView.cs create mode 100644 BarrageGrab/Forms/FormView.Designer.cs create mode 100644 BarrageGrab/Forms/FormView.cs rename BarrageGrab/{ => Forms}/FormView.resx (100%) create mode 100644 BarrageGrab/Forms/Models/RoomCacheItem.cs create mode 100644 BarrageGrab/Forms/RoomDetail.Designer.cs create mode 100644 BarrageGrab/Forms/RoomDetail.cs create mode 100644 BarrageGrab/Forms/RoomDetail.resx rename BarrageGrab/Proxy/{EventArgs => ProxyEventArgs}/HttpResponseEventArgs.cs (100%) create mode 100644 BarrageGrab/Proxy/ProxyEventArgs/SystemProxyChangeEventArgs.cs rename BarrageGrab/Proxy/{EventArgs => ProxyEventArgs}/WsMessageEventArgs.cs (100%) diff --git a/BarrageGrab/App.config b/BarrageGrab/App.config index 6a5a82d..39861f2 100644 --- a/BarrageGrab/App.config +++ b/BarrageGrab/App.config @@ -10,12 +10,16 @@ - - + + - - + + + + + + @@ -26,6 +30,10 @@ + + + + diff --git a/BarrageGrab/AppRuntime.cs b/BarrageGrab/AppRuntime.cs index 7d51e9e..e95b06a 100644 --- a/BarrageGrab/AppRuntime.cs +++ b/BarrageGrab/AppRuntime.cs @@ -71,6 +71,11 @@ namespace BarrageGrab /// public ConcurrentDictionary RoomInfoCache { get; } = new ConcurrentDictionary(); + /// + /// 添加房间缓存时触发 + /// + public event EventHandler OnCache; + /// /// 添加WebRoomid-房间ID 映射 /// @@ -84,12 +89,21 @@ namespace BarrageGrab } else { - RoomInfoCache.TryAdd(roomid, new RoomInfo() + var info = new RoomInfo() { RoomId = roomid, WebRoomId = webrid, Title = "房间" + webrid - }); + }; + var succ = RoomInfoCache.TryAdd(roomid,info); + if (succ) + { + OnCache?.Invoke(this, new RoomCacheEventArgs() + { + Model = 0, + RoomInfo = info + }); + } } } @@ -105,10 +119,23 @@ namespace BarrageGrab if (RoomInfoCache.ContainsKey(roomid)) { RoomInfoCache[roomid] = roomInfo; + OnCache?.Invoke(this, new RoomCacheEventArgs() + { + Model = 1, + RoomInfo = roomInfo + }); } else { - RoomInfoCache.TryAdd(roomid, roomInfo); + var succ = RoomInfoCache.TryAdd(roomid, roomInfo); + if (succ) + { + OnCache?.Invoke(this,new RoomCacheEventArgs() + { + Model = 0, + RoomInfo = roomInfo + }); + } } } @@ -135,7 +162,17 @@ namespace BarrageGrab if (RoomInfoCache.TryGetValue(roomid, out value)) return value; return null; } - } - } + + public class RoomCacheEventArgs : EventArgs + { + public RoomInfo RoomInfo { get; set; } + + /// + /// 0:添加,1更新,2删除 + /// + public int Model { get; set; } + } + } + } } diff --git a/BarrageGrab/Appsetting.cs b/BarrageGrab/Appsetting.cs index 9aaed9b..6992f45 100644 --- a/BarrageGrab/Appsetting.cs +++ b/BarrageGrab/Appsetting.cs @@ -6,6 +6,8 @@ using System.Text; using System.Threading.Tasks; using BarrageGrab.Modles.JsonEntity; using static System.Configuration.ConfigurationManager; +using System.Drawing; + namespace BarrageGrab { internal class Appsetting @@ -22,21 +24,37 @@ namespace BarrageGrab WsProt = int.Parse(AppSettings["wsListenPort"]); PrintBarrage = AppSettings["printBarrage"].ToLower() == "true"; ProxyPort = int.Parse(AppSettings["proxyPort"]); - PrintFilter = Enum.GetValues(typeof(PackMsgType)).Cast().ToArray(); + PrintFilter = Enum.GetValues(typeof(PackMsgType)).Cast().Where(w=>w>0).ToArray(); + PushFilter = Enum.GetValues(typeof(PackMsgType)).Cast().Where(w => w > 0).ToArray(); + 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(); RoomIds = AppSettings["roomIds"].Trim().Split(',').Where(w => !string.IsNullOrWhiteSpace(w)).Select(s => long.Parse(s)).ToArray(); - UsedProxy = bool.Parse(AppSettings["usedProxy"].Trim()); + UsedProxy = bool.Parse(AppSettings["usedProxy"].Trim()); ListenAny = bool.Parse(AppSettings["listenAny"].Trim()); UpstreamProxy = AppSettings["upstreamProxy"].Trim(); HideConsole = bool.Parse(AppSettings["hideConsole"].Trim()); + BarrageLog = bool.Parse(AppSettings["barrageFileLog"].Trim()); + ShowWindow = bool.Parse(AppSettings["showWindow"].Trim()); var printFilter = AppSettings["printFilter"].Trim().ToLower(); - if (printFilter != "all") + var pushFilter = AppSettings["pushFilter"].Trim().ToLower(); + var logFilter = AppSettings["logFilter"].Trim().ToLower(); + if (!string.IsNullOrWhiteSpace(printFilter)) { if (string.IsNullOrWhiteSpace(printFilter)) PrintFilter = new int[0]; else PrintFilter = printFilter.Split(',').Select(x => int.Parse(x)).ToArray(); } + if (!string.IsNullOrWhiteSpace(pushFilter)) + { + if (string.IsNullOrWhiteSpace(pushFilter)) PushFilter = new int[0]; + else PushFilter = pushFilter.Split(',').Select(x => int.Parse(x)).ToArray(); + } + if (!string.IsNullOrWhiteSpace(logFilter)) + { + if (string.IsNullOrWhiteSpace(logFilter)) LogFilter = new int[0]; + else LogFilter = logFilter.Split(',').Select(x => int.Parse(x)).ToArray(); + } } catch (Exception ex) { @@ -45,6 +63,40 @@ namespace BarrageGrab } } + public void Save() + { + Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + + config.AppSettings.Settings["wsListenPort"].Value = WsProt.ToString(); + config.AppSettings.Settings["printBarrage"].Value = PrintBarrage.ToString().ToLower(); + config.AppSettings.Settings["printFilter"].Value = string.Join("", PrintFilter); + config.AppSettings.Settings["pushFilter"].Value = string.Join("", PushFilter); + config.AppSettings.Settings["logFilter"].Value = string.Join("", LogFilter); + config.AppSettings.Settings["upstreamProxy"].Value = UpstreamProxy; + config.AppSettings.Settings["listenAny"].Value = ListenAny.ToString().ToLower(); + config.AppSettings.Settings["hideConsole"].Value = HideConsole.ToString().ToLower(); + config.AppSettings.Settings["barrageFileLog"].Value = HideConsole.ToString().ToLower(); + + config.Save(ConfigurationSaveMode.Modified); + ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name); + } + + /// + /// 弹幕颜色映射 + /// + public Dictionary> ColorMap = new Dictionary>() + { + { PackMsgType.弹幕消息, Tuple.Create(ConsoleColor.White, Color.White) }, + { PackMsgType.点赞消息, Tuple.Create(ConsoleColor.Cyan, Color.Cyan) }, + { PackMsgType.进直播间, Tuple.Create(ConsoleColor.Green, Color.Green) }, + { PackMsgType.关注消息, Tuple.Create(ConsoleColor.Yellow, Color.Yellow) }, + { PackMsgType.礼物消息, Tuple.Create(ConsoleColor.Red, Color.Red) }, + { PackMsgType.直播间统计, Tuple.Create(ConsoleColor.Magenta, Color.Magenta) }, + { PackMsgType.粉丝团消息, Tuple.Create(ConsoleColor.Blue, Color.Blue) }, + { PackMsgType.直播间分享, Tuple.Create(ConsoleColor.DarkBlue, Color.DarkBlue) }, + { PackMsgType.下播, Tuple.Create(ConsoleColor.DarkCyan, Color.DarkCyan) } + }; + /// /// 使用系统代理 /// @@ -58,17 +110,17 @@ namespace BarrageGrab /// /// 端口号 /// - public int WsProt { get; private set; } = 8888; + public int WsProt { get; set; } = 8888; /// /// true:监听在0.0.0.0,接受任意Ip连接,false:监听在127.0.0.1,仅接受本机连接 /// - public bool ListenAny { get; private set; } = true; + public bool ListenAny { get; set; } = true; /// /// 控制台打印消息开关 /// - public bool PrintBarrage { get; private set; } + public bool PrintBarrage { get; set; } /// /// 代理端口 @@ -78,7 +130,17 @@ namespace BarrageGrab /// /// 控制台输出过滤器 /// - public int[] PrintFilter { get; private set; } + public int[] PrintFilter { get; set; } + + /// + /// 推送弹幕过滤器 + /// + public int[] PushFilter { get; set; } + + /// + /// 弹幕日志过滤器 + /// + public int[] LogFilter { get; set; } /// /// 监听的房间号 @@ -98,11 +160,21 @@ namespace BarrageGrab /// /// 上游代理地址 /// - public string UpstreamProxy { get; private set; } + public string UpstreamProxy { get; set; } /// /// 隐藏控制台 /// - public bool HideConsole { get; private set; } + public bool HideConsole { get; set; } + + /// + /// 弹幕日志 + /// + public bool BarrageLog { get; set; } = false; + + /// + /// 显示窗体 + /// + public bool ShowWindow { get; private set; } = false; } } diff --git a/BarrageGrab/FormView.Designer.cs b/BarrageGrab/FormView.Designer.cs deleted file mode 100644 index 131d23c..0000000 --- a/BarrageGrab/FormView.Designer.cs +++ /dev/null @@ -1,394 +0,0 @@ -namespace BarrageGrab -{ - partial class FormView - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.richTextBox1 = new System.Windows.Forms.RichTextBox(); - this.cbx_bgtype_1 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_5 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_2 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_3 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_4 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_6 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_7 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_8 = new System.Windows.Forms.CheckBox(); - this.cbx_bgtype_9 = new System.Windows.Forms.CheckBox(); - this.label2 = new System.Windows.Forms.Label(); - this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); - this.panel1 = new System.Windows.Forms.Panel(); - this.label1 = new System.Windows.Forms.Label(); - this.listBox1 = new System.Windows.Forms.ListBox(); - this.cbx_enableProxy = new System.Windows.Forms.CheckBox(); - this.label3 = new System.Windows.Forms.Label(); - this.panel2 = new System.Windows.Forms.Panel(); - this.panel3 = new System.Windows.Forms.Panel(); - this.label5 = new System.Windows.Forms.Label(); - this.nud_wsport = new System.Windows.Forms.NumericUpDown(); - this.cbx_loopback = new System.Windows.Forms.CheckBox(); - this.label4 = new System.Windows.Forms.Label(); - this.txb_upstreamProxy = new System.Windows.Forms.TextBox(); - this.cbx_barrageLog = new System.Windows.Forms.CheckBox(); - this.flowLayoutPanel1.SuspendLayout(); - this.panel1.SuspendLayout(); - this.panel2.SuspendLayout(); - this.panel3.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud_wsport)).BeginInit(); - this.SuspendLayout(); - // - // richTextBox1 - // - this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.richTextBox1.Location = new System.Drawing.Point(15, 0); - this.richTextBox1.Name = "richTextBox1"; - this.richTextBox1.Size = new System.Drawing.Size(715, 260); - this.richTextBox1.TabIndex = 0; - this.richTextBox1.Text = ""; - // - // cbx_bgtype_1 - // - this.cbx_bgtype_1.AutoSize = true; - this.cbx_bgtype_1.Location = new System.Drawing.Point(3, 13); - this.cbx_bgtype_1.Name = "cbx_bgtype_1"; - this.cbx_bgtype_1.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_1.TabIndex = 0; - this.cbx_bgtype_1.Text = "消息"; - this.cbx_bgtype_1.UseVisualStyleBackColor = true; - // - // cbx_bgtype_5 - // - this.cbx_bgtype_5.AutoSize = true; - this.cbx_bgtype_5.Location = new System.Drawing.Point(3, 38); - this.cbx_bgtype_5.Name = "cbx_bgtype_5"; - this.cbx_bgtype_5.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_5.TabIndex = 1; - this.cbx_bgtype_5.Text = "礼物"; - this.cbx_bgtype_5.UseVisualStyleBackColor = true; - // - // cbx_bgtype_2 - // - this.cbx_bgtype_2.AutoSize = true; - this.cbx_bgtype_2.Location = new System.Drawing.Point(3, 63); - this.cbx_bgtype_2.Name = "cbx_bgtype_2"; - this.cbx_bgtype_2.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_2.TabIndex = 2; - this.cbx_bgtype_2.Text = "点赞"; - this.cbx_bgtype_2.UseVisualStyleBackColor = true; - // - // cbx_bgtype_3 - // - this.cbx_bgtype_3.AutoSize = true; - this.cbx_bgtype_3.Location = new System.Drawing.Point(3, 88); - this.cbx_bgtype_3.Name = "cbx_bgtype_3"; - this.cbx_bgtype_3.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_3.TabIndex = 3; - this.cbx_bgtype_3.Text = "进房"; - this.cbx_bgtype_3.UseVisualStyleBackColor = true; - // - // cbx_bgtype_4 - // - this.cbx_bgtype_4.AutoSize = true; - this.cbx_bgtype_4.Location = new System.Drawing.Point(3, 113); - this.cbx_bgtype_4.Name = "cbx_bgtype_4"; - this.cbx_bgtype_4.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_4.TabIndex = 4; - this.cbx_bgtype_4.Text = "关注"; - this.cbx_bgtype_4.UseVisualStyleBackColor = true; - // - // cbx_bgtype_6 - // - this.cbx_bgtype_6.AutoSize = true; - this.cbx_bgtype_6.Location = new System.Drawing.Point(3, 138); - this.cbx_bgtype_6.Name = "cbx_bgtype_6"; - this.cbx_bgtype_6.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_6.TabIndex = 5; - this.cbx_bgtype_6.Text = "统计"; - this.cbx_bgtype_6.UseVisualStyleBackColor = true; - // - // cbx_bgtype_7 - // - this.cbx_bgtype_7.AutoSize = true; - this.cbx_bgtype_7.Location = new System.Drawing.Point(3, 163); - this.cbx_bgtype_7.Name = "cbx_bgtype_7"; - this.cbx_bgtype_7.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_7.TabIndex = 6; - this.cbx_bgtype_7.Text = "粉团"; - this.cbx_bgtype_7.UseVisualStyleBackColor = true; - // - // cbx_bgtype_8 - // - this.cbx_bgtype_8.AutoSize = true; - this.cbx_bgtype_8.Location = new System.Drawing.Point(3, 188); - this.cbx_bgtype_8.Name = "cbx_bgtype_8"; - this.cbx_bgtype_8.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_8.TabIndex = 7; - this.cbx_bgtype_8.Text = "分享"; - this.cbx_bgtype_8.UseVisualStyleBackColor = true; - // - // cbx_bgtype_9 - // - this.cbx_bgtype_9.AutoSize = true; - this.cbx_bgtype_9.Location = new System.Drawing.Point(3, 213); - this.cbx_bgtype_9.Name = "cbx_bgtype_9"; - this.cbx_bgtype_9.Size = new System.Drawing.Size(59, 19); - this.cbx_bgtype_9.TabIndex = 8; - this.cbx_bgtype_9.Text = "下播"; - this.cbx_bgtype_9.UseVisualStyleBackColor = true; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(839, 9); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(105, 15); - this.label2.TabIndex = 3; - this.label2.Text = "🚀 代理抓取中"; - // - // flowLayoutPanel1 - // - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_1); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_5); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_2); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_3); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_4); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_6); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_7); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_8); - this.flowLayoutPanel1.Controls.Add(this.cbx_bgtype_9); - this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left; - this.flowLayoutPanel1.Location = new System.Drawing.Point(15, 0); - this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 0); - this.flowLayoutPanel1.Size = new System.Drawing.Size(79, 260); - this.flowLayoutPanel1.TabIndex = 4; - // - // panel1 - // - this.panel1.Controls.Add(this.flowLayoutPanel1); - this.panel1.Controls.Add(this.richTextBox1); - this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel1.Location = new System.Drawing.Point(0, 263); - this.panel1.Name = "panel1"; - this.panel1.Padding = new System.Windows.Forms.Padding(15, 0, 5, 0); - this.panel1.Size = new System.Drawing.Size(735, 260); - this.panel1.TabIndex = 5; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(249, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(37, 15); - this.label1.TabIndex = 6; - this.label1.Text = "配置"; - // - // listBox1 - // - this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.listBox1.FormattingEnabled = true; - this.listBox1.ItemHeight = 15; - this.listBox1.Location = new System.Drawing.Point(18, 41); - this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(228, 199); - this.listBox1.TabIndex = 7; - // - // cbx_enableProxy - // - this.cbx_enableProxy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.cbx_enableProxy.AutoSize = true; - this.cbx_enableProxy.Location = new System.Drawing.Point(634, 8); - this.cbx_enableProxy.Name = "cbx_enableProxy"; - this.cbx_enableProxy.Size = new System.Drawing.Size(89, 19); - this.cbx_enableProxy.TabIndex = 8; - this.cbx_enableProxy.Text = "启用抓取"; - this.cbx_enableProxy.UseVisualStyleBackColor = true; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(15, 9); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(121, 15); - this.label3.TabIndex = 9; - this.label3.Text = "房间缓存列表(0)"; - // - // panel2 - // - this.panel2.Controls.Add(this.cbx_barrageLog); - this.panel2.Controls.Add(this.panel3); - this.panel2.Controls.Add(this.label1); - this.panel2.Controls.Add(this.listBox1); - this.panel2.Controls.Add(this.cbx_enableProxy); - this.panel2.Controls.Add(this.label3); - this.panel2.Dock = System.Windows.Forms.DockStyle.Top; - this.panel2.Location = new System.Drawing.Point(0, 0); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(735, 257); - this.panel2.TabIndex = 10; - // - // panel3 - // - this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.panel3.Controls.Add(this.txb_upstreamProxy); - this.panel3.Controls.Add(this.label5); - this.panel3.Controls.Add(this.nud_wsport); - this.panel3.Controls.Add(this.cbx_loopback); - this.panel3.Controls.Add(this.label4); - this.panel3.Location = new System.Drawing.Point(252, 41); - this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(471, 199); - this.panel3.TabIndex = 13; - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Cursor = System.Windows.Forms.Cursors.Arrow; - this.label5.Location = new System.Drawing.Point(3, 64); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(112, 15); - this.label5.TabIndex = 13; - this.label5.Text = "上游代理地址:"; - // - // nud_wsport - // - this.nud_wsport.Location = new System.Drawing.Point(113, 16); - this.nud_wsport.Maximum = new decimal(new int[] { - 65534, - 0, - 0, - 0}); - this.nud_wsport.Minimum = new decimal(new int[] { - 1000, - 0, - 0, - 0}); - this.nud_wsport.Name = "nud_wsport"; - this.nud_wsport.Size = new System.Drawing.Size(84, 25); - this.nud_wsport.TabIndex = 11; - this.nud_wsport.Value = new decimal(new int[] { - 1000, - 0, - 0, - 0}); - // - // cbx_loopback - // - this.cbx_loopback.AutoSize = true; - this.cbx_loopback.Location = new System.Drawing.Point(219, 19); - this.cbx_loopback.Name = "cbx_loopback"; - this.cbx_loopback.Size = new System.Drawing.Size(74, 19); - this.cbx_loopback.TabIndex = 12; - this.cbx_loopback.Text = "仅回环"; - this.cbx_loopback.UseVisualStyleBackColor = true; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(9, 21); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(98, 15); - this.label4.TabIndex = 10; - this.label4.Text = "WS服务端口:"; - // - // txb_upstreamProxy - // - this.txb_upstreamProxy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.txb_upstreamProxy.Location = new System.Drawing.Point(113, 60); - this.txb_upstreamProxy.Name = "txb_upstreamProxy"; - this.txb_upstreamProxy.Size = new System.Drawing.Size(180, 25); - this.txb_upstreamProxy.TabIndex = 14; - // - // cbx_barrageLog - // - this.cbx_barrageLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.cbx_barrageLog.AutoSize = true; - this.cbx_barrageLog.Location = new System.Drawing.Point(532, 8); - this.cbx_barrageLog.Name = "cbx_barrageLog"; - this.cbx_barrageLog.Size = new System.Drawing.Size(89, 19); - this.cbx_barrageLog.TabIndex = 14; - this.cbx_barrageLog.Text = "弹幕日志"; - this.cbx_barrageLog.UseVisualStyleBackColor = true; - // - // FormView - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(735, 523); - this.Controls.Add(this.panel2); - this.Controls.Add(this.panel1); - this.Controls.Add(this.label2); - this.MaximizeBox = false; - this.Name = "FormView"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "FormView"; - this.flowLayoutPanel1.ResumeLayout(false); - this.flowLayoutPanel1.PerformLayout(); - this.panel1.ResumeLayout(false); - this.panel2.ResumeLayout(false); - this.panel2.PerformLayout(); - this.panel3.ResumeLayout(false); - this.panel3.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nud_wsport)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.RichTextBox richTextBox1; - private System.Windows.Forms.CheckBox cbx_bgtype_5; - private System.Windows.Forms.CheckBox cbx_bgtype_1; - private System.Windows.Forms.CheckBox cbx_bgtype_6; - private System.Windows.Forms.CheckBox cbx_bgtype_4; - private System.Windows.Forms.CheckBox cbx_bgtype_3; - private System.Windows.Forms.CheckBox cbx_bgtype_2; - private System.Windows.Forms.CheckBox cbx_bgtype_7; - private System.Windows.Forms.CheckBox cbx_bgtype_9; - private System.Windows.Forms.CheckBox cbx_bgtype_8; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; - private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.ListBox listBox1; - private System.Windows.Forms.CheckBox cbx_enableProxy; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Panel panel2; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.Panel panel3; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.NumericUpDown nud_wsport; - private System.Windows.Forms.CheckBox cbx_loopback; - private System.Windows.Forms.TextBox txb_upstreamProxy; - private System.Windows.Forms.CheckBox cbx_barrageLog; - } -} \ No newline at end of file diff --git a/BarrageGrab/FormView.cs b/BarrageGrab/FormView.cs deleted file mode 100644 index 4c730ec..0000000 --- a/BarrageGrab/FormView.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace BarrageGrab -{ - public partial class FormView : Form - { - public FormView() - { - InitializeComponent(); - } - } -} diff --git a/BarrageGrab/Forms/FormView.Designer.cs b/BarrageGrab/Forms/FormView.Designer.cs new file mode 100644 index 0000000..6006828 --- /dev/null +++ b/BarrageGrab/Forms/FormView.Designer.cs @@ -0,0 +1,373 @@ +namespace BarrageGrab +{ + partial class FormView + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.rich_output = new System.Windows.Forms.RichTextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.tab_filters = new System.Windows.Forms.TabControl(); + this.tabPage_Console = new System.Windows.Forms.TabPage(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.tabPage_Ws = new System.Windows.Forms.TabPage(); + this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.list_roomCaches = new System.Windows.Forms.ListBox(); + this.cbx_enableProxy = new System.Windows.Forms.CheckBox(); + this.label3 = new System.Windows.Forms.Label(); + this.panel2 = new System.Windows.Forms.Panel(); + this.cbx_barrageLog = new System.Windows.Forms.CheckBox(); + this.panel3 = new System.Windows.Forms.Panel(); + this.btn_updateUpProxy = new System.Windows.Forms.Button(); + this.txb_upstreamProxy = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.txb_wsaddr = new System.Windows.Forms.TextBox(); + this.tabPage_Log = new System.Windows.Forms.TabPage(); + this.flowLayoutPanel3 = new System.Windows.Forms.FlowLayoutPanel(); + this.panel1.SuspendLayout(); + this.tab_filters.SuspendLayout(); + this.tabPage_Console.SuspendLayout(); + this.tabPage_Ws.SuspendLayout(); + this.panel2.SuspendLayout(); + this.panel3.SuspendLayout(); + this.tabPage_Log.SuspendLayout(); + this.SuspendLayout(); + // + // rich_output + // + this.rich_output.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.rich_output.BackColor = System.Drawing.SystemColors.Desktop; + this.rich_output.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.rich_output.Location = new System.Drawing.Point(90, 0); + this.rich_output.Margin = new System.Windows.Forms.Padding(2); + this.rich_output.Name = "rich_output"; + this.rich_output.ReadOnly = true; + this.rich_output.Size = new System.Drawing.Size(592, 271); + this.rich_output.TabIndex = 0; + this.rich_output.Text = ""; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(629, 7); + this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(83, 12); + this.label2.TabIndex = 3; + this.label2.Text = "🚀 代理抓取中"; + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.Controls.Add(this.tab_filters); + this.panel1.Controls.Add(this.rich_output); + this.panel1.Location = new System.Drawing.Point(0, 202); + this.panel1.Margin = new System.Windows.Forms.Padding(2); + this.panel1.Name = "panel1"; + this.panel1.Padding = new System.Windows.Forms.Padding(0, 0, 5, 10); + this.panel1.Size = new System.Drawing.Size(687, 281); + this.panel1.TabIndex = 5; + // + // tab_filters + // + this.tab_filters.Alignment = System.Windows.Forms.TabAlignment.Left; + this.tab_filters.Controls.Add(this.tabPage_Console); + this.tab_filters.Controls.Add(this.tabPage_Ws); + this.tab_filters.Controls.Add(this.tabPage_Log); + this.tab_filters.Dock = System.Windows.Forms.DockStyle.Left; + this.tab_filters.Location = new System.Drawing.Point(0, 0); + this.tab_filters.Multiline = true; + this.tab_filters.Name = "tab_filters"; + this.tab_filters.SelectedIndex = 0; + this.tab_filters.Size = new System.Drawing.Size(89, 271); + this.tab_filters.TabIndex = 10; + // + // tabPage_Console + // + this.tabPage_Console.Controls.Add(this.flowLayoutPanel1); + this.tabPage_Console.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.tabPage_Console.Location = new System.Drawing.Point(22, 4); + this.tabPage_Console.Name = "tabPage_Console"; + this.tabPage_Console.Padding = new System.Windows.Forms.Padding(3); + this.tabPage_Console.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.tabPage_Console.Size = new System.Drawing.Size(63, 263); + this.tabPage_Console.TabIndex = 0; + this.tabPage_Console.Text = "控制台"; + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 3); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(2); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(57, 257); + this.flowLayoutPanel1.TabIndex = 5; + // + // tabPage_Ws + // + this.tabPage_Ws.Controls.Add(this.flowLayoutPanel2); + this.tabPage_Ws.Location = new System.Drawing.Point(22, 4); + this.tabPage_Ws.Name = "tabPage_Ws"; + this.tabPage_Ws.Padding = new System.Windows.Forms.Padding(3); + this.tabPage_Ws.Size = new System.Drawing.Size(63, 263); + this.tabPage_Ws.TabIndex = 1; + this.tabPage_Ws.Text = "推送 "; + // + // flowLayoutPanel2 + // + this.flowLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel2.Location = new System.Drawing.Point(3, 3); + this.flowLayoutPanel2.Margin = new System.Windows.Forms.Padding(2); + this.flowLayoutPanel2.Name = "flowLayoutPanel2"; + this.flowLayoutPanel2.Padding = new System.Windows.Forms.Padding(0, 8, 0, 0); + this.flowLayoutPanel2.Size = new System.Drawing.Size(57, 257); + this.flowLayoutPanel2.TabIndex = 6; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(248, 7); + this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(29, 12); + this.label1.TabIndex = 6; + this.label1.Text = "配置"; + // + // list_roomCaches + // + this.list_roomCaches.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.list_roomCaches.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.list_roomCaches.FormattingEnabled = true; + this.list_roomCaches.ItemHeight = 12; + this.list_roomCaches.Location = new System.Drawing.Point(14, 33); + this.list_roomCaches.Margin = new System.Windows.Forms.Padding(2); + this.list_roomCaches.Name = "list_roomCaches"; + this.list_roomCaches.Size = new System.Drawing.Size(232, 158); + this.list_roomCaches.TabIndex = 7; + this.list_roomCaches.DoubleClick += new System.EventHandler(this.list_roomCaches_DoubleClick); + // + // cbx_enableProxy + // + this.cbx_enableProxy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.cbx_enableProxy.AutoSize = true; + this.cbx_enableProxy.Location = new System.Drawing.Point(558, 6); + this.cbx_enableProxy.Margin = new System.Windows.Forms.Padding(2); + this.cbx_enableProxy.Name = "cbx_enableProxy"; + this.cbx_enableProxy.Size = new System.Drawing.Size(120, 16); + this.cbx_enableProxy.TabIndex = 8; + this.cbx_enableProxy.Text = "启用系统代理抓取"; + this.cbx_enableProxy.UseVisualStyleBackColor = true; + this.cbx_enableProxy.CheckedChanged += new System.EventHandler(this.cbx_enableProxy_CheckedChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(11, 7); + this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(95, 12); + this.label3.TabIndex = 9; + this.label3.Text = "房间缓存列表(0)"; + // + // panel2 + // + this.panel2.Controls.Add(this.cbx_barrageLog); + this.panel2.Controls.Add(this.panel3); + this.panel2.Controls.Add(this.label1); + this.panel2.Controls.Add(this.list_roomCaches); + this.panel2.Controls.Add(this.cbx_enableProxy); + this.panel2.Controls.Add(this.label3); + this.panel2.Dock = System.Windows.Forms.DockStyle.Top; + this.panel2.Location = new System.Drawing.Point(0, 0); + this.panel2.Margin = new System.Windows.Forms.Padding(2); + this.panel2.Name = "panel2"; + this.panel2.Padding = new System.Windows.Forms.Padding(0, 0, 0, 10); + this.panel2.Size = new System.Drawing.Size(687, 198); + this.panel2.TabIndex = 10; + // + // cbx_barrageLog + // + this.cbx_barrageLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.cbx_barrageLog.AutoSize = true; + this.cbx_barrageLog.Location = new System.Drawing.Point(477, 6); + this.cbx_barrageLog.Margin = new System.Windows.Forms.Padding(2); + this.cbx_barrageLog.Name = "cbx_barrageLog"; + this.cbx_barrageLog.Size = new System.Drawing.Size(72, 16); + this.cbx_barrageLog.TabIndex = 14; + this.cbx_barrageLog.Text = "弹幕日志"; + this.cbx_barrageLog.UseVisualStyleBackColor = true; + this.cbx_barrageLog.CheckedChanged += new System.EventHandler(this.cbx_barrageLog_CheckedChanged); + // + // panel3 + // + this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel3.Controls.Add(this.txb_wsaddr); + this.panel3.Controls.Add(this.btn_updateUpProxy); + this.panel3.Controls.Add(this.txb_upstreamProxy); + this.panel3.Controls.Add(this.label5); + this.panel3.Controls.Add(this.label4); + this.panel3.Location = new System.Drawing.Point(250, 33); + this.panel3.Margin = new System.Windows.Forms.Padding(2); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(429, 159); + this.panel3.TabIndex = 13; + // + // btn_updateUpProxy + // + this.btn_updateUpProxy.Location = new System.Drawing.Point(254, 48); + this.btn_updateUpProxy.Name = "btn_updateUpProxy"; + this.btn_updateUpProxy.Size = new System.Drawing.Size(64, 23); + this.btn_updateUpProxy.TabIndex = 15; + this.btn_updateUpProxy.Text = "确定"; + this.btn_updateUpProxy.UseVisualStyleBackColor = true; + this.btn_updateUpProxy.Click += new System.EventHandler(this.btn_updateUpProxy_Click); + // + // txb_upstreamProxy + // + this.txb_upstreamProxy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.txb_upstreamProxy.Location = new System.Drawing.Point(85, 48); + this.txb_upstreamProxy.Margin = new System.Windows.Forms.Padding(2); + this.txb_upstreamProxy.Name = "txb_upstreamProxy"; + this.txb_upstreamProxy.Size = new System.Drawing.Size(164, 21); + this.txb_upstreamProxy.TabIndex = 14; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Cursor = System.Windows.Forms.Cursors.Arrow; + this.label5.Location = new System.Drawing.Point(18, 52); + this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(65, 12); + this.label5.TabIndex = 13; + this.label5.Text = "上游代理:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(7, 17); + this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(77, 12); + this.label4.TabIndex = 10; + this.label4.Text = "WS服务端口:"; + // + // txb_wsaddr + // + this.txb_wsaddr.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.txb_wsaddr.Location = new System.Drawing.Point(85, 14); + this.txb_wsaddr.Margin = new System.Windows.Forms.Padding(2); + this.txb_wsaddr.Name = "txb_wsaddr"; + this.txb_wsaddr.ReadOnly = true; + this.txb_wsaddr.Size = new System.Drawing.Size(164, 21); + this.txb_wsaddr.TabIndex = 16; + // + // tabPage_Log + // + this.tabPage_Log.Controls.Add(this.flowLayoutPanel3); + this.tabPage_Log.Location = new System.Drawing.Point(22, 4); + this.tabPage_Log.Name = "tabPage_Log"; + this.tabPage_Log.Size = new System.Drawing.Size(63, 263); + this.tabPage_Log.TabIndex = 2; + this.tabPage_Log.Text = "日志 "; + this.tabPage_Log.UseVisualStyleBackColor = true; + // + // flowLayoutPanel3 + // + this.flowLayoutPanel3.BackColor = System.Drawing.SystemColors.Control; + this.flowLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel3.Location = new System.Drawing.Point(0, 0); + this.flowLayoutPanel3.Margin = new System.Windows.Forms.Padding(2); + this.flowLayoutPanel3.Name = "flowLayoutPanel3"; + this.flowLayoutPanel3.Padding = new System.Windows.Forms.Padding(0, 8, 0, 0); + this.flowLayoutPanel3.Size = new System.Drawing.Size(63, 263); + this.flowLayoutPanel3.TabIndex = 7; + // + // FormView + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(687, 483); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); + this.Controls.Add(this.label2); + this.Margin = new System.Windows.Forms.Padding(2); + this.MaximizeBox = false; + this.Name = "FormView"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "抖音弹幕抓取推送"; + this.Load += new System.EventHandler(this.FormView_Load); + this.panel1.ResumeLayout(false); + this.tab_filters.ResumeLayout(false); + this.tabPage_Console.ResumeLayout(false); + this.tabPage_Ws.ResumeLayout(false); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + this.tabPage_Log.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.RichTextBox rich_output; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox list_roomCaches; + private System.Windows.Forms.CheckBox cbx_enableProxy; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txb_upstreamProxy; + private System.Windows.Forms.CheckBox cbx_barrageLog; + private System.Windows.Forms.TabControl tab_filters; + private System.Windows.Forms.TabPage tabPage_Console; + private System.Windows.Forms.TabPage tabPage_Ws; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2; + private System.Windows.Forms.Button btn_updateUpProxy; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.TextBox txb_wsaddr; + private System.Windows.Forms.TabPage tabPage_Log; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel3; + } +} \ No newline at end of file diff --git a/BarrageGrab/Forms/FormView.cs b/BarrageGrab/Forms/FormView.cs new file mode 100644 index 0000000..e743aac --- /dev/null +++ b/BarrageGrab/Forms/FormView.cs @@ -0,0 +1,238 @@ +using BarrageGrab.Forms; +using BarrageGrab.Forms.Models; +using BarrageGrab.Modles.JsonEntity; +using BarrageGrab.Proxy; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BarrageGrab +{ + public partial class FormView : Form + { + static int printCount = 0; + + WsBarrageService barServer = AppRuntime.WssService; + WssBarrageGrab grab = AppRuntime.WssService.Grab; + ISystemProxy proxy = AppRuntime.WssService.Grab.Proxy; + + public FormView() + { + InitializeComponent(); + barServer.OnPrint += WssService_OnPrint; + barServer.Grab.Proxy.OnProxyStatus += Proxy_OnProxyStatus; + AppRuntime.RoomCaches.OnCache += RoomCaches_OnCache; + this.txb_wsaddr.Text = barServer.ServerLocation; + this.txb_upstreamProxy.Text = proxy.HttpUpstreamProxy; + this.cbx_barrageLog.Checked = Appsetting.Current.BarrageLog; + InitTabPages(); + } + + private void InitTabPages() + { + var msgTypes = GetMsgTypes(); + foreach (TabPage page in this.tab_filters.TabPages) + { + page.Padding = new Padding(0) + { + Left = 5 + }; + page.Margin = new Padding(0); + foreach (Control control in page.Controls) + { + var panel = control as FlowLayoutPanel; + if (panel == null) continue; + panel.Padding = new Padding(0); + panel.Margin = new Padding(0); + + foreach (var label in msgTypes) + { + var ck = new CheckBox() + { + Text = label.Value, + Tag = label.Key, + Parent = panel, + Padding = new Padding(0), + Margin = new Padding(0) + }; + string type = "console"; + if (page == this.tabPage_Ws) + { + type = "ws"; + ck.Checked = Appsetting.Current.PushFilter.Contains(label.Key); + } + if (page == this.tabPage_Console) + { + type = "console"; + ck.Checked = Appsetting.Current.PrintFilter.Contains(label.Key); + } + if (page == this.tabPage_Log) + { + type = "log"; + ck.Checked = Appsetting.Current.LogFilter.Contains(label.Key); + } + ck.Name = $"cbx_bartype_{type}_{label.Key}"; + ck.CheckedChanged += Ck_CheckedChanged; + panel.Controls.Add(ck); + } + } + } + } + + private void Ck_CheckedChanged(object sender, EventArgs e) + { + CheckBox cbx = sender as CheckBox; + if (cbx == null) return; + var selected = GetCheckedBarTypes((FlowLayoutPanel)cbx.Parent); + if (cbx.Parent.Parent == this.tabPage_Console) + { + Appsetting.Current.PrintFilter = selected; + } + if (cbx.Parent.Parent == this.tabPage_Ws) + { + Appsetting.Current.PushFilter = selected; + } + if(cbx.Parent.Parent == this.tabPage_Log) + { + Appsetting.Current.LogFilter = selected; + } + Appsetting.Current.Save(); + } + + private int[] GetCheckedBarTypes(FlowLayoutPanel panel) + { + List list = new List(); + foreach (Control ctr in panel.Controls) + { + var cbk = ctr as CheckBox; + if (cbk == null) continue; + if (cbk.Checked && cbk.Name.StartsWith("cbx_bartype_")) + { + list.Add((int)cbk.Tag); + } + } + return list.OrderBy(o => o).ToArray(); + } + + private Dictionary GetMsgTypes() + { + var dic = new Dictionary(); + Type enumType = typeof(PackMsgType); + FieldInfo[] fields = enumType.GetFields(BindingFlags.Public | BindingFlags.Static); + foreach (var field in fields) + { + DescriptionAttribute attribute = (DescriptionAttribute)field.GetCustomAttribute(typeof(DescriptionAttribute), false); + int value = (int)field.GetValue(null); + if (attribute != null && value>0) + { + dic.Add(value, attribute.Description); + } + } + + return dic; + } + + private void RoomCaches_OnCache(object sender, AppRuntime.RoomCacheManager.RoomCacheEventArgs e) + { + this.Invoke(new Action(() => + { + if (e.Model == 0) + { + var item = new RoomCacheItem(e.RoomInfo); + this.label3.Text = $"房间缓存列表({AppRuntime.RoomCaches.RoomInfoCache.Count})"; + list_roomCaches.Items.Add(item); + } + })); + } + + private void FormView_Load(object sender, EventArgs e) + { + this.cbx_enableProxy.Checked = SystemProxy.ProxyIsOpen(); + } + + private void Proxy_OnProxyStatus(object sender, Proxy.ProxyEventArgs.SystemProxyChangeEventArgs e) + { + if (this.Disposing || this.IsDisposed) return; + this.Invoke(new Action(() => + { + this.cbx_enableProxy.Checked = e.Open; + })); + } + + private void WssService_OnPrint(object sender, WsBarrageService.PrintEventArgs e) + { + //将弹幕输出到richTextBox + //颜色转换 + Color color = Appsetting.Current.ColorMap[e.MsgType].Item2; + string msg = e.Message; + + this.Invoke(new Action(() => + { + //输出到richTextBox + this.rich_output.SelectionColor = color; + this.rich_output.AppendText(msg + "\n"); + this.rich_output.ScrollToCaret(); + })); + + if (++printCount > 10000) + { + this.rich_output.Clear(); + printCount = 0; + } + } + + private void cbx_enableProxy_CheckedChanged(object sender, EventArgs e) + { + var checker = (CheckBox)sender; + if (checker.Checked) + { + barServer.Grab.Proxy.RegisterSystemProxy(); + } + else + { + barServer.Grab.Proxy.CloseSystemProxy(); + } + } + + private void list_roomCaches_DoubleClick(object sender, EventArgs e) + { + // 获取双击的 ListBox 中的选中项 + var selectedItem = list_roomCaches.SelectedItem as RoomCacheItem; + if (selectedItem == null) return; + + var form = new RoomDetail(selectedItem.RoomInfo); + form.ShowDialog(); + } + + private void btn_updateUpProxy_Click(object sender, EventArgs e) + { + var text = this.txb_upstreamProxy.Text; + try + { + proxy.SetUpstreamProxy(text); + Appsetting.Current.UpstreamProxy = text; + Appsetting.Current.Save(); + } + catch (Exception ex) + { + //弹窗提示错误 + MessageBox.Show(ex.Message,"设置失败"); + } + } + + private void cbx_barrageLog_CheckedChanged(object sender, EventArgs e) + { + var checker = (CheckBox)sender; + Appsetting.Current.BarrageLog = checker.Checked; + Appsetting.Current.Save(); + } + } +} diff --git a/BarrageGrab/FormView.resx b/BarrageGrab/Forms/FormView.resx similarity index 100% rename from BarrageGrab/FormView.resx rename to BarrageGrab/Forms/FormView.resx diff --git a/BarrageGrab/Forms/Models/RoomCacheItem.cs b/BarrageGrab/Forms/Models/RoomCacheItem.cs new file mode 100644 index 0000000..6dad8c2 --- /dev/null +++ b/BarrageGrab/Forms/Models/RoomCacheItem.cs @@ -0,0 +1,27 @@ +using BarrageGrab.Modles; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BarrageGrab.Forms.Models +{ + internal class RoomCacheItem + { + public RoomCacheItem(RoomInfo info) + { + this.RoomInfo = info; + } + /// + /// 数据对象 + /// + public RoomInfo RoomInfo { get; set; } + + public override string ToString() + { + if (RoomInfo == null) return "NULL"; + return $"({RoomInfo.WebRoomId}){RoomInfo?.Owner?.Nickname??"-1"}"; + } + } +} diff --git a/BarrageGrab/Forms/RoomDetail.Designer.cs b/BarrageGrab/Forms/RoomDetail.Designer.cs new file mode 100644 index 0000000..724d88b --- /dev/null +++ b/BarrageGrab/Forms/RoomDetail.Designer.cs @@ -0,0 +1,80 @@ +namespace BarrageGrab.Forms +{ + partial class RoomDetail + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.Location = new System.Drawing.Point(12, 12); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.textBox1.Size = new System.Drawing.Size(332, 246); + this.textBox1.TabIndex = 0; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.button1.Location = new System.Drawing.Point(12, 277); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 1; + this.button1.Text = "复制"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // RoomDetail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(356, 312); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox1); + this.Name = "RoomDetail"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "房间数据"; + this.Load += new System.EventHandler(this.RoomDetail_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/BarrageGrab/Forms/RoomDetail.cs b/BarrageGrab/Forms/RoomDetail.cs new file mode 100644 index 0000000..352b3ce --- /dev/null +++ b/BarrageGrab/Forms/RoomDetail.cs @@ -0,0 +1,41 @@ +using BarrageGrab.Modles; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Newtonsoft.Json; + +namespace BarrageGrab.Forms +{ + public partial class RoomDetail : Form + { + public RoomDetail(RoomInfo info) + { + InitializeComponent(); + //小驼峰 + var json = JsonConvert.SerializeObject(info,Formatting.Indented,new JsonSerializerSettings() + { + ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() + }); + + this.textBox1.Text = json; + } + + private void RoomDetail_Load(object sender, EventArgs e) + { + + } + + private void button1_Click(object sender, EventArgs e) + { + //复制到剪切板 + Clipboard.SetText(this.textBox1.Text); + MessageBox.Show("复制成功"); + } + } +} diff --git a/BarrageGrab/Forms/RoomDetail.resx b/BarrageGrab/Forms/RoomDetail.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BarrageGrab/Forms/RoomDetail.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BarrageGrab/Logger.cs b/BarrageGrab/Logger.cs index 7c0e051..6147f33 100644 --- a/BarrageGrab/Logger.cs +++ b/BarrageGrab/Logger.cs @@ -4,11 +4,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using NLog; +using BarrageGrab.Modles.JsonEntity; +using System.IO; namespace BarrageGrab { public static class Logger - { + { private static NLog.Config.ISetupBuilder builder = LogManager.Setup().LoadConfigurationFromFile("nlog.config"); private static readonly NLog.Logger logger = builder.GetLogger("*"); @@ -53,5 +55,62 @@ namespace BarrageGrab { logger.Fatal(ex, message); } + + public static void LogBarrage(PackMsgType type, Msg msg) + { + if (!Appsetting.Current.BarrageLog) return; + if (type == PackMsgType.无) return; + if (Appsetting.Current.LogFilter.Any() && !Appsetting.Current.LogFilter.Contains(type.GetHashCode())) return; + + try + { + var dir = Path.Combine(AppContext.BaseDirectory, "logs", "弹幕日志"); + var room = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString()); + var date = DateTime.Now.ToString("yyyy年MM月dd日直播"); + dir = Path.Combine(dir, $"({room.WebRoomId}){room?.Owner?.Nickname ?? "-1"}", date); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + var path = Path.Combine(dir, type + ".txt"); + if (!File.Exists(path)) + { + File.Create(path).Close(); + } + var writer = new StreamWriter(path, true, Encoding.UTF8); + var line = LogText(msg, type); + writer.WriteLine(line); + writer.Close(); + } + catch (Exception ex) + { + LogWarn("弹幕日志写入失败," + ex.Message); + return; + } + } + + + private static string LogText(Msg msg, PackMsgType barType) + { + var rinfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString()); + var text = $"{DateTime.Now.ToString("HH:mm:ss")} [{barType}]"; + + if (msg.User != null) + { + text += $" [{msg.User?.GenderToString()}] "; + } + + ConsoleColor color = Appsetting.Current.ColorMap[barType].Item1; + var append = msg.Content; + switch (barType) + { + case PackMsgType.弹幕消息: append = $"{msg?.User?.Nickname}: {msg.Content}"; break; + case PackMsgType.下播: append = $"直播已结束"; break; + default: break; + } + + text += append; + return text; + } } } diff --git a/BarrageGrab/Modles/JsonEntity/BarrageMessages.cs b/BarrageGrab/Modles/JsonEntity/BarrageMessages.cs index b9b5741..8b4132a 100644 --- a/BarrageGrab/Modles/JsonEntity/BarrageMessages.cs +++ b/BarrageGrab/Modles/JsonEntity/BarrageMessages.cs @@ -1,19 +1,31 @@ -namespace BarrageGrab.Modles.JsonEntity +using System.ComponentModel; + +namespace BarrageGrab.Modles.JsonEntity { /// /// 弹幕消息类型 /// public enum PackMsgType { - 无 = 0, + [Description("无")] + 无 = 0, + [Description("消息")] 弹幕消息 = 1, + [Description("点赞")] 点赞消息 = 2, + [Description("进房")] 进直播间 = 3, + [Description("关注")] 关注消息 = 4, + [Description("礼物")] 礼物消息 = 5, + [Description("统计")] 直播间统计 = 6, + [Description("粉团")] 粉丝团消息 = 7, + [Description("分享")] 直播间分享 = 8, + [Description("下播")] 下播 = 9 } diff --git a/BarrageGrab/Modles/RoomInfo.cs b/BarrageGrab/Modles/RoomInfo.cs index 26a1006..2b6e4c9 100644 --- a/BarrageGrab/Modles/RoomInfo.cs +++ b/BarrageGrab/Modles/RoomInfo.cs @@ -519,7 +519,8 @@ namespace BarrageGrab.Modles } //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 roomDataReg = new Regex(@"(?<=self\.__pace_f\.push\(\[1,\s*""9:)\[.+?\](?=\\n""?\]\)[\s\n\r]*?<\/script>)"); + var roomDataReg = new Regex(@"(?<=self\.__pace_f\.push\(\[\d,\s*""\w:.+)\{\\""state.+?\}(?=\]\\n""\]\)[\s\n\r]*?<\/script>)"); //字符串转义符号版本 var match = roomDataReg.Match(html); @@ -530,10 +531,10 @@ namespace BarrageGrab.Modles } var matchData = Regex.Unescape(match.Value); - JToken jsonObject = null; + JObject jsonObject = null; try { - jsonObject = JsonConvert.DeserializeObject(matchData)[3]; + jsonObject = JObject.Parse(matchData); } catch (Exception ex) { diff --git a/BarrageGrab/Program.cs b/BarrageGrab/Program.cs index 10c0a2b..633024a 100644 --- a/BarrageGrab/Program.cs +++ b/BarrageGrab/Program.cs @@ -12,7 +12,7 @@ namespace BarrageGrab public class Program { static void Main(string[] args) - { + { if (CheckAlreadyRunning()) { Console.WriteLine("已经有一个监听程序在运行,按任意键退出..."); @@ -24,15 +24,31 @@ namespace BarrageGrab WinApi.DisableQuickEditMode();//禁用控制台快速编辑模式 Console.Title = "抖音弹幕监听推送"; AppRuntime.DisplayConsole(!Appsetting.Current.HideConsole); + AppRuntime.WssService.Grab.Proxy.SetUpstreamProxy(Appsetting.Current.UpstreamProxy); bool exited = false; + bool formExited = false; AppRuntime.WssService.StartListen(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{AppRuntime.WssService.ServerLocation} 弹幕服务已启动..."); Console.ForegroundColor = ConsoleColor.Gray; Console.Title = $"抖音弹幕监听推送 [{AppRuntime.WssService.ServerLocation}]"; - + FormView mainForm = null; + + if (Appsetting.Current.ShowWindow) + { + var uiThread = new Thread(new ThreadStart(() => + { + mainForm = new FormView(); + //开启消息循环 + System.Windows.Forms.Application.Run(mainForm); + formExited = true; + })); + uiThread.SetApartmentState(ApartmentState.STA); + uiThread.IsBackground = true; + uiThread.Start(); + } AppRuntime.WssService.OnClose += (s, e) => { @@ -42,13 +58,25 @@ namespace BarrageGrab while (!exited) { + if (formExited && !exited) + { + AppRuntime.WssService.Close(); + } Thread.Sleep(500); } Console.WriteLine("服务器已关闭..."); - + + //if (!mainForm.IsDisposed) + //{ + // mainForm.Invoke(new Action(() => + // { + // mainForm.Close(); + // })); + //} + //退出程序,不显示 按任意键退出 - Environment.Exit(0); + //Environment.Exit(0); } private static WinApi.ControlCtrlDelegate cancelHandler = new WinApi.ControlCtrlDelegate((CtrlType) => diff --git a/BarrageGrab/Proxy/ISystemProxy.cs b/BarrageGrab/Proxy/ISystemProxy.cs index 417cac5..8626e7e 100644 --- a/BarrageGrab/Proxy/ISystemProxy.cs +++ b/BarrageGrab/Proxy/ISystemProxy.cs @@ -11,6 +11,23 @@ namespace BarrageGrab.Proxy event EventHandler OnFetchResponse; + event EventHandler OnProxyStatus; + + /// + /// Http上游代理地址 + /// + string HttpUpstreamProxy { get; } + + /// + /// Https 上游代理地址 + /// + string HttpsUpstreamProxy { get; } + + /// + /// 设置上游代理地址(http+https) + /// + void SetUpstreamProxy(string addr); + /// /// 关闭系统代理 /// diff --git a/BarrageGrab/Proxy/EventArgs/HttpResponseEventArgs.cs b/BarrageGrab/Proxy/ProxyEventArgs/HttpResponseEventArgs.cs similarity index 100% rename from BarrageGrab/Proxy/EventArgs/HttpResponseEventArgs.cs rename to BarrageGrab/Proxy/ProxyEventArgs/HttpResponseEventArgs.cs diff --git a/BarrageGrab/Proxy/ProxyEventArgs/SystemProxyChangeEventArgs.cs b/BarrageGrab/Proxy/ProxyEventArgs/SystemProxyChangeEventArgs.cs new file mode 100644 index 0000000..2a00689 --- /dev/null +++ b/BarrageGrab/Proxy/ProxyEventArgs/SystemProxyChangeEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BarrageGrab.Proxy.ProxyEventArgs +{ + public class SystemProxyChangeEventArgs:EventArgs + { + /// + /// True 以开启:False: 已关闭 + /// + public bool Open { get; set; } + } +} diff --git a/BarrageGrab/Proxy/EventArgs/WsMessageEventArgs.cs b/BarrageGrab/Proxy/ProxyEventArgs/WsMessageEventArgs.cs similarity index 100% rename from BarrageGrab/Proxy/EventArgs/WsMessageEventArgs.cs rename to BarrageGrab/Proxy/ProxyEventArgs/WsMessageEventArgs.cs diff --git a/BarrageGrab/Proxy/SystemProxy.cs b/BarrageGrab/Proxy/SystemProxy.cs index c75eddc..fdcc8b9 100644 --- a/BarrageGrab/Proxy/SystemProxy.cs +++ b/BarrageGrab/Proxy/SystemProxy.cs @@ -24,15 +24,26 @@ namespace BarrageGrab.Proxy /// public event EventHandler OnFetchResponse; + /// + /// 代理切换时触�? + /// + public event EventHandler OnProxyStatus; + /// /// 代理端口 /// - public int ProxyPort { get { return Appsetting.Current.ProxyPort; } } + public int ProxyPort { get { return Appsetting.Current.ProxyPort; } } + + public abstract string HttpUpstreamProxy { get; } + + public abstract string HttpsUpstreamProxy { get; } public abstract void Dispose(); public abstract void Start(); + public abstract void SetUpstreamProxy(string addr); + //https://live.douyin.com/webcast/gift/list/ [礼物数据接口] /// @@ -41,16 +52,16 @@ namespace BarrageGrab.Proxy /// /// protected virtual bool CheckHost(string host) - { + { host = host.Trim().ToLower(); if (!Appsetting.Current.FilterHostName) return true; - + if (host.StartsWith("webcast")) return true; if (Appsetting.Current.HostNameFilter.Any(a => a.Trim().ToLower() == host)) return true; - return false; + return false; } /// @@ -86,18 +97,22 @@ namespace BarrageGrab.Proxy return process.ProcessName; } } - catch (Exception ex){} + catch (Exception ex) { } return $"<{processID}>"; } /// - /// 注册为系统代理 + /// 注册为系统代�? /// public void RegisterSystemProxy() { RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); registry.SetValue("ProxyEnable", 1); registry.SetValue("ProxyServer", $"http=localhost:{ProxyPort};https=localhost:{ProxyPort}"); + OnProxyStatus?.Invoke(this, new SystemProxyChangeEventArgs() + { + Open = true + }); } /// @@ -108,6 +123,21 @@ namespace BarrageGrab.Proxy RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); registry.SetValue("ProxyEnable", 0); registry.SetValue("ProxyServer", $"http=localhost:{ProxyPort};https=localhost:{ProxyPort}"); + OnProxyStatus?.Invoke(this, new SystemProxyChangeEventArgs() + { + Open = false + }); + } + + public static bool ProxyIsOpen() + { + RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); + var proxyEnable = registry.GetValue("ProxyEnable"); + if (proxyEnable != null && proxyEnable.ToString() == "1") + { + return true; + } + return false; } } } diff --git a/BarrageGrab/Proxy/TitaniumProxy.cs b/BarrageGrab/Proxy/TitaniumProxy.cs index 9a7a791..580097a 100644 --- a/BarrageGrab/Proxy/TitaniumProxy.cs +++ b/BarrageGrab/Proxy/TitaniumProxy.cs @@ -31,6 +31,10 @@ namespace BarrageGrab.Proxy const string BARRAGE_POOL_PATH = "/webcast/im/fetch"; static ConsoleWriter console = new ConsoleWriter(); + public override string HttpUpstreamProxy { get { return proxyServer?.UpStreamHttpProxy?.ToString()??""; } } + + public override string HttpsUpstreamProxy { get { return proxyServer?.UpStreamHttpsProxy?.ToString()??""; } } + public TitaniumProxy() { //注册系统代理 @@ -47,10 +51,28 @@ namespace BarrageGrab.Proxy { Console.WriteLine("正在进行证书安装,需要安装证书才可进行https解密,若有提示请确定"); proxyServer.CertificateManager.CreateRootCertificate(); - } + } + proxyServer.ServerCertificateValidationCallback += ProxyServer_ServerCertificateValidationCallback; + proxyServer.BeforeResponse += ProxyServer_BeforeResponse; + //proxyServer.AfterResponse += ProxyServer_AfterResponse; + + explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, ProxyPort, true); + explicitEndPoint.BeforeTunnelConnectRequest += ExplicitEndPoint_BeforeTunnelConnectRequest; + proxyServer.AddEndPoint(explicitEndPoint); + } + + public override void SetUpstreamProxy(string upstreamProxyAddr) + { + if (string.IsNullOrWhiteSpace(upstreamProxyAddr)) return; + upstreamProxyAddr = upstreamProxyAddr.Trim(); + var reg = new Regex(@"[a-zA-Z0-9\.]+:\d+"); + if(!reg.IsMatch(upstreamProxyAddr)) + { + throw new Exception("上游代理地址格式不正确,必须为ip:port格式"); + } //设置上游代理地址 - var upstreamProxyAddr = Appsetting.Current.UpstreamProxy; + //var upstreamProxyAddr = Appsetting.Current.UpstreamProxy; if (!upstreamProxyAddr.IsNullOrWhiteSpace()) { upStreamProxy = new ExternalProxy() @@ -62,15 +84,6 @@ namespace BarrageGrab.Proxy proxyServer.UpStreamHttpProxy = upStreamProxy; proxyServer.UpStreamHttpsProxy = upStreamProxy; } - - proxyServer.ServerCertificateValidationCallback += ProxyServer_ServerCertificateValidationCallback; - proxyServer.BeforeResponse += ProxyServer_BeforeResponse; - //proxyServer.AfterResponse += ProxyServer_AfterResponse; - - - explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, ProxyPort, true); - explicitEndPoint.BeforeTunnelConnectRequest += ExplicitEndPoint_BeforeTunnelConnectRequest; - proxyServer.AddEndPoint(explicitEndPoint); } private async Task ProxyServer_BeforeResponse(object sender, SessionEventArgs e) diff --git a/BarrageGrab/WsBarrageService.cs b/BarrageGrab/WsBarrageService.cs index aad6559..6dd1ea3 100644 --- a/BarrageGrab/WsBarrageService.cs +++ b/BarrageGrab/WsBarrageService.cs @@ -16,6 +16,7 @@ using System.IO.Compression; using System.IO; using BarrageGrab.Modles.JsonEntity; using BarrageGrab.Modles.ProtoEntity; +using System.Drawing; namespace BarrageGrab { @@ -23,7 +24,7 @@ namespace BarrageGrab /// 弹幕服务 /// public class WsBarrageService - { + { WebSocketServer socketServer; Dictionary socketList = new Dictionary(); //礼物计数缓存 @@ -45,6 +46,16 @@ namespace BarrageGrab /// public string ServerLocation { get { return socketServer.Location; } } + /// + /// 数据内核 + /// + public WssBarrageGrab Grab { get { return grab; } } + + /// + /// 控制台打印事件 + /// + public event EventHandler OnPrint; + public WsBarrageService() { #if DEBUG @@ -128,10 +139,7 @@ namespace BarrageGrab static int count = 0; private void PrintMsg(Msg msg, PackMsgType barType) - { - if (!Appsetting.PrintBarrage) return; - if (Appsetting.Current.PrintFilter.Any() && !Appsetting.Current.PrintFilter.Contains(barType.GetHashCode())) return; - + { var rinfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString()); var roomName = (rinfo?.Owner?.Nickname ?? ("直播间" + (msg.WebRoomId == 0 ? msg.RoomId : msg.WebRoomId))); var text = $"{DateTime.Now.ToString("HH:mm:ss")} [{roomName}] [{barType}]"; @@ -141,30 +149,39 @@ namespace BarrageGrab text += $" [{msg.User?.GenderToString()}] "; } - ConsoleColor color = ConsoleColor.White; + ConsoleColor color = Appsetting.Current.ColorMap[barType].Item1; var append = msg.Content; switch (barType) { - case PackMsgType.弹幕消息: color = ConsoleColor.White; append = $"{msg?.User?.Nickname}: {msg.Content}"; break; - case PackMsgType.点赞消息: color = ConsoleColor.Cyan; break; - case PackMsgType.进直播间: color = ConsoleColor.Green; break; - case PackMsgType.关注消息: color = ConsoleColor.Yellow; break; - case PackMsgType.礼物消息: color = ConsoleColor.Red; break; - case PackMsgType.直播间统计: color = ConsoleColor.Magenta; break; - case PackMsgType.粉丝团消息: color = ConsoleColor.Blue; break; - case PackMsgType.直播间分享: color = ConsoleColor.DarkBlue; break; - case PackMsgType.下播: color = ConsoleColor.DarkCyan; append = $"直播已结束"; break; + case PackMsgType.弹幕消息:append = $"{msg?.User?.Nickname}: {msg.Content}"; break; + case PackMsgType.下播:append = $"直播已结束"; break; default: break; } + text += append; + if (Appsetting.Current.BarrageLog) + { + Logger.LogBarrage(barType, msg); + } + + if (!Appsetting.PrintBarrage) return; + if (Appsetting.Current.PrintFilter.Any() && !Appsetting.Current.PrintFilter.Contains(barType.GetHashCode())) return; + + OnPrint?.Invoke(this, new PrintEventArgs() + { + Color = color, + Message = text, + MsgType = barType + }); + if (++count > 10000) { Console.Clear(); Console.WriteLine("控制台已清理"); count = 0; } - console.WriteLine(text + "\n", color); + console.WriteLine(text + "\n", color); } //粉丝团 @@ -528,6 +545,8 @@ namespace BarrageGrab public void Broadcast(BarrageMsgPack pack) { if (pack == null) return; + if (Appsetting.Current.PushFilter.Any() && !Appsetting.Current.PushFilter.Contains(pack.Type.GetHashCode())) return; + var offLines = new List(); foreach (var item in socketList) { @@ -588,5 +607,14 @@ namespace BarrageGrab Socket = socket; } } + + public class PrintEventArgs : EventArgs + { + public string Message { get; set; } + + public ConsoleColor Color { get; set; } + + public PackMsgType MsgType { get; set; } + } } } diff --git a/BarrageGrab/WssBarrageGrab.cs b/BarrageGrab/WssBarrageGrab.cs index f8d21ae..89631c1 100644 --- a/BarrageGrab/WssBarrageGrab.cs +++ b/BarrageGrab/WssBarrageGrab.cs @@ -280,7 +280,7 @@ namespace BarrageGrab break; } } - catch (Exception) + catch (Exception ex) { return; } diff --git a/BarrageGrab/WssBarrageService.csproj b/BarrageGrab/WssBarrageService.csproj index 5f3a8d2..7ca0c5b 100644 --- a/BarrageGrab/WssBarrageService.csproj +++ b/BarrageGrab/WssBarrageService.csproj @@ -139,12 +139,19 @@ - + Form - + FormView.cs + + + Form + + + RoomDetail.cs + @@ -153,8 +160,9 @@ - - + + + @@ -190,9 +198,12 @@ - + FormView.cs + + RoomDetail.cs + \ No newline at end of file