From ab5a9944af04d430cbb181571c55401e1ad8fe34 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 11 Apr 2021 23:09:07 +0800 Subject: [PATCH] =?utf8?q?=E4=B8=A4=E6=AC=A1ctrl+c=E5=BC=BA=E5=88=B6?= =?utf8?q?=E9=80=80=E5=87=BA=20=E7=BD=91=E7=BB=9C=E4=B8=AD=E6=96=AD?= =?utf8?q?=E4=BF=9D=E6=8C=81=E4=B8=8D=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- F/api.go | 28 ++++++++++++++++++++++++++++ Reply/F.go | 4 ++-- bili_danmu.go | 36 ++++++++++++++++++++++++------------ demo/config/config_K_v.json | 3 ++- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/F/api.go b/F/api.go index 25fd6da..7be40cb 100644 --- a/F/api.go +++ b/F/api.go @@ -2242,3 +2242,31 @@ func GetHistory(Roomid_int int) (j J.GetHistory) { } return } + +func KeepConnect() (o bool) { + for !IsConnected() { + o = true + time.Sleep(time.Duration(30)*time.Second) + } + return +} + +func IsConnected() bool { + apilog := apilog.Base_add(`IsConnected`) + + v,ok := c.K_v.LoadV(`网络中断不退出`).(bool) + if !ok || !v {return true} + + req := reqf.Req() + if err := req.Reqf(reqf.Rval{ + Url:"https://www.bilibili.com", + Timeout:10, + JustResponseCode:true, + });err != nil { + apilog.L(`W: `,`网络中断`,err) + return false + } + + apilog.L(`T: `,`已连接`) + return true +} \ No newline at end of file diff --git a/Reply/F.go b/Reply/F.go index d6d3521..259930b 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -316,8 +316,8 @@ func Saveflvf(){ if e := rr.Reqf(reqf.Rval{ Url:c.Live[cuLinkIndex], - Retry:10, - SleepTime:5, + Retry:3, + SleepTime:3, Header:map[string]string{ `Cookie`:reqf.Map_2_Cookies_String(CookieM), }, diff --git a/bili_danmu.go b/bili_danmu.go index a8bb11c..43ffa45 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -13,7 +13,7 @@ import ( send "github.com/qydysky/bili_danmu/Send" c "github.com/qydysky/bili_danmu/CV" F "github.com/qydysky/bili_danmu/F" - + p "github.com/qydysky/part" ws "github.com/qydysky/part/websocket" msgq "github.com/qydysky/part/msgq" @@ -38,8 +38,16 @@ func Demo(roomid ...int) { defer danmulog.Block(1000) //ctrl+c退出 - interrupt := make(chan os.Signal, 1) - + interrupt := make(chan os.Signal,2) + go func(){ + danmulog.L(`T: `, "两次ctrl+c强制退出") + for len(interrupt) < 2 { + time.Sleep(time.Second*3) + } + danmulog.L(`I: `, "强制退出!").Block(1000) + os.Exit(1) + }() + { var groomid = flag.Int("r", 0, "roomid") flag.Parse() @@ -78,7 +86,6 @@ func Demo(roomid ...int) { c.Uname = ``//主播id c.Title = `` c.Wearing_FansMedal = 0 - reply.Saveflv_wait()//停止保存直播流 for len(change_room_chan) != 0 {<-change_room_chan} change_room_chan <- struct{}{} return false @@ -110,6 +117,10 @@ func Demo(roomid ...int) { <-change_room_chan + //捕获ctrl+c退出 + signal.Notify(interrupt, os.Interrupt) + //如果连接中断,则等待 + F.KeepConnect() //获取cookie F.Get(`Cookie`) //获取uid @@ -127,14 +138,16 @@ func Demo(roomid ...int) { //附加功能 自动发送即将过期礼物 go reply.AutoSend_silver_gift() - //捕获ctrl+c退出 - signal.Notify(interrupt, os.Interrupt) - var exit_sign = 2 for exit_sign > 0 { exit_sign -= 1 danmulog.L(`T: `,"准备") + //如果连接中断,则等待 + if F.KeepConnect() { + //成功保持连接 + exit_sign = 2 + } //获取热门榜 F.Get(`Note`) @@ -282,15 +295,14 @@ func Demo(roomid ...int) { if break_sign {break} } - + {//附加功能 直播流停止 + reply.Saveflv_wait() + reply.Save_to_json(-1, []interface{}{`{}]`}) + } p.Sys().Timeoutf(1) } close(interrupt) - {//附加功能 直播流 - reply.Saveflv_wait() - reply.Save_to_json(-1, []interface{}{`{}]`}) - } danmulog.L(`I: `,"结束退出") } } diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index accf0a9..fb03596 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -66,5 +66,6 @@ "cookie解密私钥": "private.pem", "扫码登录-help": "当扫码登陆设置为true时,每次启动会检查,若失败则会要求登录", "扫码登录": true, - "扫码登录自动打开标签页": false + "扫码登录自动打开标签页": false, + "网络中断不退出": true } \ No newline at end of file -- 2.39.2