]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
修复不能点亮牌子的问题,小心心响应超时不退出
authorqydysky <qydysky@foxmail.com>
Thu, 8 Apr 2021 07:15:28 +0000 (15:15 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 8 Apr 2021 07:15:28 +0000 (15:15 +0800)
F/api.go
Json/gethistory.go [new file with mode: 0644]
Reply/F.go
demo/config/config_K_v.json

index 1e276df9db9f338664144247740c93e0c3f664b0..5369528a51a0c266a969de27fbfcd9b98474d085 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -9,6 +9,7 @@ import (
        "encoding/json"
        "net/http"
        "net/url"
+       "errors"
 
        "github.com/skratchdot/open-golang/open"
        qr "github.com/skip2/go-qrcode"
@@ -1657,8 +1658,6 @@ func F_x25Kn() {
        }
 
        {//初始化
-               //新调用,此退出
-               if boot_F_x25Kn.NeedExit(id) {return}
 
                PostStr := `id=[`+strconv.Itoa(c.ParentAreaID)+`,`+strconv.Itoa(c.AreaID)+`,`+strconv.Itoa(loop_num)+`,`+strconv.Itoa(c.Roomid)+`]&`
                PostStr += `device=["`+LIVE_BUVID+`","`+new_uuid+`"]&`
@@ -1676,28 +1675,39 @@ func F_x25Kn() {
                })
 
                req := p.Req()
-               if err := req.Reqf(p.Rval{
-                       Url:`https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/E`,
-                       Header:map[string]string{
-                               `Host`: `api.live.bilibili.com`,
-                               `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
-                               `Accept`: `application/json, text/plain, */*`,
-                               `Content-Type`: `application/x-www-form-urlencoded`,
-                               `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
-                               `Accept-Encoding`: `gzip, deflate, br`,
-                               `Origin`: `https://live.bilibili.com`,
-                               `Connection`: `keep-alive`,
-                               `Pragma`: `no-cache`,
-                               `Cache-Control`: `no-cache`,
-                               `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
-                       },
-                       PostStr:url.PathEscape(PostStr),
-                       Timeout:3,
-                       Retry:2,
-               });err != nil {
-                       apilog.L(`E: `,err)
-                       return
+               for {
+                       //新调用,此退出
+                       if boot_F_x25Kn.NeedExit(id) {return}
+
+                       if err := req.Reqf(p.Rval{
+                               Url:`https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/E`,
+                               Header:map[string]string{
+                                       `Host`: `api.live.bilibili.com`,
+                                       `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
+                                       `Accept`: `application/json, text/plain, */*`,
+                                       `Content-Type`: `application/x-www-form-urlencoded`,
+                                       `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
+                                       `Accept-Encoding`: `gzip, deflate, br`,
+                                       `Origin`: `https://live.bilibili.com`,
+                                       `Connection`: `keep-alive`,
+                                       `Pragma`: `no-cache`,
+                                       `Cache-Control`: `no-cache`,
+                                       `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
+                                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               },
+                               PostStr:url.PathEscape(PostStr),
+                               Timeout:3,
+                               Retry:2,
+                       });err != nil {
+                               if !errors.Is(err, context.DeadlineExceeded) {
+                                       apilog.L(`E: `,err)
+                                       return
+                               }
+                               apilog.L(`W: `,`响应超时,1min后重试`)
+                               time.Sleep(time.Minute)
+                       } else {
+                               break
+                       }
                }
 
                if e := json.Unmarshal(req.Respon,&res);e != nil {
@@ -1795,6 +1805,11 @@ func F_x25Kn() {
                                Timeout:3,
                                Retry:2,
                        });err != nil {
+                               if errors.Is(err, context.DeadlineExceeded) {
+                                       loop_num -= 1
+                                       apilog.L(`W: `,`响应超时,将重试`)
+                                       continue
+                               }
                                apilog.L(`E: `,err)
                                return
                        }
@@ -2174,4 +2189,37 @@ func Feed_list() (Uplist []UpItem) {
 
        apilog.L(`T: `,`完成`)
        return
-}
\ No newline at end of file
+}
+
+func GetHistory(Roomid_int int) (j J.GetHistory) {
+       apilog := apilog.Base_add(`GetHistory`)
+
+       Roomid := strconv.Itoa(Roomid_int)
+
+       {//使用其他api
+               req := p.Req()
+               if err := req.Reqf(p.Rval{
+                       Url:"https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid=" + Roomid,
+                       Header:map[string]string{
+                               `Referer`:"https://live.bilibili.com/" + Roomid,
+                       },
+                       Timeout:10,
+                       Retry:2,
+               });err != nil {
+                       apilog.L(`E: `,err)
+                       return
+               }
+
+               //GetHistory
+               {
+                       if e := json.Unmarshal(req.Respon,&j);e != nil{
+                               apilog.L(`E: `, e)
+                               return
+                       } else if j.Code != 0 {
+                               apilog.L(`E: `, j.Message)
+                               return
+                       }
+               }
+       }
+       return
+}
diff --git a/Json/gethistory.go b/Json/gethistory.go
new file mode 100644 (file)
index 0000000..f09b19d
--- /dev/null
@@ -0,0 +1,35 @@
+package part
+
+type GetHistory struct {
+       Code int `json:"code"`
+       Data struct {
+               Admin []interface{} `json:"admin"`
+               Room  []struct {
+                       Text        string        `json:"text"`
+                       UID         int           `json:"uid"`
+                       Nickname    string        `json:"nickname"`
+                       UnameColor  string        `json:"uname_color"`
+                       Timeline    string        `json:"timeline"`
+                       Isadmin     int           `json:"isadmin"`
+                       Vip         int           `json:"vip"`
+                       Svip        int           `json:"svip"`
+                       Medal       []interface{} `json:"medal"`
+                       Title       []string      `json:"title"`
+                       UserLevel   []interface{} `json:"user_level"`
+                       Rank        int           `json:"rank"`
+                       Teamid      int           `json:"teamid"`
+                       Rnd         string        `json:"rnd"`
+                       UserTitle   string        `json:"user_title"`
+                       GuardLevel  int           `json:"guard_level"`
+                       Bubble      int           `json:"bubble"`
+                       BubbleColor string        `json:"bubble_color"`
+                       CheckInfo   struct {
+                               Ts int    `json:"ts"`
+                               Ct string `json:"ct"`
+                       } `json:"check_info"`
+                       Lpl int `json:"lpl"`
+               } `json:"room"`
+       } `json:"data"`
+       Message string `json:"message"`
+       Msg     string `json:"msg"`
+} 
index 7e3ab23f705ae121b8812ad407fd2d5dd2a32a5f..e7619f05695c813a91f70b34874342869611b33d 100644 (file)
@@ -784,8 +784,9 @@ func Entry_danmu(){
                        return
                }
        }
-       if s,ok := c.K_v.LoadV(`进房弹幕_内容`).(string);ok && s != ``{
-               send.Danmu_s(s, c.Roomid)
+       if array,ok := c.K_v.LoadV(`进房弹幕_内容`).([]interface{});ok && len(array) != 0{
+               rand := p.Rand().MixRandom(0,int64(len(array)-1))
+               send.Danmu_s(array[rand].(string), c.Roomid)
        }
 }
 
@@ -796,11 +797,11 @@ func Keep_medal_light() {
        }
        flog := flog.Base_add(`保持亮牌`)
 
-       var sendStr string
-       if s,ok := c.K_v.LoadV(`进房弹幕_内容`).(string);!ok || s == ``{
+       array,ok := c.K_v.LoadV(`进房弹幕_内容`).([]interface{})
+       if !ok || len(array) == 0{
                flog.L(`I: `,`进房弹幕_内容 为 空,退出`)
                return
-       } else {sendStr = s}
+       }
 
        flog.L(`T: `,`开始`)
 
@@ -812,17 +813,29 @@ func Keep_medal_light() {
 
                info := F.Info(v.Target_id)
                //两天内到期,发弹幕续期
-               send.Danmu_s(sendStr, info.Data.LiveRoom.Roomid)
+               rand := p.Rand().MixRandom(0,int64(len(array)-1))
+               send.Danmu_s(array[rand].(string), info.Data.LiveRoom.Roomid)
                time.Sleep(time.Second)
        }
 
-       //recheck
+       //重试,使用历史弹幕
        for _,v := range F.Get_list_in_room() {
                if t := int64(v.Last_wear_time) - time.Now().Unix();t > 60*60*24*2 || t < 0{continue}//到期时间在2天以上或已过期
 
                info := F.Info(v.Target_id)
-               //两天内到期,发弹幕续期,使用随机字符
-               send.Danmu_s(sendStr+p.Stringf().Rand(2,2),info.Data.LiveRoom.Roomid)
+               //两天内到期,发弹幕续期
+               var Str string
+               for _,v := range F.GetHistory(info.Data.LiveRoom.Roomid).Data.Room{
+                       if v.Text != "" {
+                               Str = v.Text
+                               break
+                       }
+               }
+               if Str == "" {
+                       rand := p.Rand().MixRandom(0,int64(len(array)-1))
+                       Str = array[rand].(string)
+               }
+               send.Danmu_s(Str,info.Data.LiveRoom.Roomid)
                time.Sleep(time.Second)
        }
 
index 740aae62c602f0e4d92f19e8c5f4faf83768f677..9cf1068dfd897caa1ef9d680509147e0793e8b30 100644 (file)
@@ -1,65 +1,67 @@
 {
-    "私信-help":"额外私信对象为0时,所有额外私信都不会触发;私信为空字符串时,不触发",
-    "额外私信对象":0,
-    "上舰私信":"",
-    "上舰私信(额外)":"[弹幕机测试 额外]:感谢上舰",
-    "弹幕私信":"",
-    "弹幕私信(额外)":"[弹幕机测试 额外]:弹幕",
-
-    "TTS_配置-help":"将会运行[TTS_使用程序路径 获取的音频路径 TTS_使用程序参数]",
-    "TTS_总开关":false,
-    "TTS_使用程序路径":"ffplay",
-    "TTS_使用程序参数":"-autoexit -nodisp -volume 60",
-
-    "弹幕-help":"弹幕相关",
-    "弹幕_礼物金额显示阈值":20,
-
-    "gtk":"GTK相关",
-    "gtk_保留弹幕数量":25,
-    "gtk_内存头像数量":30,
-    "gtk_头像获取等待最大数量":30,
-
-    "save_to_json-help":"保存消息设置,将所有消息保存为json文件,输入文件名(带后缀)",
-    "save_to_json":"",
-
-    "get_xiao_xinxin-help":"获取小心心",
-    "get_xiao_xinxin":true,
-
-    "进房弹幕-help":"进入房间发送弹幕,单空格似乎被屏蔽了",
-    "进房弹幕_内容":"打卡",
-    "进房弹幕_有粉丝牌时才发":true,
-    "进房弹幕_仅发首日弹幕":true,
-
-    "其他":"",
-    "发送还有几天过期的礼物":3,
-    "保持牌子亮着":true,
-    "日志显示":["I: ","W: ","E: "],
-    "统计营收":true,
-    "Gtk弹幕窗":true,
-    "调用obs":false,
-    
-    "直播流清晰度-help":"清晰度可选-1:不保存 0:默认 10000:原画 800:4K 401:蓝光(杜比) 400:蓝光 250:超清 150:高清 80:流畅,无提供所选清晰度时,使用低一档清晰度",
-    "flv直播流清晰度":150,
-    "ass-help":"只有保存直播流时才考虑生成ass",
-    "生成Ass弹幕":true,
-
-    "弹幕处理":"",
-    "弹幕合并":true,
-    "相似弹幕忽略":true,
-    "精简弹幕":true,
-
-    "弹幕机":"",
-    "反射弹幕机":true,
-    "自动弹幕机":false,
-    "自动弹幕机-help":"间隔最小5s,空字符串不会发送但仍会等待",
-    "自动弹幕机_内容":["hhh",""],
-    "自动弹幕机_发送间隔s":30,
-
-    "cookie保护":"下填路径",
-    "cookie加密公钥":"public.pem",
-    "cookie解密私钥":"private.pem",
-
-    "扫码登录-help":"当扫码登陆设置为true时,每次启动会检查,若失败则会要求登录",
-    "扫码登录":true,
-    "扫码登录自动打开标签页":true
+    "私信-help": "额外私信对象为0时,所有额外私信都不会触发;私信为空字符串时,不触发",
+    "额外私信对象": 0,
+    "上舰私信": "",
+    "上舰私信(额外)": "[弹幕机测试 额外]:感谢上舰",
+    "弹幕私信": "",
+    "弹幕私信(额外)": "[弹幕机测试 额外]:弹幕",
+    "TTS_配置-help": "将会运行[TTS_使用程序路径 获取的音频路径 TTS_使用程序参数]",
+    "TTS_总开关": false,
+    "TTS_使用程序路径": "ffplay",
+    "TTS_使用程序参数": "-autoexit -nodisp -volume 60",
+    "弹幕-help": "弹幕相关",
+    "弹幕_礼物金额显示阈值": 20,
+    "gtk": "GTK相关",
+    "gtk_保留弹幕数量": 25,
+    "gtk_内存头像数量": 30,
+    "gtk_头像获取等待最大数量": 30,
+    "save_to_json-help": "保存消息设置,将所有消息保存为json文件,输入文件名(带后缀)",
+    "save_to_json": "",
+    "get_xiao_xinxin-help": "获取小心心",
+    "get_xiao_xinxin": true,
+    "进房弹幕-help": "进入房间发送弹幕,似乎屏蔽了一些字符",
+    "进房弹幕_内容": [
+        "(`・ω・´)",
+        "(〜 ̄△ ̄)〜",
+        "(・∀・)",
+        "(⌒▽⌒)",
+        "( ̄▽ ̄)",
+        "(=・ω・=)"
+    ],
+    "进房弹幕_有粉丝牌时才发": true,
+    "进房弹幕_仅发首日弹幕": true,
+    "其他": "",
+    "发送还有几天过期的礼物": 3,
+    "保持牌子亮着": true,
+    "日志显示": [
+        "I: ",
+        "W: ",
+        "E: "
+    ],
+    "统计营收": true,
+    "Gtk弹幕窗": false,
+    "调用obs": false,
+    "直播流清晰度-help": "清晰度可选-1:不保存 0:默认 10000:原画 800:4K 401:蓝光(杜比) 400:蓝光 250:超清 150:高清 80:流畅,无提供所选清晰度时,使用低一档清晰度",
+    "flv直播流清晰度": 150,
+    "ass-help": "只有保存直播流时才考虑生成ass",
+    "生成Ass弹幕": true,
+    "弹幕处理": "",
+    "弹幕合并": true,
+    "相似弹幕忽略": true,
+    "精简弹幕": true,
+    "弹幕机": "",
+    "反射弹幕机": true,
+    "自动弹幕机": false,
+    "自动弹幕机-help": "间隔最小5s,空字符串不会发送但仍会等待",
+    "自动弹幕机_内容": [
+        "hhh",
+        ""
+    ],
+    "自动弹幕机_发送间隔s": 30,
+    "cookie保护": "下填路径",
+    "cookie加密公钥": "public.pem",
+    "cookie解密私钥": "private.pem",
+    "扫码登录-help": "当扫码登陆设置为true时,每次启动会检查,若失败则会要求登录",
+    "扫码登录": true,
+    "扫码登录自动打开标签页": true
 }
\ No newline at end of file