Skip to content

Commit

Permalink
✨ feat(commClient): live get room info by id
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Nov 4, 2021
1 parent 2aa1577 commit 7b9828d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
26 changes: 24 additions & 2 deletions comm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ func (c *CommClient) ChargeVideoGetList(mid int64, aid int64) (*ChargeVideoList,
// LiveGetRoomInfoByMID
//
// 从mid获取直播间信息
func (c *CommClient) LiveGetRoomInfoByMID(mid int64) (*LiveRoomInfo, error) {
func (c *CommClient) LiveGetRoomInfoByMID(mid int64) (*LiveRoomInfoByMID, error) {
resp, err := c.RawParse(
BiliApiURL,
"x/space/acc/info",
Expand All @@ -1091,10 +1091,32 @@ func (c *CommClient) LiveGetRoomInfoByMID(mid int64) (*LiveRoomInfo, error) {
return nil, err
}
var info struct {
LiveRoom *LiveRoomInfo `json:"live_room"`
LiveRoom *LiveRoomInfoByMID `json:"live_room"`
}
if err = json.Unmarshal(resp.Data, &info); err != nil {
return nil, err
}
return info.LiveRoom, nil
}

// LiveGetRoomInfoByID 从roomID获取直播间信息
//
// roomID 可为短号也可以是真实房号
func (c *CommClient) LiveGetRoomInfoByID(roomID int64) (*LiveRoomInfoByID, error) {
resp, err := c.RawParse(
BiliLiveURL,
"xlive/web-room/v1/index/getRoomPlayInfo",
"GET",
map[string]string{
"room_id": strconv.FormatInt(roomID, 10),
},
)
if err != nil {
return nil, err
}
var r = &LiveRoomInfoByID{}
if err = json.Unmarshal(resp.Data, &r); err != nil {
return nil, err
}
return r, nil
}
16 changes: 16 additions & 0 deletions comm_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,19 @@ func TestCommClient_FollowingsGetDetail(t *testing.T) {
t.Logf("mid: %d,uname: %s", l.MID, l.Uname)
}
}
func TestCommClient_LiveGetRoomInfoByID(t *testing.T) {
r, err := testCommClient.LiveGetRoomInfoByID(1)
if err != nil {
t.Error(err)
t.FailNow()
}
t.Logf("id: %d,short: %d,uid: %d,status: %d,time: %d", r.RoomID, r.ShortID, r.UID, r.LiveStatus, r.LiveTime)
}
func TestCommClient_LiveGetRoomInfoByID2(t *testing.T) {
r, err := testCommClient.LiveGetRoomInfoByID(287083)
if err != nil {
t.Error(err)
t.FailNow()
}
t.Logf("id: %d,short: %d,uid: %d,status: %d,time: %d", r.RoomID, r.ShortID, r.UID, r.LiveStatus, r.LiveTime)
}
22 changes: 21 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ type ChargeQrCodeStatus struct {
// 3:未确认
Status int `json:"status"`
}
type LiveRoomInfo struct {
type LiveRoomInfoByMID struct {
RoomStatus int `json:"roomStatus"` // 直播间状态 0:无房间 1:有房间
RoundStatus int `json:"roundStatus"` // 轮播状态 0:未轮播 1:轮播
LiveStatus int `json:"liveStatus"` // 直播状态 0:未开播 1:直播中
Expand Down Expand Up @@ -1452,3 +1452,23 @@ type DynaDraft struct {
} `json:"level_info"`
} `json:"user_profile"` // 动态作者各种信息
}

type LiveRoomInfoByID struct {
RoomID int64 `json:"room_id"` // 真实直播间ID
ShortID int `json:"short_id"` // 短号
UID int64 `json:"uid"` // 主播mid
NeedP2P int `json:"need_p2p"` // 需要P2P
IsHidden bool `json:"is_hidden"` // 直播间是否隐藏
IsLocked bool `json:"is_locked"` // 直播间是否被封锁
IsPortrait bool `json:"is_portrait"` // 是否为竖屏直播间
LiveStatus int `json:"live_status"` // 0:未开播 1:开播
HiddenTill int64 `json:"hidden_till"` // 隐藏截止时间戳?
LockTill int64 `json:"lock_till"` // 封锁截止时间戳?
Encrypted bool `json:"encrypted"` // 直播间是否加密
PwdVerified bool `json:"pwd_verified"` // 直播间是否需要密码验证
LiveTime int64 `json:"live_time"` // 开播时间,-1为未开播
RoomShield int `json:"room_shield"`
IsSp int `json:"is_sp"`
SpecialType int `json:"special_type"`
AllSpecialTypes []int `json:"all_special_types"`
}

0 comments on commit 7b9828d

Please sign in to comment.