Skip to content

Commit

Permalink
增加虎牙获取直播信息过程中的错误处理,为flv parser设置 header 以支持虎牙直播录制 (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
kira1928 authored Dec 30, 2023
1 parent 15bf274 commit 7dced2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/live/huya/huya.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ func (l *Live) GetStreamUrls() (us []*url.URL, err error) {
return nil, err
}

liveInfoJson := gjson.Parse(strings.Split(strings.Split(body, `"tLiveInfo":`)[1], `,"_classname":"LiveRoom.LiveInfo"}`)[0] + "}")
if !liveInfoJson.Exists() {
return nil, fmt.Errorf("liveInfo not found")
tmpStrings := strings.Split(body, `"tLiveInfo":`)
if len(tmpStrings) < 2 {
return nil, fmt.Errorf("tLiveInfo not found")
}
liveInfoJsonRawString := strings.Split(tmpStrings[1], `,"_classname":"LiveRoom.LiveInfo"}`)[0] + "}"
if !gjson.Valid(liveInfoJsonRawString) {
return nil, fmt.Errorf("liveInfoJsonRawString not valid")
}
liveInfoJson := gjson.Parse(liveInfoJsonRawString)

streamInfoJsons := liveInfoJson.Get("tLiveStreamInfo.vStreamInfo.value").Array()
if len(streamInfoJsons) == 0 {
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/parser/native/flv/flv.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (p *Parser) ParseLiveStream(ctx context.Context, url *url.URL, live live.Li
return err
}
req.Header.Add("User-Agent", "Chrome/59.0.3071.115")
// add headers for downloader from live
for k, v := range live.GetHeadersForDownloader() {
req.Header.Set(k, v)
}
resp, err := p.hc.Do(req)
if err != nil {
return err
Expand Down

0 comments on commit 7dced2c

Please sign in to comment.