diff --git a/Auxiliary/DDcenter/DdcClient.cs b/Auxiliary/DDcenter/DdcClient.cs index 62d8f0ec8..1e69f1905 100644 --- a/Auxiliary/DDcenter/DdcClient.cs +++ b/Auxiliary/DDcenter/DdcClient.cs @@ -19,7 +19,7 @@ public static void Connect() { try { - MMPU.DDC采集间隔 = int.Parse(MMPU.TcpSend(30001, "{}", true,50)); + MMPU.DDC采集间隔 = int.Parse(MMPU.TcpSend(Server.RequestCode.GET_DDC_TIME_NUMBER, "{}", true,50)); } catch (Exception) { diff --git a/Auxiliary/Downloader.cs b/Auxiliary/Downloader.cs index af20acf20..46303bbbb 100644 --- a/Auxiliary/Downloader.cs +++ b/Auxiliary/Downloader.cs @@ -23,7 +23,7 @@ public class Downloader /// /// 关闭直播流和弹幕储存流 /// - public void Clear(bool 续命模式, DownIofoData DOL) + public static void Clear(bool 续命模式, DownIofoData DOL) { DOL.备注 = "下载任务结束"; DOL.下载状态 = false; @@ -66,6 +66,8 @@ public class DownIofoData public WebClient WC { set; get; } public bool 下载状态 { set; get; } = false; + public int 最后连接时间 { set; get; } = 0; + public bool 网络超时 { set; get; } = false; public double 已下载大小bit { set; get; } public string 已下载大小str { set; get; } public string 文件保存路径 { set; get; } @@ -91,8 +93,58 @@ public class 继承 public string 继承的下载文件路径 { set; get; } = null; public string 合并后的文件路径 { set; get; } = null; } + public static bool 轮询检查下载任务开关 = true; + public static void 轮询检查下载任务() + { + new Task(()=> { + while (true) + { + while (轮询检查下载任务开关) + { + try + { + if (!string.IsNullOrEmpty(MMPU.TcpSend(Server.RequestCode.GET_IP, "{}", true, 50, 5000))) + { + 下载任务状态检测(); + } + else + { + + } + } + catch (Exception) + { } + Thread.Sleep(60 * 1000); + } + Thread.Sleep(500); + } + }).Start(); + } + public static void 下载任务状态检测() + { + foreach (var item in MMPU.DownList) + { + if(item.DownIofo.下载状态&&item.DownIofo.已下载大小bit>10000&& item.DownIofo.最后连接时间!=0&& Gettime()-item.DownIofo.最后连接时间>120) + { + InfoLog.InfoPrintf(item.DownIofo.房间_频道号 + "下载状态异常,重置下载任务", InfoLog.InfoClass.下载必要提示); + item.DownIofo.网络超时 = true; + item.DownIofo.备注 = "下载状态异常,重置下载任务"; + Clear(true, item.DownIofo); + item.DownIofo.下载状态 = false; + item.DownIofo.结束时间 = Convert.ToInt32((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds); + item.DownIofo.WC.CancelAsync(); + new Task(() => + { + Downloader DLL = Downloader.新建下载对象(item.DownIofo.平台, item.DownIofo.房间_频道号, bilibili.根据房间号获取房间信息.获取标题(item.DownIofo.标题), Guid.NewGuid().ToString(), bilibili.根据房间号获取房间信息.下载地址(item.DownIofo.标题), "下载状态异常,重置下载任务", item.DownIofo.是否保存, item.DownIofo.主播名称, false, null); + }).Start(); + } + } + } + + public string Start(string 开始后显示的备注) { + DownIofo.开始时间 = Gettime(); MMPU.DownList.Add(this); int a = 0; DownIofo.WC = new WebClient(); @@ -386,9 +438,15 @@ public static Downloader 新建下载对象(string 平台, string 唯一码, str return 下载对象; } + public static int Gettime() + { + int time = (int)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds; + return time; + } private void 下载过程中事件(object sender, DownloadProgressChangedEventArgs e) { var bytes = e.BytesReceived; + DownIofo.最后连接时间 = Gettime(); DownIofo.已下载大小bit = bytes; DownIofo.已下载大小str = 转换下载大小数据格式(bytes); } @@ -404,7 +462,7 @@ private void 下载完成事件(object sender, AsyncCompletedEventArgs e) //DownIofo.下载状态 = true; DownIofo.结束时间 = Convert.ToInt32((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds); DownIofo.备注 = "下载任务结束"; - if (e.Cancelled) + if (e.Cancelled&&!DownIofo.网络超时) { if (!DownIofo.播放状态 && DownIofo.是否是播放任务) diff --git a/Auxiliary/InfoLog.cs b/Auxiliary/InfoLog.cs index ee31c861c..7f3b7b61e 100644 --- a/Auxiliary/InfoLog.cs +++ b/Auxiliary/InfoLog.cs @@ -218,7 +218,7 @@ public static string GetSystemInfo() BB += $"
当前DDTVLiveRec核心版本:{MMPU.版本号}"; if(MMPU.是否有新版本) { - BB += "
检测到云端有新版本。如需更新,请上github或到" + + BB += "
检测到云端有新版本。如需更新,请上github或加307156949" + "\"每天都是单推的一天\"群共享下载"; } BB += $"

---运行状态---
下载中:{下载中}个 下载完成:{下载完成}个"; diff --git a/Auxiliary/MMPU.cs b/Auxiliary/MMPU.cs index 4209a4466..c2ad60faa 100644 --- a/Auxiliary/MMPU.cs +++ b/Auxiliary/MMPU.cs @@ -79,8 +79,10 @@ public class MMPU public static bool Debug输出到文件 = false; public static bool Debug打印到终端 = false; public static bool 强制WSS连接模式 = false; + public static int 心跳打印间隔 = 180; public static int 启动模式 = 0;//0:DDTV,1:DDTVLive + public static bool 网络环境变动监听 = true;//0:DDTV,1:DDTVLive /// /// 配置文件初始化 @@ -89,9 +91,11 @@ public class MMPU public static bool 配置文件初始化(int 模式) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //加上这一句 - Debug模式 = MMPU.读取exe默认配置文件("DebugMod", "1") == "0" ? false : true; - Debug输出到文件 = MMPU.读取exe默认配置文件("DebugFile", "1") == "0" ? false : true; - Debug打印到终端 = MMPU.读取exe默认配置文件("DebugCmd", "0") == "0" ? false : true; + Debug模式 = 读取exe默认配置文件("DebugMod", "1") == "0" ? false : true; + Debug输出到文件 = 读取exe默认配置文件("DebugFile", "1") == "0" ? false : true; + Debug打印到终端 = 读取exe默认配置文件("DebugCmd", "0") == "0" ? false : true; + 心跳打印间隔 = int.Parse(读取exe默认配置文件("DokiDoki", "180")); + 网络环境变动监听 = 读取exe默认配置文件("NetStatusMonitor", "1") == "0" ? false : true; if (模式 == 0) { InfoLog.InfoInit("./DDTVLog.out", new InfoLog.InfoClasslBool() @@ -196,6 +200,7 @@ public static bool 配置文件初始化(int 模式) VTBS.API.VTBS服务器CDN.根据CDN更新VTBS_Url(); RoomInit.start(); DokiDoki(模式); + Downloader.轮询检查下载任务(); return true; } /// @@ -204,7 +209,7 @@ public static bool 配置文件初始化(int 模式) /// public static void DokiDoki(int 模式) { - + ///心跳检查 new Thread(new ThreadStart(delegate { while (true) { @@ -217,16 +222,22 @@ public static void DokiDoki(int 模式) } })).Start(); string LIP = string.Empty; + try + { + LIP = MMPU.TcpSend(Server.RequestCode.GET_IP, "{}", true, 50); + } + catch (Exception){} int Num = 0; + ///网络状态检查 new Thread(new ThreadStart(delegate { - while (true) + while (网络环境变动监听) { Num++; try { - string NIP = MMPU.TcpSend(模式 == 0 ? Server.RequestCode.SET_DokiDoki_DDTV : Server.RequestCode.SET_DokiDoki_DDTVLiveRec, "{}", true, 50); - if (Num > 10) + string NIP = MMPU.TcpSend(Server.RequestCode.GET_IP, "{}", true, 50); + if (Num > 3) { if (LIP != NIP&& IsCorrectIP(LIP)&& IsCorrectIP(NIP)) { @@ -264,9 +275,28 @@ public static void DokiDoki(int 模式) } } catch (Exception) { } - Thread.Sleep(3600 * 1000); + Thread.Sleep(30 * 1000); } })).Start(); + new Task(()=> { + while(true) + { + try + { + int 下载中 = 0; + foreach (var item in DownList) + { + if (item.DownIofo.下载状态) + { + 下载中++; + } + } + InfoLog.InfoPrintf($"[DDTVLR心跳信息]临时API监控房间数:{RoomList.Count - 已连接的直播间状态.Count},WSS长连接数:{已连接的直播间状态.Count},{下载中}个下载中", InfoLog.InfoClass.下载必要提示); + } + catch (Exception){} + Thread.Sleep(60*1000); + } + }).Start(); } public static void BiliUser配置文件初始化(int 模式) { @@ -1151,7 +1181,7 @@ public static bool setFiles(string key, string value) /// 消息内容 /// /// - public static string TcpSend(int code, string msg, bool 是否需要回复,int 等待时间) + public static string TcpSend(int code, string msg, bool 是否需要回复,int 等待时间,int 超时时间 = 0) { try { @@ -1160,6 +1190,7 @@ public static string TcpSend(int code, string msg, bool 是否需要回复,int tcpClient.ReceiveBufferSize = 1024 * 1024 * 8; IPAddress ipaddress = Server.IP_ADDRESS; EndPoint point = new IPEndPoint(ipaddress, Server.PORT); + tcpClient.SendTimeout = 超时时间; tcpClient.Connect(point);//通过IP和端口号来定位一个所要连接的服务器端 tcpClient.Send(Encoding.UTF8.GetBytes(JSON发送拼接(code, msg))); if (是否需要回复) @@ -1276,7 +1307,11 @@ public static string 返回网页内容(string url, Dictionary d /// public static bool IsCorrectIP(string ip) { - return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); + bool b = Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); + if (b) + return b; + else + return b; } public class UA diff --git a/Auxiliary/Server.cs b/Auxiliary/Server.cs index 9d00cd556..e6318603a 100644 --- a/Auxiliary/Server.cs +++ b/Auxiliary/Server.cs @@ -28,12 +28,14 @@ public static class RequestCode public static readonly int GET_DYNAMIC_NOTIFICATION = 20010; public static readonly int GET_LATEST_VERSION_NUMBER = 20011; public static readonly int GET_UPDATE_ANNOUNCEMENT = 20012; + public static readonly int GET_VER = 20013; + public static readonly int GET_VERTEXT = 20014; public static readonly int GET_LIVELSIT = 20016; public static readonly int GET_VTBSROOMLIST = 20017; public static readonly int GET_DDC_TIME_NUMBER = 30001; public static readonly int SET_DokiDoki_DDTV = 40001; public static readonly int SET_DokiDoki_DDTVLiveRec = 40002; - public static readonly int SET_GETIP = 50001; + public static readonly int GET_IP = 50001; } } } diff --git a/Auxiliary/bilibili.cs b/Auxiliary/bilibili.cs index ff4dad3c1..dc152cd8a 100644 --- a/Auxiliary/bilibili.cs +++ b/Auxiliary/bilibili.cs @@ -277,13 +277,15 @@ public static void 使用vtbsAPI更新房间状态() } catch (Exception) { - InfoLog.InfoPrintf("备用缓存数据加载失败,使用原生阿Bapi开始获取开始获取", InfoLog.InfoClass.Debug); - 使用B站API更新房间状态(); - } - + if(!string.IsNullOrEmpty(MMPU.TcpSend(Server.RequestCode.GET_IP, "{}", true, 50))) + { + InfoLog.InfoPrintf("备用缓存数据加载失败,使用原生阿Bapi开始获取开始获取", InfoLog.InfoClass.Debug); + 使用B站API更新房间状态(); + } + } } - if(C1!=0) - InfoLog.InfoPrintf("使用VTBS数据库加载数据量:"+C1.ToString()+"/"+C2.ToString(), InfoLog.InfoClass.Debug); + //if(C1!=0) + //InfoLog.InfoPrintf("使用VTBS数据库加载数据量:"+C1.ToString()+"/"+C2.ToString(), InfoLog.InfoClass.Debug); } public static void 使用B站API更新房间状态() { diff --git a/DDTVLiveRec/App.config b/DDTVLiveRec/App.config index 3f14829ac..1387c8200 100644 --- a/DDTVLiveRec/App.config +++ b/DDTVLiveRec/App.config @@ -34,7 +34,9 @@ - + + + diff --git a/DDTVLiveRec/Program.cs b/DDTVLiveRec/Program.cs index d5c616276..fc0b36ecf 100644 --- a/DDTVLiveRec/Program.cs +++ b/DDTVLiveRec/Program.cs @@ -23,7 +23,7 @@ static void Main(string[] args) { try { - string 服务器版本号 = MMPU.TcpSend(20013, "{}", true, 50); + string 服务器版本号 = MMPU.TcpSend(Server.RequestCode.GET_VER, "{}", true, 50); if (!string.IsNullOrEmpty(服务器版本号)) { bool 检测状态 = true; @@ -37,7 +37,7 @@ static void Main(string[] args) if (MMPU.版本号 != 服务器版本号 && 检测状态) { MMPU.是否有新版本 = true; - InfoLog.InfoPrintf("检测到版本更新,更新公告:\n" + MMPU.TcpSend(20014, "{}", true, 100) + "\n\n", InfoLog.InfoClass.下载必要提示); + InfoLog.InfoPrintf("检测到版本更新,更新公告:\n" + MMPU.TcpSend(Server.RequestCode.GET_VERTEXT, "{}", true, 100) + "\n\n", InfoLog.InfoClass.下载必要提示); //Console.ReadKey(); } }