c.GetUid,
},
`UpUid`: { //主播uid
+ c.getRoomBaseInfo,
c.getInfoByRoom,
c.getRoomPlayInfo,
c.Html,
},
`Live_Start_Time`: { //直播开始时间
+ c.getRoomBaseInfo,
c.getInfoByRoom,
c.getRoomPlayInfo,
c.Html,
},
`Liveing`: { //是否在直播
+ c.getRoomBaseInfo,
c.getInfoByRoom,
c.getRoomPlayInfo,
c.Html,
},
`Title`: { //直播间标题
+ c.getRoomBaseInfo,
c.getInfoByRoom,
c.Html,
},
`Uname`: { //主播名
+ c.getRoomBaseInfo,
c.getInfoByRoom,
c.Html,
},
`ParentAreaID`: { //分区
+ c.getRoomBaseInfo,
c.getInfoByRoom,
c.Html,
},
`AreaID`: { //子分区
+ c.getRoomBaseInfo,
c.getInfoByRoom,
c.Html,
},
return
}
+func (c *GetFunc) getRoomBaseInfo() (missKey []string) {
+ fkey := `getRoomBaseInfo`
+
+ if v, ok := c.Cache.LoadV(fkey).(cacheItem); ok && v.exceeded.After(time.Now()) {
+ return
+ }
+
+ apilog := apilog.Base_add(`getRoomBaseInfo`)
+
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
+ return
+ }
+
+ Roomid := strconv.Itoa(c.Roomid)
+
+ { //使用其他api
+ req := c.Common.ReqPool.Get()
+ defer c.Common.ReqPool.Put(req)
+ if err := req.Reqf(reqf.Rval{
+ Url: "https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomBaseInfo?req_biz=link-center&room_ids=" + Roomid,
+ Header: map[string]string{
+ `Referer`: "https://link.bilibili.com/p/center/index",
+ },
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ }); err != nil {
+ apilog.L(`E: `, err)
+ return
+ }
+
+ //Roominfores
+ {
+ var j J.GetRoomBaseInfo
+
+ 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
+ }
+
+ if data, ok := j.Data.ByRoomIds[Roomid]; ok {
+ //主播id
+ c.UpUid = data.UID
+ //子分区
+ c.AreaID = data.AreaID
+ //分区
+ c.ParentAreaID = data.ParentAreaID
+ //直播间标题
+ c.Title = data.Title
+ //直播开始时间
+ if ti, e := time.Parse(time.DateTime, data.LiveTime); e != nil && !ti.IsZero() {
+ c.Live_Start_Time = ti
+ }
+ //是否在直播
+ c.Liveing = data.LiveStatus == 1
+ //主播名
+ c.Uname = data.Uname
+ //房间id
+ if data.RoomID != 0 {
+ c.Roomid = data.RoomID
+ }
+ }
+ }
+ }
+
+ c.Cache.Store(fkey, cacheItem{
+ data: nil,
+ exceeded: time.Now().Add(time.Second * 2),
+ })
+ return
+}
+
func (c *GetFunc) getInfoByRoom() (missKey []string) {
fkey := `getInfoByRoom`
--- /dev/null
+package part
+
+type GetRoomBaseInfo struct {
+ Code int `json:"code"`
+ Message string `json:"message"`
+ TTL int `json:"ttl"`
+ Data struct {
+ ByRoomIds map[string]GetRoomBaseInfoD `json:"by_room_ids"`
+ } `json:"data"`
+}
+
+type GetRoomBaseInfoD struct {
+ RoomID int `json:"room_id"`
+ UID int `json:"uid"`
+ AreaID int `json:"area_id"`
+ LiveStatus int `json:"live_status"`
+ // LiveURL string `json:"live_url"`
+ ParentAreaID int `json:"parent_area_id"`
+ Title string `json:"title"`
+ // ParentAreaName string `json:"parent_area_name"`
+ // AreaName string `json:"area_name"`
+ LiveTime string `json:"live_time"`
+ // Description string `json:"description"`
+ // Tags string `json:"tags"`
+ Attention int `json:"attention"`
+ Online int `json:"online"`
+ ShortID int `json:"short_id"`
+ Uname string `json:"uname"`
+ Cover string `json:"cover"`
+ Background string `json:"background"`
+ JoinSlide int `json:"join_slide"`
+ LiveID int64 `json:"live_id"`
+ LiveIDStr string `json:"live_id_str"`
+}
ws_msg "github.com/qydysky/bili_danmu/Reply/ws_msg"
send "github.com/qydysky/bili_danmu/Send"
p "github.com/qydysky/part"
+ funcCtrl "github.com/qydysky/part/funcCtrl"
mq "github.com/qydysky/part/msgq"
pstrings "github.com/qydysky/part/strings"
)
}
+var roomChangeFC funcCtrl.FlashFunc
+
// Msg-房间信息改变,标题等
func (replyF) room_change(s string) {
- title := p.Json().GetValFromS(s, "data.title")
- area_name := p.Json().GetValFromS(s, "data.area_name")
+ var type_item ws_msg.ROOM_CHANGE
- var sh = []interface{}{"房间改变"}
+ if e := json.Unmarshal([]byte(s), &type_item); e != nil {
+ msglog.L(`E: `, e)
+ }
+
+ change := c.C.AreaID != type_item.Data.AreaID || c.C.Title != type_item.Data.Title
+
+ if c.C.Title != type_item.Data.Title {
+ StreamOCut(c.C.Roomid, type_item.Data.Title)
+ } else if c.C.AreaID == type_item.Data.AreaID {
+ // 直播间标题引入审核机制,触发审核时会接收到一个roomchange但标题不变
+ cancle := make(chan struct{})
+ roomChangeFC.FlashWithCallback(func() {
+ close(cancle)
+ })
- if c.C.Title != title.(string) {
- StreamOCut(c.C.Roomid, title.(string))
+ go func(roomid int, oldTitle string) {
+ for tryC := 30; tryC > 0 && c.C.Roomid == roomid; tryC-- {
+ select {
+ case <-cancle:
+ return
+ case <-time.After(time.Second * 30):
+ F.Get(c.C).Get(`Title`)
+ if c.C.Roomid == roomid && c.C.Title != oldTitle {
+ StreamOCut(c.C.Roomid, c.C.Title)
+ var sh = []any{"房间改变", c.C.Title}
+ Gui_show(Itos(sh), "0room")
+ msglog.Base_add("房").L(`I: `, sh...)
+ return
+ }
+ }
+ }
+ }(c.C.Roomid, c.C.Title)
+ }
+
+ if type_item.Data.AreaID != 0 {
+ c.C.AreaID = type_item.Data.AreaID
+ }
+ if type_item.Data.ParentAreaID != 0 {
+ c.C.ParentAreaID = type_item.Data.ParentAreaID
}
- if title != nil {
- sh = append(sh, title)
- c.C.Title = title.(string)
+ var sh = []interface{}{"房间改变"}
+ if type_item.Data.Title != "" {
+ sh = append(sh, type_item.Data.Title)
+ c.C.Title = type_item.Data.Title
}
- if area_name != nil {
- sh = append(sh, area_name)
+ if type_item.Data.AreaName != "" {
+ sh = append(sh, type_item.Data.AreaName)
}
- Gui_show(Itos(sh), "0room")
- msglog.Base_add("房").L(`I: `, sh...)
+ if change {
+ Gui_show(Itos(sh), "0room")
+ msglog.Base_add("房").L(`I: `, sh...)
+ }
}
// Msg-超管警告
--- /dev/null
+package part
+
+type ROOM_CHANGE struct {
+ Cmd string `json:"cmd"`
+ Data struct {
+ Title string `json:"title"`
+ AreaID int `json:"area_id"`
+ ParentAreaID int `json:"parent_area_id"`
+ AreaName string `json:"area_name"`
+ ParentAreaName string `json:"parent_area_name"`
+ LiveKey string `json:"live_key"`
+ SubSessionKey string `json:"sub_session_key"`
+ } `json:"data"`
+}