]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix 偶发异常资源高占用 (#179)
authorqydysky <qydysky@foxmail.com>
Sun, 2 Mar 2025 07:02:41 +0000 (15:02 +0800)
committerGitHub <noreply@github.com>
Sun, 2 Mar 2025 07:02:41 +0000 (15:02 +0800)
* Fix 偶发异常资源高占用

* Improve 优化

Reply/F/ass/ass.go
Reply/F/ass/ass_test.go
Reply/F/comp.go
go.mod
go.sum

index 70ab0f1a2ef9e080fd5f7b449cdf6191f9d112d5..31d6c1e96246aa1bafb9afe39c9e44e9d6fa819f 100644 (file)
@@ -7,6 +7,7 @@ import (
        "iter"
        "math"
        "strconv"
+       "strings"
        "unicode/utf8"
 
        "github.com/dustin/go-humanize"
@@ -20,7 +21,7 @@ var (
 )
 
 type i interface {
-       ToAss(savePath string)
+       ToAss(savePath string, filename ...string)
        Init(cfg any)
 }
 
@@ -93,8 +94,8 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
        }
 }
 
-func (t *Ass) ToAss(savePath string) {
-       f := file.New(savePath+"0.ass", 0, false)
+func (t *Ass) ToAss(savePath string, filename ...string) {
+       f := file.New(savePath+append(filename, "0.ass")[0], 0, false)
        defer f.Close()
        if f.IsExist() {
                _ = f.Delete()
@@ -104,8 +105,12 @@ func (t *Ass) ToAss(savePath string) {
        var lsd = make([]float64, lsSize)
        var lso = make([]float64, lsSize)
 
-       _, _ = f.Write([]byte(t.header), true)
-       for line := range loadCsv(savePath) {
+       var write bool
+       for line := range loadCsv(savePath, strings.Split(append(filename, "0.ass")[0], `.`)[0]+".csv") {
+               if !write {
+                       _, _ = f.Write([]byte(t.header), true)
+                       write = true
+               }
 
                danmul := utf8.RuneCountInString(line.Text)
                danmuSec := (float64(t.showSec*t.fontsize*danmul) / float64(t.fontsize*danmul+playResX))
@@ -142,9 +147,9 @@ func (t *Ass) ToAss(savePath string) {
        }
 }
 
-func loadCsv(savePath string) iter.Seq[Data] {
+func loadCsv(savePath string, filename ...string) iter.Seq[Data] {
        return func(yield func(Data) bool) {
-               csvf := file.New(savePath+"0.csv", 0, false)
+               csvf := file.New(savePath+append(filename, "0.csv")[0], 0, false)
                defer csvf.Close()
 
                if !csvf.IsExist() {
index d8bc7ed3e6b176dce05b1533f6868edc61b0c213..aaadf0b91914592bd3499544c02d497ed7aa2527 100644 (file)
@@ -8,10 +8,10 @@ import (
 
 func TestMain(t *testing.T) {
        var ass = comp.Get[interface {
-               ToAss(savePath string)
+               ToAss(savePath string, filename ...string)
                Init(cfg any)
        }](`ass`)
-       ass.ToAss("./testdata/")
+       ass.ToAss("./testdata/", "1.ass")
 }
 
 func TestStos(t *testing.T) {
index 4c4d702e43f6592ee2634d1c0b929860157103ba..f75d2b9c4a38393a3b50b338240b45d55fca0e4d 100644 (file)
@@ -25,7 +25,7 @@ var DanmuCountPerMin = comp.Get[interface {
 }](`danmuCountPerMin`)
 
 var Ass = comp.Get[interface {
-       ToAss(savePath string)
+       ToAss(savePath string, filename ...string)
        Init(cfg any)
 }](`ass`)
 
diff --git a/go.mod b/go.mod
index 4d12711c11b8739bc3355f2e6cfab7f4ece8b116..c520fac81db97d0fed0b2678be53d5471a27f0b3 100644 (file)
--- 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.20250225161111
+       github.com/qydysky/part v0.28.20250302064654
        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.22.0 // indirect
diff --git a/go.sum b/go.sum
index 4365d3f1db43efd4463658b741cda6efbd4cc5eb..2c426691aa76407be05ade9fd57cec0e8a31e3c3 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -46,8 +46,8 @@ github.com/qydysky/biliApi v0.0.0-20240725184407-15076dddb6fb h1:dtSpNF9hLQa09TU
 github.com/qydysky/biliApi v0.0.0-20240725184407-15076dddb6fb/go.mod h1:om024vfxALQ5vxsbaGoMm8IS0esLYBnEOpJI8FsGoDg=
 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.20250225161111 h1:34x3k9NeHpP2rfMaq6d5sm3Lru9QdxI3zcXT5JbgUOg=
-github.com/qydysky/part v0.28.20250225161111/go.mod h1:MsSAiZMiWQ5pGP5BCEB3OBsoAPaGykNB7vbeY3mKF2w=
+github.com/qydysky/part v0.28.20250302064654 h1:DpyB2t8PlwClebx2lDsUakDPNaDAXfOXLTzVH3xCb6k=
+github.com/qydysky/part v0.28.20250302064654/go.mod h1:MsSAiZMiWQ5pGP5BCEB3OBsoAPaGykNB7vbeY3mKF2w=
 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=