From b96f3019761319424016caa95bdddf69ab72ab90 Mon Sep 17 00:00:00 2001 From: qydysky Date: Mon, 1 Jan 2024 23:36:25 +0800 Subject: [PATCH] =?utf8?q?Improve=20=E7=89=88=E6=9C=AC=E6=98=BE=E7=A4=BA?= =?utf8?q?=E5=88=B0state?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .github/workflows/go.yml | 6 +++--- .github/workflows/test.yml | 4 ++-- VERSION => CV/VERSION | 0 CV/Var.go | 22 +++++++++++++++------- F/F.go | 9 +++++++-- README.md | 1 - Reply/stream.go | 4 +++- bili_danmu.go | 6 +----- go.mod | 2 +- go.sum | 4 ++-- 10 files changed, 34 insertions(+), 24 deletions(-) rename VERSION => CV/VERSION (100%) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0ca4ff1..44419bb 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,7 +5,7 @@ on: branches: - 'master' paths: - - 'VERSION' + - 'CV/VERSION' jobs: buildtest: @@ -72,7 +72,7 @@ jobs: run: | sudo apt-get update sudo apt-get install libgtk-3-dev libcairo2-dev libglib2.0-dev - git rev-parse --short HEAD > VERSION + git rev-parse --short HEAD > CV/VERSION cd demo go get . CGO_ENABLED=0 go build -pgo=auto -v -buildmode=exe -o demo.run main.go @@ -111,7 +111,7 @@ jobs: - name: Build run: | - git rev-parse --short HEAD > VERSION + git rev-parse --short HEAD > CV/VERSION cd demo set CGO_ENABLED=0 go get . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87601af..33a43a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -74,7 +74,7 @@ jobs: - name: Build run: | - git rev-parse --short HEAD > VERSION + git rev-parse --short HEAD > CV/VERSION cd demo sudo apt-get update sudo apt-get install libgtk-3-dev libcairo2-dev libglib2.0-dev @@ -113,7 +113,7 @@ jobs: - name: Build run: | - git rev-parse --short HEAD > VERSION + git rev-parse --short HEAD > CV/VERSION cd demo go get . set CGO_ENABLED=0 diff --git a/VERSION b/CV/VERSION similarity index 100% rename from VERSION rename to CV/VERSION diff --git a/CV/Var.go b/CV/Var.go index e4192b1..b782dcf 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -3,6 +3,7 @@ package cv import ( "context" "database/sql" + _ "embed" "encoding/json" "errors" "flag" @@ -31,6 +32,9 @@ import ( _ "modernc.org/sqlite" ) +//go:embed VERSION +var version string + type StreamType struct { Protocol_name string Format_name string @@ -39,6 +43,7 @@ type StreamType struct { type Common struct { PID int `json:"pid"` //进程id + Version string `json:"version"` //版本 Uid int `json:"-"` //client uid Live []LiveQn `json:"-"` //直播流链接 Live_qn int `json:"liveQn"` //当前直播流质量 @@ -119,6 +124,7 @@ func (t *Common) IsOn(key string) bool { func (t *Common) Copy() *Common { var c = Common{ PID: t.PID, + Version: t.Version, Uid: t.Uid, Live: t.Live, Live_qn: t.Live_qn, @@ -197,6 +203,7 @@ func (t *Common) ValidLive() *LiveQn { func (t *Common) Init() *Common { t.PID = os.Getpid() + t.Version = version t.StartT = time.Now() t.AllStreamType = map[string]StreamType{ @@ -381,20 +388,21 @@ func (t *Common) Init() *Common { gcAvgS = time.Since(t.StartT).Seconds() / float64(memStats.NumGC) } - reqState := t.ReqPool.PoolState() + reqState := t.ReqPool.State() ResStruct{0, "ok", map[string]any{ + "version": strings.TrimSpace(t.Version), "startTime": t.StartT.Format(time.DateTime), "currentTime": time.Now().Format(time.DateTime), "state": map[string]any{ "base": map[string]any{ "reqPoolState": map[string]any{ - "pooled": reqState[0], - "nopooled": reqState[1], - "inuse": reqState[2], - "nouse": reqState[3], - "sum": reqState[4], - "qts": math.Round(reqState[5].(float64)*100) / 100, + "pooled": reqState.Pooled, + "nopooled": reqState.Nopooled, + "inuse": reqState.Inuse, + "nouse": reqState.Nouse, + "sum": reqState.Sum, + "qts": math.Round(reqState.GetPerSec*100) / 100, }, "numGoroutine": runtime.NumGoroutine(), "goVersion": runtime.Version(), diff --git a/F/F.go b/F/F.go index c7ca5f1..34d3ed0 100644 --- a/F/F.go +++ b/F/F.go @@ -65,8 +65,13 @@ func HelloGen(roomid int, key string) []byte { var obj = `{"uid":` + strconv.Itoa(c.C.Uid) + `,"roomid":` + strconv.Itoa(roomid) + - `,"protover":` + strconv.Itoa(c.Protover) + - `,"platform":"` + c.Platform + + `,"protover":` + strconv.Itoa(c.Protover) + + if buvid, ok := c.C.Cookie.LoadV("buvid3").(string); ok { + obj += `,"buvid":"` + buvid + `"` + } + + obj += `,"platform":"` + c.Platform + // `","clientver":"` + c.VERSION + //delete at 2021 4 14 `","type":` + strconv.Itoa(c.Type) + `,"key":"` + key + `"}` diff --git a/README.md b/README.md index 5647d1c..aed86e0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ## bilibili 直播弹幕机 [![Go Report Card](https://goreportcard.com/badge/github.com/qydysky/bili_danmu)](https://goreportcard.com/report/github.com/qydysky/bili_danmu) [![codecov](https://codecov.io/gh/qydysky/bili_danmu/branch/master/graph/badge.svg?token=2R7031P47C)](https://codecov.io/gh/qydysky/bili_danmu) -[![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/qydysky/bili_danmu)](https://libraries.io/go/github.com%2Fqydysky%2Fbili_danmu) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fqydysky%2Fbili_danmu.svg?type=small)](https://app.fossa.com/projects/git%2Bgithub.com%2Fqydysky%2Fbili_danmu?ref=badge_small) [![少年Pi的直播回放](https://img.shields.io/website?up_message=%E5%9C%A8%E7%BA%BF&down_message=%E7%A6%BB%E7%BA%BF&url=http%3A%2F%2F8.134.76.53%3A8080%2Fweb%2F&label=%E5%B0%91%E5%B9%B4Pi%E7%9A%84%E7%9B%B4%E6%92%AD%E5%9B%9E%E6%94%BE)](https://r.qydysky.org/bili) diff --git a/Reply/stream.go b/Reply/stream.go index 1631e59..d4249e2 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -884,7 +884,9 @@ func (t *M4SStream) saveStreamM4s() (e error) { return case <-ticker.C: } - t.log.L(`T: `, fmt.Sprintf("m4sPoolState pooled/no(%d/%d), inuse/no(%d/%d), sum(%d), qts(%.2f)", t.m4s_pool.PoolState()...)) + reqState := t.m4s_pool.State() + t.log.L(`T: `, fmt.Sprintf("m4sPoolState pooled/no(%d/%d), inuse/no(%d/%d), sum(%d), qts(%.2f)", + reqState.Pooled, reqState.Nopooled, reqState.Inuse, reqState.Nouse, reqState.Sum, reqState.GetPerSec)) } }() } diff --git a/bili_danmu.go b/bili_danmu.go index c94dde0..cbccb95 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -9,7 +9,6 @@ import ( "os" "os/signal" "strconv" - "strings" "time" c "github.com/qydysky/bili_danmu/CV" @@ -28,13 +27,10 @@ import ( ws "github.com/qydysky/part/websocket" ) -//go:embed VERSION -var version string - func Start() { danmulog := c.C.Log.Base(`bilidanmu`) danmulog.L(`I: `, `当前PID:`, c.C.PID) - danmulog.L(`I: `, "version: ", strings.TrimSpace(version)) + danmulog.L(`I: `, "version: ", c.C.Version) //检查配置 if c.C.K_v.Len() == 0 { diff --git a/go.mod b/go.mod index 410092a..0d61f57 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/gotk3/gotk3 v0.6.2 github.com/mdp/qrterminal/v3 v3.2.0 - github.com/qydysky/part v0.28.20231215215733 + github.com/qydysky/part v0.28.20240101151147 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.14.0 diff --git a/go.sum b/go.sum index 6c45799..84dd7d8 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= 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/part v0.28.20231215215733 h1:qxbqSdoLUBG6o2VkKxM1IAaXoCQZcgLcmierFW9zwvc= -github.com/qydysky/part v0.28.20231215215733/go.mod h1:NyKyjpBCSjcHtKlC+fL5lCidm57UCnwEgufiBDs5yxA= +github.com/qydysky/part v0.28.20240101151147 h1:ugiSjvUjGWjdWGN3nJppcNAxGPHccFkUtDTcqnfUvJ4= +github.com/qydysky/part v0.28.20240101151147/go.mod h1:NyKyjpBCSjcHtKlC+fL5lCidm57UCnwEgufiBDs5yxA= 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