From: qydysky Date: Fri, 27 Nov 2020 10:30:20 +0000 (+0800) Subject: 人气,舰长 X-Git-Tag: v0.5.3~1^2~2 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=f0fe0099b2c30b6760fb80d2d904370dd75fbf01;p=bili_danmu%2F.git 人气,舰长 --- diff --git a/CV/Var.go b/CV/Var.go index 67de522..a9240b8 100644 --- 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//是否在直播 ) diff --git a/F/api.go b/F/api.go index 8a8b506..ceb74b4 100644 --- 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 +} diff --git a/Reply/Heartbeat.go b/Reply/Heartbeat.go index f28019a..fb215c3 100644 --- a/Reply/Heartbeat.go +++ b/Reply/Heartbeat.go @@ -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); diff --git a/Reply/Msg.go b/Reply/Msg.go index 1944654..139c167 100644 --- a/Reply/Msg.go +++ b/Reply/Msg.go @@ -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, diff --git a/Reply/Reply.go b/Reply/Reply.go index 7112b1d..4eb5eb5 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -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) } diff --git a/Reply/gtk.go b/Reply/gtk.go index f44c0cd..93d1993 100644 --- a/Reply/gtk.go +++ b/Reply/gtk.go @@ -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 diff --git a/bili_danmu.go b/bili_danmu.go index 0a65b28..4ea8799 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -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) diff --git a/demo/config/config_gtk_keep_key.json b/demo/config/config_gtk_keep_key.json index 99b5688..8d209c7 100644 --- a/demo/config/config_gtk_keep_key.json +++ b/demo/config/config_gtk_keep_key.json @@ -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 index 0000000..75da1f1 Binary files /dev/null and b/demo/face/0tianxuan differ diff --git a/demo/ui/2.glade b/demo/ui/2.glade index a3d8610..097c471 100644 --- a/demo/ui/2.glade +++ b/demo/ui/2.glade @@ -90,7 +90,6 @@ True True - natural False right False @@ -125,6 +124,56 @@ 0 + + + True + False + 人气 + + + 0 + 3 + + + + + True + True + False + right + False + False + + + 1 + 3 + + + + + True + False + 舰长数 + + + 0 + 4 + + + + + True + True + False + right + False + False + + + 1 + 4 + +