From 19635b9c19c1742fc45888f6b029ece08d5cc54a Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 24 Sep 2024 01:40:43 +0800 Subject: [PATCH] =?utf8?q?Improve=20=E8=A1=A8=E6=83=85=E4=BD=BF=E7=94=A8md?= =?utf8?q?5=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F/danmuEmotes/danmuEmotes.go | 113 ++++++++++++++--------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/Reply/F/danmuEmotes/danmuEmotes.go b/Reply/F/danmuEmotes/danmuEmotes.go index 22bd3f9..bca94ee 100644 --- a/Reply/F/danmuEmotes/danmuEmotes.go +++ b/Reply/F/danmuEmotes/danmuEmotes.go @@ -8,10 +8,9 @@ import ( c "github.com/qydysky/bili_danmu/CV" comp "github.com/qydysky/part/component" file "github.com/qydysky/part/file" + phash "github.com/qydysky/part/hash" log "github.com/qydysky/part/log" - ppool "github.com/qydysky/part/pool" reqf "github.com/qydysky/part/reqf" - pslice "github.com/qydysky/part/slice" ) // path @@ -20,21 +19,21 @@ var ( Hashr = comp.NewComp(func(ctx context.Context, s string) (r string, e error) { return hashr(s), nil }) - danmuPool = ppool.New(ppool.PoolFunc[pslice.Buf[byte]]{ - New: func() *pslice.Buf[byte] { - return pslice.New[byte]() - }, - InUse: func(b *pslice.Buf[byte]) bool { - return !b.IsEmpty() - }, - Reuse: func(b *pslice.Buf[byte]) *pslice.Buf[byte] { - return b - }, - Pool: func(b *pslice.Buf[byte]) *pslice.Buf[byte] { - b.Reset() - return b - }, - }, 100) + // danmuPool = ppool.New(ppool.PoolFunc[pslice.Buf[byte]]{ + // New: func() *pslice.Buf[byte] { + // return pslice.New[byte]() + // }, + // InUse: func(b *pslice.Buf[byte]) bool { + // return !b.IsEmpty() + // }, + // Reuse: func(b *pslice.Buf[byte]) *pslice.Buf[byte] { + // return b + // }, + // Pool: func(b *pslice.Buf[byte]) *pslice.Buf[byte] { + // b.Reset() + // return b + // }, + // }, 100) ) type Danmu struct { @@ -55,8 +54,7 @@ func saveEmote(ctx context.Context, ptr Danmu) (ret any, err error) { *ptr.Msg = "[" + *ptr.Msg + emoticon_unique + "]" } } - *ptr.Msg = hashr(*ptr.Msg) - savePath := "emots/" + *ptr.Msg + ".png" + savePath := "emots/" + hashr(*ptr.Msg) + ".png" if !file.New(savePath, 0, true).IsExist() { go func() { req := c.C.ReqPool.Get() @@ -91,7 +89,6 @@ func saveEmote(ctx context.Context, ptr Danmu) (ret any, err error) { if e := json.Unmarshal([]byte(extrab), &E); e != nil { return nil, e } else { - *ptr.Msg = hashr(*ptr.Msg) for k, v := range E.Emots { m, ok := v.(map[string]any) if !ok { @@ -138,42 +135,44 @@ func saveEmote(ctx context.Context, ptr Danmu) (ret any, err error) { } func hashr(s string) (r string) { - buf := danmuPool.Get() - defer danmuPool.Put(buf) + return phash.Md5String(s) - emoteB := false - for i := 0; i < len(s); i++ { - if !emoteB { - _ = buf.Append([]byte{s[i]}) - emoteB = s[i] == '[' - continue - } else if s[i] == ']' { - _ = buf.Append([]byte{s[i]}) - emoteB = false - continue - } - switch s[i] { - case '\\': - _ = buf.Append([]byte("_1")) - case '/': - _ = buf.Append([]byte("_2")) - case '*': - _ = buf.Append([]byte("_3")) - case '<': - _ = buf.Append([]byte("_4")) - case '>': - _ = buf.Append([]byte("_5")) - case '|': - _ = buf.Append([]byte("_6")) - case ':': - _ = buf.Append([]byte(":")) - case '?': - _ = buf.Append([]byte("?")) - case '"': - _ = buf.Append([]byte("“")) - default: - _ = buf.Append([]byte{s[i]}) - } - } - return string(buf.GetCopyBuf()) + // buf := danmuPool.Get() + // defer danmuPool.Put(buf) + + // emoteB := false + // for i := 0; i < len(s); i++ { + // if !emoteB { + // _ = buf.Append([]byte{s[i]}) + // emoteB = s[i] == '[' + // continue + // } else if s[i] == ']' { + // _ = buf.Append([]byte{s[i]}) + // emoteB = false + // continue + // } + // switch s[i] { + // case '\\': + // _ = buf.Append([]byte("_1")) + // case '/': + // _ = buf.Append([]byte("_2")) + // case '*': + // _ = buf.Append([]byte("_3")) + // case '<': + // _ = buf.Append([]byte("_4")) + // case '>': + // _ = buf.Append([]byte("_5")) + // case '|': + // _ = buf.Append([]byte("_6")) + // case ':': + // _ = buf.Append([]byte(":")) + // case '?': + // _ = buf.Append([]byte("?")) + // case '"': + // _ = buf.Append([]byte("“")) + // default: + // _ = buf.Append([]byte{s[i]}) + // } + // } + // return string(buf.GetCopyBuf()) } -- 2.39.2