From 65a387ce05d6730b2541e3f6a613dbea828f94cf Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 16 Jan 2024 00:27:04 +0800 Subject: [PATCH] =?utf8?q?Improve=20=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A?= =?utf8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- F/api.go | 10 +++---- F/api_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++ Reply/flvDecode.go | 2 +- Reply/fmp4Decode.go | 4 +-- Reply/stream.go | 2 +- 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/F/api.go b/F/api.go index eddb0a8..88afce9 100644 --- a/F/api.go +++ b/F/api.go @@ -326,7 +326,7 @@ func (t *GetFunc) Html() (missKey []string) { if !t.Liveing { t.Live_qn = 0 t.AcceptQn = t.Qn - t.Live = []c.LiveQn{} + clear(t.Live) return } @@ -415,7 +415,7 @@ func (t *GetFunc) configStreamType(sts []J.StreamType) { t.AcceptQn = tmp } //直播流链接 - t.Live = []c.LiveQn{} + clear(t.Live) for _, v1 := range v.URLInfo { item := c.LiveQn{ Url: v1.Host + v.BaseURL + v1.Extra, @@ -475,7 +475,7 @@ func (t *GetFunc) configStreamType(sts []J.StreamType) { t.AcceptQn = tmp } //直播流链接 - t.Live = []c.LiveQn{} + clear(t.Live) for _, v1 := range v.URLInfo { item := c.LiveQn{ Url: v1.Host + v.BaseURL + v1.Extra, @@ -730,7 +730,7 @@ func (t *GetFunc) getRoomPlayInfo() (missKey []string) { if !t.Liveing { t.Live_qn = 0 t.AcceptQn = t.Qn - t.Live = []c.LiveQn{} + clear(t.Live) return } @@ -825,7 +825,7 @@ func (t *GetFunc) getRoomPlayInfoByQn() (missKey []string) { if !t.Liveing { t.Live_qn = 0 t.AcceptQn = t.Qn - t.Live = []c.LiveQn{} + clear(t.Live) return } diff --git a/F/api_test.go b/F/api_test.go index 5fccaed..a5f870d 100644 --- a/F/api_test.go +++ b/F/api_test.go @@ -59,3 +59,69 @@ func Test_Title(t *testing.T) { t.Fatal() } } + +func Test_Html(t *testing.T) { + //获取cookie + Get(c.C).Get(`Cookie`) + //获取LIVE_BUVID + Get(c.C).Get(`LIVE_BUVID`) + c.C.Roomid = 394988 + c.C.UpUid = 0 + Get(c.C).Html() + if c.C.UpUid == 0 { + t.Fatal() + } +} + +func Test_getRoomPlayInfo(t *testing.T) { + //获取cookie + Get(c.C).Get(`Cookie`) + //获取LIVE_BUVID + Get(c.C).Get(`LIVE_BUVID`) + c.C.Roomid = 394988 + c.C.UpUid = 0 + Get(c.C).getRoomPlayInfo() + if c.C.UpUid == 0 { + t.Fatal() + } +} + +func Test_getRoomPlayInfoByQn(t *testing.T) { + //获取cookie + Get(c.C).Get(`Cookie`) + //获取LIVE_BUVID + Get(c.C).Get(`LIVE_BUVID`) + c.C.Roomid = 394988 + c.C.UpUid = 0 + Get(c.C).getRoomPlayInfoByQn() + if c.C.UpUid == 0 { + t.Fatal() + } +} + +func Test_getDanmuInfo(t *testing.T) { + //获取cookie + Get(c.C).Get(`Cookie`) + //获取LIVE_BUVID + Get(c.C).Get(`LIVE_BUVID`) + c.C.Roomid = 394988 + c.C.WSURL = []string{} + Get(c.C).getDanmuInfo() + if len(c.C.WSURL) == 0 { + t.Fatal() + } +} + +func Test_Get_guardNum(t *testing.T) { + //获取cookie + Get(c.C).Get(`Cookie`) + //获取LIVE_BUVID + Get(c.C).Get(`LIVE_BUVID`) + c.C.Roomid = 394988 + c.C.GuardNum = -1 + Get(c.C).Html() + Get(c.C).Get_guardNum() + if c.C.GuardNum == -1 { + t.Fatal() + } +} diff --git a/Reply/flvDecode.go b/Reply/flvDecode.go index 68757c9..9d51843 100644 --- a/Reply/flvDecode.go +++ b/Reply/flvDecode.go @@ -54,7 +54,7 @@ func Search_stream_tag(buf []byte, keyframe *slice.Buf[byte]) (front_buf []byte, // if sign != 0x00 { // fmt.Printf("front_buf error:%x\n", sign) // } - front_buf = []byte{} + clear(front_buf) } if bufl := keyframe.Size(); confirm_num != bufl { _ = keyframe.RemoveBack(bufl - confirm_num) diff --git a/Reply/fmp4Decode.go b/Reply/fmp4Decode.go index b495524..f5f0f2f 100644 --- a/Reply/fmp4Decode.go +++ b/Reply/fmp4Decode.go @@ -231,7 +231,7 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte]) ies, e := decode(buf, "moof") if e != nil { - return + return 0, e } err = deals(ies, @@ -428,7 +428,7 @@ func decode(buf []byte, reSyncboxName string) (m []ie, err error) { err = E if reSyncI := bytes.Index(buf[cu:], []byte(reSyncboxName)); reSyncI != -1 { cu += reSyncI - 4 - m = []ie{} + clear(m) continue } err = errors.New(E.Error() + " > 未能reSync") diff --git a/Reply/stream.go b/Reply/stream.go index c7ac73c..fd06887 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -455,7 +455,7 @@ func (t *M4SStream) fetchParseM3U8(fmp4ListUpdateTo float64) (m4s_links []*m4s_l if index := bytes.Index(m3u8_addon, []byte(m4s_link.Base)); index != -1 { index += len([]byte(m4s_link.Base)) if index == len(m3u8_addon) { - m3u8_addon = []byte{} + clear(m3u8_addon) } else { m3u8_addon = m3u8_addon[index+1:] } -- 2.39.2