From 3ce776c2bc250374cdcdb35e159806713eab83a8 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 1 Jun 2025 18:11:07 +0800 Subject: [PATCH] =?utf8?q?Improve=20=E4=BC=98=E5=8C=96=20(#214)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Improve 优化 * Improve 优化 * Improve 优化 * Improve 优化 * Improve 优化 --- CV/Var.go | 8 +++----- Reply/stream.go | 25 ++++++++++++++++++------- Reply/tts.go | 9 +++++++-- Send/Send.go | 2 +- Send/Send_gift.go | 2 +- Send/Send_pm.go | 6 +++--- go.mod | 6 +++--- go.sum | 12 ++++++------ 8 files changed, 42 insertions(+), 28 deletions(-) diff --git a/CV/Var.go b/CV/Var.go index 2fab228..215a3cd 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -775,13 +775,11 @@ func (t *Common) loadConf(customConf string) error { }); e != nil { return errors.New("无法获取自定义配置文件 " + e.Error()) } - if req.Response == nil { - return errors.New("无法获取自定义配置文件 响应为空") - } else if req.Response.StatusCode&200 != 200 { - return fmt.Errorf("无法获取自定义配置文件 %d", req.Response.StatusCode) + if req.ResStatusCode()&200 != 200 { + return fmt.Errorf("无法获取自定义配置文件 %d", req.ResStatusCode()) } else { var tmp map[string]interface{} - _ = json.Unmarshal(req.Respon, &tmp) + _ = req.ResponUnmarshal(json.Unmarshal, &tmp) for k, v := range tmp { data[k] = v } diff --git a/Reply/stream.go b/Reply/stream.go index f33f8da..a3cdb30 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "io/fs" + "iter" "math" "net" "net/http" @@ -160,7 +161,7 @@ func (link *m4s_link_item) download(reqPool *pool.Buf[reqf.Req], reqConfig reqf. link.status = 3 // 设置切片状态为下载失败 link.err = e return e - } else if e = link.data.Append(r.Respon); e != nil { + } else if e = r.Respon(link.data.Append); e != nil { link.status = 3 // 设置切片状态为下载失败 link.err = e return e @@ -408,12 +409,12 @@ func (t *M4SStream) fetchCheckStream() bool { continue } - if r.Response == nil { + if r.Wait() != nil { _log.L(`W: `, `live响应错误`, F.ParseHost(v.Url)) v.DisableAuto() continue - } else if r.Response.StatusCode&200 != 200 { - _log.L(`W: `, `live响应错误`, F.ParseHost(v.Url), r.Response.Status) + } else if r.ResStatusCode()&200 != 200 { + _log.L(`W: `, `live响应错误`, F.ParseHost(v.Url), r.ResStatusCode()) v.DisableAuto() continue } @@ -485,13 +486,13 @@ func (t *M4SStream) fetchParseM3U8(lastM4s *m4s_link_item, fmp4ListUpdateTo floa continue } - if r.Response.StatusCode == http.StatusNotModified { + if r.ResStatusCode() == http.StatusNotModified { t.log.L(`T: `, `hls未更改`) return } // 保存最后m3u8修改时间 - if last_mod, ok := r.Response.Header[`Last-Modified`]; ok && len(last_mod) > 0 { + if last_mod, ok := r.ResHeader()[`Last-Modified`]; ok && len(last_mod) > 0 { if lm, e := time.Parse(time.RFC1123, last_mod[0]); e == nil { t.stream_last_modified = lm } @@ -504,7 +505,17 @@ func (t *M4SStream) fetchParseM3U8(lastM4s *m4s_link_item, fmp4ListUpdateTo floa lastNo, _ = lastM4s.getNo() } - if rg, redirectUrl, err := replyFunc.ParseM3u8.Parse(r.Respon, lastNo); err != nil { + var ( + rg iter.Seq[interface { + IsHeader() bool + M4sLink() string + }] + redirectUrl string + ) + if err := r.Respon(func(b []byte) (err error) { + rg, redirectUrl, err = replyFunc.ParseM3u8.Parse(b, lastNo) + return + }); err != nil { if replyFunc.ParseM3u8.IsErrRedirect(err) { // 指向新连接 t.log.L(`I: `, `指向新连接`, v.Host(), "=>", F.ParseHost(redirectUrl)) diff --git a/Reply/tts.go b/Reply/tts.go index 21aff67..f174957 100644 --- a/Reply/tts.go +++ b/Reply/tts.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "io" + "net/http" "net/url" "os/exec" "strings" @@ -258,8 +259,12 @@ func youdao(msg string) error { }); err != nil { return err } - if req.Response.Header.Get(`Content-type`) == `application/json` { - return errors.New(`错误 ` + req.Response.Status + string(req.Respon)) + if req.ResHeader().Get(`Content-type`) == `application/json` { + return req.Response(func(r *http.Response) error { + return req.Respon(func(b []byte) error { + return errors.New(`错误 ` + r.Status + string(b)) + }) + }) } play() return nil diff --git a/Send/Send.go b/Send/Send.go index 1194962..7129f20 100644 --- a/Send/Send.go +++ b/Send/Send.go @@ -140,7 +140,7 @@ func Danmu_s2(data map[string]string) error { Message string `json:"message"` } - if e := json.Unmarshal(r.Respon, &res); e != nil { + if e := r.ResponUnmarshal(json.Unmarshal, &res); e != nil { l.L(`E: `, e) return e } diff --git a/Send/Send_gift.go b/Send/Send_gift.go index 241d27a..6662b4b 100644 --- a/Send/Send_gift.go +++ b/Send/Send_gift.go @@ -86,7 +86,7 @@ func Send_gift(common *c.Common, gift_id, bag_id, gift_num int) { var res J.SendBag - if e := json.Unmarshal(req.Respon, &res); e != nil { + if e := req.ResponUnmarshal(json.Unmarshal, &res); e != nil { log.L(`E: `, e) return } diff --git a/Send/Send_pm.go b/Send/Send_pm.go index a2648f6..9ed23aa 100644 --- a/Send/Send_pm.go +++ b/Send/Send_pm.go @@ -80,9 +80,9 @@ func Send_pm(uid int, msg string) error { Code int `json:"code"` }{} - if e := json.Unmarshal(req.Respon, &J); e != nil { - log.L(`E: `, string(req.Respon)) - return errors.New(string(req.Respon)) + if e := req.ResponUnmarshal(json.Unmarshal, &J); e != nil { + log.L(`E: `, e) + return e } log.L(`I: `, `发送私信给`, uid, `:`, msg) diff --git a/go.mod b/go.mod index 19e853a..2fec9c5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.24 require ( github.com/gotk3/gotk3 v0.6.4 github.com/mdp/qrterminal/v3 v3.2.0 - github.com/qydysky/part v0.28.20250528161452 + github.com/qydysky/part v0.28.20250531145811 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 golang.org/x/text v0.24.0 // indirect @@ -13,8 +13,8 @@ require ( require ( github.com/google/uuid v1.6.0 - github.com/qydysky/biliApi v0.0.0-20250526141352-fb7c3ea428df - github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9 + github.com/qydysky/biliApi v0.0.0-20250531145900-53e14d4e3627 + github.com/qydysky/brotli v0.0.0-20250531004300-54adcf96cc4a golang.org/x/exp v0.0.0-20250215185904-eff6e970281f ) diff --git a/go.sum b/go.sum index b5d9ec7..befc90c 100644 --- a/go.sum +++ b/go.sum @@ -42,12 +42,12 @@ github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdh github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/qydysky/biliApi v0.0.0-20250526141352-fb7c3ea428df h1:ynGDEQujbNemrrsIViEhWdOSvpNOeg9HQE4ImHklCJk= -github.com/qydysky/biliApi v0.0.0-20250526141352-fb7c3ea428df/go.mod h1:1FbgCj+aOwIvuRRuX/l5uTLb3JIwWyJSa0uEfwpYV/8= -github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9 h1:k451T+bpsLr+Dq9Ujo+Qtx0iomRA1XXS5ttlEojvfuQ= -github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9/go.mod h1:cI8/gy/wjy2Eb+p2IUj2ZuDnC8R5Vrx3O0VMPvMvphA= -github.com/qydysky/part v0.28.20250528161452 h1:DmxR6kWBfvZKpQ03Dgj2i2FIsWizaIGlKCQT44o3E7s= -github.com/qydysky/part v0.28.20250528161452/go.mod h1:wp71PQdKYcg9jn9yDDvqC4shS/kzejyvFqbfUxuHocY= +github.com/qydysky/biliApi v0.0.0-20250531145900-53e14d4e3627 h1:w1EusitHqpnsoDq9vrLWkB0/aLPTGdx61v74QtfNfdE= +github.com/qydysky/biliApi v0.0.0-20250531145900-53e14d4e3627/go.mod h1:XLorzcekv/Tzb6lg6w8kIGSbxsw9AUa77VERkuljH78= +github.com/qydysky/brotli v0.0.0-20250531004300-54adcf96cc4a h1:OSIFTKGKsOLYycboWvW/1EvgPMinwtm2/IH+TE/zYrc= +github.com/qydysky/brotli v0.0.0-20250531004300-54adcf96cc4a/go.mod h1:cI8/gy/wjy2Eb+p2IUj2ZuDnC8R5Vrx3O0VMPvMvphA= +github.com/qydysky/part v0.28.20250531145811 h1:oahY+e4vRKFQoLH4h9FbzydEd3erYXm9aajof7x+9io= +github.com/qydysky/part v0.28.20250531145811/go.mod h1:GV8Idc6+XRu5Lt5hB6NXJoUJ3viEZ72BMSHeey/ZM5A= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= -- 2.39.2