Skip to content

Commit

Permalink
✨ feat(commClient): LiveGetPlayURL
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Nov 6, 2021
1 parent 0bbc27a commit 14f64f7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions comm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions comm_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
16 changes: 16 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 14f64f7

Please sign in to comment.