diff --git a/comm_client.go b/comm_client.go index 08d59f3..1016fd7 100644 --- a/comm_client.go +++ b/comm_client.go @@ -1218,3 +1218,29 @@ func (c *CommClient) LiveGetMedalRank(roomID int64, mid int64) (*LiveMedalRank, } return r, nil } + +// LiveGetPlayURL 获取直播流信息 +// +// qn: 原画:10000 蓝光:400 超清:250 高清:150 流畅:80 +func (c *CommClient) LiveGetPlayURL(roomID int64, qn int) (*LivePlayURL, error) { + resp, err := c.RawParse( + BiliLiveURL, + "xlive/web-room/v1/playUrl/playUrl", + "GET", + map[string]string{ + "cid": strconv.FormatInt(roomID, 10), + "qn": strconv.Itoa(qn), + "platform": "web", + "https_url_req": "1", + "ptype": "16", + }, + ) + if err != nil { + return nil, err + } + var r = &LivePlayURL{} + 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 e8f4187..1a80542 100644 --- a/comm_client_test.go +++ b/comm_client_test.go @@ -546,3 +546,17 @@ func TestCommClient_LiveGetMedalRank(t *testing.T) { t.Logf("rank: %d,uname: %s,medal: %s,guard: %d,level: %d", l.Rank, l.Uname, l.MedalName, l.GuardLevel, l.Level) } } +func TestCommClient_LiveGetPlayURL(t *testing.T) { + r, err := testCommClient.LiveGetPlayURL(923833, 10000) + if err != nil { + t.Error(err) + t.FailNow() + } + t.Logf("cur: %d", r.CurrentQn) + for _, q := range r.QualityDescription { + t.Logf("qn: %d,desc: %s", q.Qn, q.Desc) + } + for _, u := range r.DURL { + t.Logf("order: %d,url: %s", u.Order, u.URL) + } +} diff --git a/types.go b/types.go index 989459f..e577f49 100644 --- a/types.go +++ b/types.go @@ -1559,3 +1559,19 @@ type LiveMedalRank struct { IsLighted int `json:"is_lighted"` } `json:"list"` } +type LivePlayURL struct { + CurrentQn int `json:"current_qn"` + QualityDescription []*struct { + Qn int `json:"qn"` + Desc string `json:"desc"` + } `json:"quality_description"` // 清晰度列表 + DURL []*struct { + URL string `json:"url"` + Length int `json:"length"` + Order int `json:"order"` + StreamType int `json:"stream_type"` + PTag int `json:"ptag"` + P2PType int `json:"p2p_type"` + } `json:"durl"` + IsDashAuto bool `json:"is_dash_auto"` +}