]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
人气,舰长
authorqydysky <qydysky@foxmail.com>
Fri, 27 Nov 2020 10:30:20 +0000 (18:30 +0800)
committerqydysky <qydysky@foxmail.com>
Fri, 27 Nov 2020 10:30:40 +0000 (18:30 +0800)
CV/Var.go
F/api.go
Reply/Heartbeat.go
Reply/Msg.go
Reply/Reply.go
Reply/gtk.go
bili_danmu.go
demo/config/config_gtk_keep_key.json
demo/face/0tianxuan [new file with mode: 0644]
demo/ui/2.glade

index 67de52224659535d7446a0df5abf741f1303e765..a9240b8905c851bf18104a803594b5461954981e 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -13,6 +13,8 @@ var (
        Cookie string
        Title string
        Rev float64//营收
+       Renqi int//人气
+       GuardNum int//舰长数
        Live_Start_Time time.Time//直播开始时间
        Liveing bool//是否在直播
 )
index 8a8b5069004cb3aa9d5ad2addd51543d506aa846..ceb74b4799701fb70752c19ee4ed15fc196cb9d7 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -200,9 +200,11 @@ func (i *api) Get_live(qn ...string) (o *api) {
                        o.Live_status = live_status.(float64)
                        switch live_status.(float64) {
                        case 2:
+                               c.Liveing = false
                                apilog.W("轮播中")
                                return
                        case 0: //未直播
+                               c.Liveing = false
                                apilog.W("未在直播")
                                return
                        case 1:
@@ -353,14 +355,15 @@ func Get_face_src(uid string) (string) {
        return rface.(string) + `@58w_58h`
 }
 
+var user_score_map = make(map[string]float64)
 func (i *api) Get_OnlineGoldRank() {
        if i.Uid == 0 || c.Roomid == 0 {
                apilog.Base(1, "Get_OnlineGoldRank").E("i.Uid == 0 || c.Roomid == 0")
                return
        }
        var session_roomid = c.Roomid
-       var self_loop func(page int)(score float64)
-       self_loop = func(page int)(score float64){
+       var self_loop func(page int)
+       self_loop = func(page int){
                if page <= 0 || session_roomid != c.Roomid{return}
                // apilog.Base(1, "self_loop").E(page)
 
@@ -396,10 +399,11 @@ func (i *api) Get_OnlineGoldRank() {
                } else {
                        tmp_onlineNum := onlineNum.(float64)
                        if tmp_onlineNum == 0 {
-                               apilog.Base(1, "获取tmp_onlineNum").E("tmp_onlineNum", tmp_onlineNum)
+                               // apilog.Base(1, "获取tmp_onlineNum").E("tmp_onlineNum", tmp_onlineNum)
                                return
                        }
 
+                       var score = 0.0
                        if tmp_score_list := p.Json().GetArrayFrom(p.Json().GetValFromS(res, "data.OnlineRankItem"), "score");len(tmp_score_list) != 0 {
                                for _,v := range tmp_score_list {
                                        score += v.(float64)/10
@@ -410,10 +414,10 @@ func (i *api) Get_OnlineGoldRank() {
                                Data:score,
                        })
 
-                       if rank_list := p.Json().GetArrayFrom(p.Json().GetValFromS(res, "data.OnlineRankItem"), "userRank");len(rank_list) == 0 {
+                       if rank_list := p.Json().GetArrayFrom(p.Json().GetValFromS(res, "data.OnlineRankItem"), "userRank");rank_list == nil {
                                apilog.Base(1, "获取 rank_list").E("rank_list", len(rank_list))
                                return
-                       } else if rank_list[len(rank_list)-1].(float64) == tmp_onlineNum {
+                       } else if len(rank_list) == 0 {
                                // apilog.Base(1, "获取 rank_list").E("rank_list == tmp_onlineNum")
                                return
                        } else {
@@ -428,10 +432,52 @@ func (i *api) Get_OnlineGoldRank() {
 
        // apilog.Base(1, "获取score").E("score", self_loop(1))
        self_loop(1)
-       apilog.Base(1, "获取score").E("以往营收获取成功")
+       apilog.Base(1, "获取score").W("以往营收获取成功", c.Rev)
        // c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列
        //      Class:`c.Rev_add`,
        //      Data:self_loop(1),
        // })
        return
-}
\ No newline at end of file
+}
+
+func (i *api) Get_guardNum() {
+       if i.Uid == 0 || c.Roomid == 0 {
+               apilog.Base(1, "Get_guardNum").E("i.Uid == 0 || c.Roomid == 0")
+               return
+       }
+
+       req := p.Req()
+       if err := req.Reqf(p.Rval{
+               Url:`https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid=`+strconv.Itoa(c.Roomid)+`&page=1&ruid=`+strconv.Itoa(i.Uid)+`&page_size=29`,
+               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, */*`,
+                       `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),
+               },
+               Timeout:3,
+               Retry:2,
+       });err != nil {
+               apilog.Base(1, "获取guardNum").E(err)
+               return
+       }
+       res := string(req.Respon)
+       if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
+               apilog.Base(1, "获取guardNum").E("message", msg)
+               return
+       }
+       if num := p.Json().GetValFromS(res, "data.info.num");num == nil {
+               apilog.Base(1, "获取num").E("num", num)
+               return
+       } else {
+               c.GuardNum = int(num.(float64))
+               apilog.Base(1, "获取guardNum").W("舰长数获取成功", c.GuardNum)
+       }
+       return
+}
index f28019af8b253a185163b338baf1cde4c7064557..fb215c344155562f23a17e990f3826bb54e3a72a 100644 (file)
@@ -1,8 +1,6 @@
 package reply
 
 import (
-       "strconv"
-
        p "github.com/qydysky/part"
        F "github.com/qydysky/bili_danmu/F"
 )
@@ -14,13 +12,13 @@ import (
 var heartlog = p.Logf().New().Base(-1, "Heart.go").Open("danmu.log").Fileonly(true)
 
 //HeartBeat类型处理方法map
-var Heart_map = map[string]func(replyF, string) {
+var Heart_map = map[string]func(replyF, int) {
        "heartbeat":replyF.heartbeat,//人气
 }
 
 //HeartBeat类型,将人气4位byte转为字符串,并送到上述map指定的方法
 func Heart(b []byte){
-       s := strconv.Itoa(int(F.Btoi32(b, 0)))
+       s := int(F.Btoi32(b, 0))
        if F,ok := Heart_map["heartbeat"]; ok {
                var f replyF
                F(f, s);
index 1944654973b40218bfb56b6761eb647995fd3068..139c167a9adabffb00cba9fb851879e5326cde91 100644 (file)
@@ -12,6 +12,7 @@ var msglog = p.Logf().New().Base(-1, "Msg.go").Open("danmu.log").Level(1)
 
 //Msg类型数据处理方法map
 var Msg_map = map[string]func(replyF, string) {
+       `WIDGET_BANNER`:nil,//每日任务
        `ROOM_ADMINS`:nil,//房管列表
        `room_admin_entrance`:nil,
        `ONLINE_RANK_TOP3`:nil,
index 7112b1d4a7280260cd66edeffa1346ded4b6cdc2..4eb5eb5bc2eacf2170913acc38ecb9b09897de07 100644 (file)
@@ -72,7 +72,7 @@ func (replyF) anchor_lot_start(s string){
                Assf(fmt.Sprintln("天选之人", award_name, "开始"))
        }
        fmt.Println(sh...)
-       Gui_show(Itos(sh))
+       Gui_show(Itos(sh),`0tianxuan`)
 
        msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -101,7 +101,7 @@ func (replyF) anchor_lot_award(s string){
                Assf(fmt.Sprintln("天选之人", award_name, "结束"))
        }
        fmt.Println(sh...)
-       Gui_show(Itos(sh))
+       Gui_show(Itos(sh),`0tianxuan`)
 
        msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -125,10 +125,12 @@ func (replyF) user_toast_msg(s string){
                switch op_type.(float64) {
                case 1:
                        sh = append(sh, "购买了")
+                       c.GuardNum += 1
                case 2:
                        sh = append(sh, "续费了")
                case 3:
                        sh = append(sh, "自动续费了")
+                       c.GuardNum += 1
                default:
                        msglog.W(s)
                        sh = append(sh, op_type)
@@ -165,8 +167,12 @@ func (replyF) user_toast_msg(s string){
 }
 
 //HeartBeat-心跳用来传递人气值
-func (replyF) heartbeat(s string){
-       if s == "1" {return}//人气为1,不输出
+func (replyF) heartbeat(s int){
+       c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{
+               Class:`c.Renqi`,
+               Data:s,
+       })
+       // if s == "1" {return}//人气为1,不输出
        heartlog.I("当前人气", s)
 }
 
@@ -198,7 +204,7 @@ func (replyF) special_gift(s string){
                sh = append(sh, "节奏风暴", content, "¥ 100")
                c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列
                        Class:`c.Rev_add`,
-                       Data:100,
+                       Data:float64(100),
                })
        }
        {//额外
@@ -302,7 +308,7 @@ func (replyF) send_gift(s string){
        total_coin := p.Json().GetValFromS(s, "data.total_coin");
 
        var sh []interface{}
-       var allprice int64
+       var allprice float64
 
        if uname != nil {
                sh = append(sh, uname)
@@ -317,11 +323,11 @@ func (replyF) send_gift(s string){
                sh = append(sh, giftName)
        }
        if total_coin != nil {
-               allprice = int64(total_coin.(float64) / 1000)
-               sh = append(sh, "¥", allprice)
+               allprice = total_coin.(float64) / 1000
+               sh = append(sh, fmt.Sprintf("¥%.1f",allprice))
                c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列
                        Class:`c.Rev_add`,
-                       Data:total_coin.(float64) / 1000,
+                       Data:allprice,
                })
        }
 
@@ -432,8 +438,10 @@ func (replyF) super_chat_message(s string){
        if uname != nil {
                sh = append(sh, uname)
        }
+       logg := sh
        if price != nil {
                sh = append(sh, "¥", price, "\n")
+               logg = append(logg, "¥", price)
                c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列
                        Class:`c.Rev_add`,
                        Data:price.(float64),
@@ -446,11 +454,13 @@ func (replyF) super_chat_message(s string){
                fmt.Println(message)
                // Gui_show(message.(string))
                sh = append(sh, message)
+               logg = append(logg, message)
        }
        if message_jpn != nil && message.(string) != message_jpn.(string) && message_jpn.(string) != "" {
                fmt.Println(message_jpn)
                // Gui_show(message_jpn.(string))
                sh = append(sh, message_jpn)
+               logg = append(logg, message_jpn)
        }
        fmt.Print("====\n\n")
        
@@ -459,7 +469,7 @@ func (replyF) super_chat_message(s string){
                // Gui_show("====\n")
                Gui_show(Itos(sh), "0superchat")
        }
-       msglog.Base(1, "礼").Fileonly(true).I(sh...).Fileonly(false)
+       msglog.Base(1, "礼").Fileonly(true).I(logg...).Fileonly(false)
 }
 
 //Msg-分区排行
@@ -556,7 +566,10 @@ func (replyF) danmu(s string) {
 //传入字符串即可发送
 //需要cookie
 func Msg_senddanmu(msg string){
-       if c.Cookie == "" || c.Roomid == 0 {return}
+       if c.Cookie == "" || c.Roomid == 0 {
+               msglog.I(`c.Cookie == "" || c.Roomid == 0`)
+               return
+       }
        S.Danmu_s(msg, c.Cookie, c.Roomid)
 }
 
index f44c0cdb40440c124e177c72f8942c7de17417a7..93d1993d01aa0d9889479f2748166d70e2c2daab 100644 (file)
@@ -48,6 +48,7 @@ var keep_key = map[string]int{
        "face/0level2":3,
        "face/0level3":1,
        "face/0superchat":13,
+       "face/0tianxuan":5,
 }
 var (
        Gtk_on bool
@@ -90,6 +91,9 @@ func Gtk_danmu() {
        var viewport0 *gtk.Viewport
        var w2_textView0 *gtk.TextView
        var w2_textView1 *gtk.TextView
+       var w2_textView2 *gtk.TextView
+       var w2_textView3 *gtk.TextView
+       var renqi_old = 1
        var w2_Entry0 *gtk.Entry
        var w2_Entry0_editting bool
 
@@ -143,6 +147,20 @@ func Gtk_danmu() {
                                w2_textView1 = tmp
                        }else{log.Println("cant find #t1 in .glade");return}
                }
+               {//人气值
+                       obj, err := builder2.GetObject("t2")
+                       if err != nil {log.Println(err);return}
+                       if tmp,ok := obj.(*gtk.TextView); ok {
+                               w2_textView2 = tmp
+                       }else{log.Println("cant find #t2 in .glade");return}
+               }
+               {//舰长数
+                       obj, err := builder2.GetObject("t3")
+                       if err != nil {log.Println(err);return}
+                       if tmp,ok := obj.(*gtk.TextView); ok {
+                               w2_textView3 = tmp
+                       }else{log.Println("cant find #t3 in .glade");return}
+               }
                {//发送弹幕
                        var danmu_send_form string
                        {//发送弹幕格式
@@ -202,6 +220,7 @@ func Gtk_danmu() {
                                                        y(`输入错误`,load_face("0room"))
                                                } else {
                                                        c.Roomid =  i
+                                                       renqi_old = 1//人气置1
                                                        c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{
                                                                Class:`change_room`,
                                                        })
@@ -374,17 +393,51 @@ func Gtk_danmu() {
                                        b.SetText(fmt.Sprintf("¥%.2f",c.Rev))                                 
                                }
                        }
+                       {//舰长
+                               b,e := w2_textView3.GetBuffer()
+                               if e != nil {log.Println(e);return}
+                               b.SetText(fmt.Sprintf("%d",c.GuardNum))
+                       }
                        {//时长
+                               b,e := w2_textView1.GetBuffer()
+                               if e != nil {log.Println(e);return}
                                if c.Liveing {
-                                       b,e := w2_textView1.GetBuffer()
-                                       if e != nil {log.Println(e);return}
                                        d := time.Since(c.Live_Start_Time).Round(time.Second)
                                        h := d / time.Hour
                                        d -= h * time.Hour
                                        m := d / time.Minute
                                        d -= m * time.Minute
                                        s := d / time.Second
-                                       b.SetText(fmt.Sprintf("%02d:%02d:%02d", h, m, s))                                       
+                                       b.SetText(fmt.Sprintf("%02d:%02d:%02d", h, m, s))
+                               } else {
+                                       b.SetText("00:00:00")
+                               }
+                       }
+                       {//人气
+                               b,e := w2_textView2.GetBuffer()
+                               if e != nil {log.Println(e);return}
+                               if c.Liveing {
+                                       if c.Renqi != renqi_old {
+                                               var Renqi string = strconv.Itoa(c.Renqi)
+                                               L:=len([]rune(Renqi))
+
+                                               var tmp string
+                                               if renqi_old != 1 {
+                                                       if c.Renqi > renqi_old {tmp += `+`}
+                                                       tmp += fmt.Sprintf("%.1f",100*float64(c.Renqi - renqi_old)/float64(renqi_old)) + `% | `
+                                               }
+                                               if c.Renqi != 0 {renqi_old = c.Renqi}
+
+                                               for k,v := range []rune(Renqi) {
+                                                       tmp += string(v)
+                                                       if (L - k)%3 == 1 && L - k != 1{
+                                                               tmp += `,`
+                                                       }
+                                               }
+                                               b.SetText(tmp)
+                                       }
+                               } else {
+                                       b.SetText(`0`)
                                }
                        }
                        {//房间id
index 0a65b2845696ce9b943a3656548f66af6a0fa0bf..4ea8799ecc8f01dfeb50d38e76535b1df2da6c24 100644 (file)
@@ -65,9 +65,12 @@ func Demo(roomid ...int) {
                                        switch d.Class {
                                        case `change_room`:
                                                c.Rev = 0 //营收
+                                               c.Renqi = 1//人气置1
                                                change_room_chan <- true
                                        case `c.Rev_add`:
                                                c.Rev += d.Data.(float64)
+                                       case `c.Renqi`:
+                                               c.Renqi = d.Data.(int)
                                        default:
                                        }
                                }
@@ -118,8 +121,9 @@ func Demo(roomid ...int) {
                                                c.Roomid = api.Roomid
                                                c.Live = api.Live
                                                c.Cookie = f
-                                               //获取过往营收
+                                               //获取过往营收 舰长数量
                                                go api.Get_OnlineGoldRank()
+                                               go api.Get_guardNum()
 
                                                if p.Checkfile().IsExist("cookie.txt") {//附加功能 弹幕机
                                                        reply.Danmuji_auto(1)
index 99b568822d65f696532005e1b909d07a7944d8cd..8d209c7c4f8865c015f65e75ec04b9046d128892 100644 (file)
@@ -7,5 +7,6 @@
        "face/0level1":5,
        "face/0level2":3,
        "face/0level3":1,
-       "face/0superchat":13
+       "face/0superchat":13,
+       "face/0tianxuan":5
 }
\ No newline at end of file
diff --git a/demo/face/0tianxuan b/demo/face/0tianxuan
new file mode 100644 (file)
index 0000000..75da1f1
Binary files /dev/null and b/demo/face/0tianxuan differ
index a3d8610347760830180bdd17ced592b915e2fc20..097c471c06d756d92381710d7b0bfd2b70aac43a 100644 (file)
@@ -90,7 +90,6 @@
                           <object class="GtkTextView" id="t0">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
-                            <property name="hscroll_policy">natural</property>
                             <property name="editable">False</property>
                             <property name="justification">right</property>
                             <property name="cursor_visible">False</property>
                             <property name="top_attach">0</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">人气</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">3</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkTextView" id="t2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="editable">False</property>
+                            <property name="justification">right</property>
+                            <property name="cursor_visible">False</property>
+                            <property name="accepts_tab">False</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">3</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">舰长数</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">4</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkTextView" id="t3">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="editable">False</property>
+                            <property name="justification">right</property>
+                            <property name="cursor_visible">False</property>
+                            <property name="accepts_tab">False</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">4</property>
+                          </packing>
+                        </child>
                         <style>
                           <class name="this_time_body"/>
                         </style>