From 7dced2c8d25511557a390b16b2c294a3e6cd77c9 Mon Sep 17 00:00:00 2001 From: kira1928 Date: Sun, 31 Dec 2023 00:33:54 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=99=8E=E7=89=99=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=9B=B4=E6=92=AD=E4=BF=A1=E6=81=AF=E8=BF=87=E7=A8=8B?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E4=B8=BAflv=20parser=E8=AE=BE=E7=BD=AE=20header=20=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=99=8E=E7=89=99=E7=9B=B4=E6=92=AD=E5=BD=95?= =?UTF-8?q?=E5=88=B6=20(#640)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/live/huya/huya.go | 11 ++++++++--- src/pkg/parser/native/flv/flv.go | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/live/huya/huya.go b/src/live/huya/huya.go index b3c0029a..00bc4fa7 100644 --- a/src/live/huya/huya.go +++ b/src/live/huya/huya.go @@ -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 { diff --git a/src/pkg/parser/native/flv/flv.go b/src/pkg/parser/native/flv/flv.go index a7e266c1..d01e980c 100644 --- a/src/pkg/parser/native/flv/flv.go +++ b/src/pkg/parser/native/flv/flv.go @@ -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