diff --git a/comm_client.go b/comm_client.go index aa1e96f..b9187a6 100644 --- a/comm_client.go +++ b/comm_client.go @@ -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", @@ -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 +} diff --git a/comm_client_test.go b/comm_client_test.go index a7cbaf5..2d4140d 100644 --- a/comm_client_test.go +++ b/comm_client_test.go @@ -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) +} diff --git a/types.go b/types.go index 6a4347b..a1de114 100644 --- a/types.go +++ b/types.go @@ -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:直播中 @@ -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"` +}