]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve 自动化检查 (#68)
authorqydysky <qydysky@foxmail.com>
Tue, 18 Apr 2023 18:52:22 +0000 (02:52 +0800)
committerGitHub <noreply@github.com>
Tue, 18 Apr 2023 18:52:22 +0000 (02:52 +0800)
golangci-lint,Codecov

21 files changed:
.github/workflows/go.yml
.github/workflows/test.yml
.gitignore
CV/Var.go
F/CookieCrypo.go
F/api.go
README.md
Reply/F.go
Reply/Msg.go
Reply/Reply.go
Reply/flvDecode.go
Reply/flvDecode_test.go
Reply/fmp4Decode.go
Reply/fmp4Decode_test.go
Reply/stream.go
Reply/test/0.flv [new file with mode: 0644]
Reply/test/0.mp4 [new file with mode: 0644]
Reply/tts.go
Send/Send.go
bili_danmu.go
cmd/cmd.go

index 1da45b2d34349271073fdbdda9f4922b558a8a90..711510b517ebccbb6ded206c49be6b6e4c113752 100644 (file)
@@ -22,7 +22,25 @@ jobs:
 
     - name: Check out code
       uses: actions/checkout@v3
-            
+
+    - name: golangci-lint
+      uses: golangci/golangci-lint-action@v3
+      with:
+        args: --timeout 3m --verbose
+        
+    - name: Test
+      run: |
+        sudo apt-get update
+        sudo apt-get install libgtk-3-dev libcairo2-dev libglib2.0-dev
+        go get .
+        CGO_ENABLED=0 go test -v --cover -coverprofile=coverage ./...
+
+    - name: Codecov
+      uses: codecov/codecov-action@v3
+      with:
+        token: ${{secrets.CODECOV_TOKEN}}
+        file: coverage
+      
     - name: Build
       run: |
         sudo apt-get update
@@ -56,6 +74,23 @@ jobs:
     - name: Check out code
       uses: actions/checkout@v3
 
+    - name: golangci-lint
+      uses: golangci/golangci-lint-action@v3
+      with:
+        args: --timeout 3m --verbose
+
+    - name: Test
+      run: |
+        set CGO_ENABLED=0
+        go get .
+        go test -v --cover -coverprofile=coverage ./...
+        
+    - name: Codecov
+      uses: codecov/codecov-action@v3
+      with:
+        token: ${{secrets.CODECOV_TOKEN}}
+        file: coverage
+      
     - name: Build
       run: |
         cd demo
index f2e77d54d7b2ae91ff431254582be3162556fb7f..0e80d1ae4c6d79f3dda503d00df7b9029328e2e3 100644 (file)
@@ -5,6 +5,7 @@ on:
     branches:
       - '**'
     paths:
+      - '**.yml'
       - '**.go'
       - '**.mod'
       - '**.sum'
@@ -24,12 +25,30 @@ jobs:
 
     - name: Check out code
       uses: actions/checkout@v3
-    
-    - name: Build
+
+    - name: golangci-lint
+      uses: golangci/golangci-lint-action@v3
+      with:
+        args: --timeout 3m --verbose
+
+    - name: Test
       run: |
         sudo apt-get update
         sudo apt-get install libgtk-3-dev libcairo2-dev libglib2.0-dev
+        go get .
+        CGO_ENABLED=0 go test -v --cover -coverprofile=coverage ./...
+
+    - name: Codecov
+      uses: codecov/codecov-action@v3
+      with:
+        token: ${{secrets.CODECOV_TOKEN}}
+        file: coverage
+      
+    - name: Build
+      run: |
         cd demo
+        sudo apt-get update
+        sudo apt-get install libgtk-3-dev libcairo2-dev libglib2.0-dev
         go get .
         CGO_ENABLED=0 go build -v -buildmode=exe -o demo.run main.go
       
@@ -55,7 +74,24 @@ jobs:
 
     - name: Check out code
       uses: actions/checkout@v3
-            
+
+    - name: golangci-lint
+      uses: golangci/golangci-lint-action@v3
+      with:
+        args: --timeout 3m --verbose
+
+    - name: Test
+      run: |
+        set CGO_ENABLED=0
+        go get .
+        go test -v --cover -coverprofile=coverage ./...
+
+    - name: Codecov
+      uses: codecov/codecov-action@v3
+      with:
+        token: ${{secrets.CODECOV_TOKEN}}
+        file: coverage
+        
     - name: Build
       run: |
         cd demo
index 12f61739950bcfc375a04cee5ab7854881cc114f..6b272a80a7558688180473530da581dc654a09c6 100644 (file)
@@ -22,6 +22,8 @@ demo/live
 demo/main.exe
 *.m4s
 *.m3u8
-*.flv
 demo/build.bat
 demo/build.sh
+Reply/0.flv.log
+demo/coverage.txt
+coverage.txt
index 355c84600627d450d2a22610ad92540e58e2798a..1297701cb3c6c6eacdbf7e1345aced6a104a7bf7 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -184,7 +184,7 @@ func (t *Common) ValidLive() *LiveQn {
        return nil
 }
 
-func (t *Common) Init() Common {
+func (t *Common) Init() *Common {
        t.PID = os.Getpid()
        t.StartT = time.Now()
 
@@ -255,7 +255,11 @@ func (t *Common) Init() Common {
        t.Roomid = *roomIdP
 
        if e := t.loadConf(*ckv); e != nil {
-               panic(e)
+               if os.IsNotExist(e) {
+                       fmt.Println("未能加载配置文件")
+               } else {
+                       panic(e)
+               }
        }
 
        go func() {
@@ -361,18 +365,22 @@ func (t *Common) Init() Common {
                t.Log = t.Log.Level(logmap)
        }
 
-       return *t
+       return t
 }
 
 func (t *Common) loadConf(customConf string) error {
        var data map[string]interface{}
 
        // 64k
-       if bb, e := file.New("config/config_K_v.json", 0, true).ReadAll(100, 1<<16); e != nil {
+       f := file.New("config/config_K_v.json", 0, true)
+       if !f.IsExist() {
+               return os.ErrNotExist
+       }
+       if bb, e := f.ReadAll(100, 1<<16); e != nil {
                if !errors.Is(e, io.EOF) {
                        return e
                } else {
-                       json.Unmarshal(bb, &data)
+                       _ = json.Unmarshal(bb, &data)
                }
        }
 
@@ -401,7 +409,7 @@ func (t *Common) loadConf(customConf string) error {
                                return fmt.Errorf("无法获取自定义配置文件 %d", req.Response.StatusCode)
                        } else {
                                var tmp map[string]interface{}
-                               json.Unmarshal(req.Respon, &tmp)
+                               _ = json.Unmarshal(req.Respon, &tmp)
                                for k, v := range tmp {
                                        data[k] = v
                                }
@@ -412,7 +420,7 @@ func (t *Common) loadConf(customConf string) error {
                        if bb, err := file.New(customConf, 0, true).ReadAll(100, 1<<16); err != nil {
                                if errors.Is(err, io.EOF) {
                                        var tmp map[string]interface{}
-                                       json.Unmarshal(bb, &tmp)
+                                       _ = json.Unmarshal(bb, &tmp)
                                        for k, v := range tmp {
                                                data[k] = v
                                        }
@@ -454,5 +462,5 @@ func (t ResStruct) Write(w http.ResponseWriter) {
                t.Message = e.Error()
                data, _ = json.Marshal(t)
        }
-       w.Write(data)
+       _, _ = w.Write(data)
 }
index 95873423b913e813ebe740185a57719ae5afb620..c6a8fca86ebe6f1fefef6cda89ab66538d00ba3a 100644 (file)
@@ -72,8 +72,8 @@ func CookieSet(source []byte) {
                        }
                } else {
                        f := file.New(`cookie.txt`, 0, true)
-                       f.Delete()
-                       f.Write(append([]byte("nol"), source...), true)
+                       _ = f.Delete()
+                       _, _ = f.Write(append([]byte("nol"), source...), true)
                        return
                }
        }
@@ -82,7 +82,7 @@ func CookieSet(source []byte) {
                return
        } else {
                f := file.New(`cookie.txt`, 0, true)
-               f.Delete()
-               f.Write(append([]byte("pem"), source...), true)
+               _ = f.Delete()
+               _, _ = f.Write(append([]byte("pem"), source...), true)
        }
 }
index 968484a9f80bbbfefe275b7ab1eb54bfa57280b1..95098ee46425ef1f6f2122389e5c123f90f7b090 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -1311,8 +1311,7 @@ func (c *GetFunc) Get_cookie() (missKey []string) {
        }
 
        { //生成二维码
-               qr.WriteFile(img_url, qr.Medium, 256, `qr.png`)
-               if !p.Checkfile().IsExist(`qr.png`) {
+               if e := qr.WriteFile(img_url, qr.Medium, 256, `qr.png`); e != nil || !p.Checkfile().IsExist(`qr.png`) {
                        apilog.L(`E: `, `qr error`)
                        return
                }
@@ -1320,10 +1319,10 @@ func (c *GetFunc) Get_cookie() (missKey []string) {
                //启动web
                if scanPath, ok := c.K_v.LoadV("扫码登录路径").(string); ok && scanPath != "" {
                        c.SerF.Store(scanPath, func(w http.ResponseWriter, _ *http.Request) {
-                               file.New("qr.png", 0, true).CopyToIoWriter(w, humanize.MByte, true)
+                               _ = file.New("qr.png", 0, true).CopyToIoWriter(w, humanize.MByte, true)
                        })
                        if c.K_v.LoadV(`扫码登录自动打开标签页`).(bool) {
-                               open.Run(`http://127.0.0.1:` + c.Stream_url.Port() + scanPath)
+                               _ = open.Run(`http://127.0.0.1:` + c.Stream_url.Port() + scanPath)
                        }
                        apilog.L(`W: `, `或打开链接扫码登录:`+c.Stream_url.String()+scanPath)
                }
@@ -1555,7 +1554,7 @@ func Get_weared_medal() (item J.GetWearedMedal_Data) {
                case []interface{}:
                default:
                        if data, err := json.Marshal(res.Data); err == nil {
-                               json.Unmarshal(data, &item)
+                               _ = json.Unmarshal(data, &item)
                        }
                }
 
@@ -1832,7 +1831,7 @@ func (c *GetFunc) Get_LIVE_BUVID() (missKey []string) {
                }
 
                //cookie
-               save_cookie(req.Response.Cookies())
+               _ = save_cookie(req.Response.Cookies())
                var has bool
                for k := range reqf.Cookies_List_2_Map(req.Response.Cookies()) {
                        if k == `LIVE_BUVID` {
@@ -2102,7 +2101,7 @@ func (c *GetFunc) Silver_2_coin() (missKey []string) {
                        return
                }
 
-               save_cookie(req.Response.Cookies())
+               _ = save_cookie(req.Response.Cookies())
 
                var res struct {
                        Code    int    `json:"code"`
index 42cd8e6d8e7b56eefde15e3b1d7552f64639a36d..cf659e39e3543bc6cb8f6c99a7fa09b92c1f88b4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 ## 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/Codecov/graph/badge.svg?token=2R7031P47C)](https://codecov.io/gh/qydysky/bili_danmu)
 
 ### 当前支持显示/功能
 
index 626cdb6cf3e0b76ec7f080c041319047c0084edd..f6d42ae85d660d4de68320b526a2820849fea560 100644 (file)
@@ -213,7 +213,7 @@ func Ass_f(contextC context.Context, save_path string, filePath string, st time.
                        Coder:     ass.wrap,
                },
        }
-       f.Write([]byte(ass.header), true)
+       _, _ = f.Write([]byte(ass.header), true)
        ass.startT = st
 
        <-contextC.Done()
@@ -264,10 +264,10 @@ func dtos(t time.Duration) string {
 var streamO = new(sync.Map)
 
 // 获取实例的Common
-func StreamOCommon(roomid int) (array []c.Common) {
+func StreamOCommon(roomid int) (array []*c.Common) {
        if roomid != -1 { //返回特定房间
                if v, ok := streamO.Load(roomid); ok {
-                       return []c.Common{v.(*M4SStream).Common()}
+                       return []*c.Common{v.(*M4SStream).Common()}
                }
        } else { //返回所有
                streamO.Range(func(_, v interface{}) bool {
@@ -298,7 +298,7 @@ func StreamOStart(roomid int) {
 
        var tmp = new(M4SStream)
 
-       if e := tmp.LoadConfig(*c.C.Copy()); e != nil {
+       if e := tmp.LoadConfig(c.C.Copy()); e != nil {
                flog.L(`E: `, e)
                return
        }
@@ -543,12 +543,16 @@ var danmuji = Danmuji{
 }
 
 func init() { //初始化反射型弹幕机
-       bb, err := file.New("config/config_auto_reply.json", 0, true).ReadAll(100, 1<<16)
+       f := file.New("config/config_auto_reply.json", 0, true)
+       if !f.IsExist() {
+               return
+       }
+       bb, err := f.ReadAll(100, 1<<16)
        if !errors.Is(err, io.EOF) {
                return
        }
        var buf map[string]interface{}
-       json.Unmarshal(bb, &buf)
+       _ = json.Unmarshal(bb, &buf)
        for k, v := range buf {
                if k == v {
                        continue
@@ -920,23 +924,23 @@ func (t *saveToJson) Init() {
        t.once.Do(func() {
                if path, ok := c.C.K_v.LoadV(`save_to_json`).(string); ok && path != `` {
                        f := file.New(path, 0, false)
-                       f.Delete()
-                       f.Write([]byte("["), true)
+                       _ = f.Delete()
+                       _, _ = f.Write([]byte("["), true)
                        f.Close()
 
                        t.msg = msgq.NewType[[]byte]()
                        t.msg.Pull_tag(map[string]func([]byte) (disable bool){
                                `data`: func(b []byte) (disable bool) {
                                        f := file.New(path, -1, false)
-                                       f.Write(b, true)
-                                       f.Write([]byte(","), true)
+                                       _, _ = f.Write(b, true)
+                                       _, _ = f.Write([]byte(","), true)
                                        f.Close()
                                        return false
                                },
                                `stop`: func(_ []byte) (disable bool) {
                                        f := file.New(path, -1, false)
-                                       f.Seed(-1, 2)
-                                       f.Write([]byte("]"), true)
+                                       _ = f.Seed(-1, 2)
+                                       _, _ = f.Write([]byte("]"), true)
                                        f.Close()
                                        return true
                                },
@@ -964,7 +968,7 @@ func Entry_danmu() {
        flog := flog.Base_add(`进房弹幕`)
 
        //检查与切换粉丝牌,只在cookie存在时启用
-       F.Get(&c.C).Get(`CheckSwitch_FansMedal`)
+       F.Get(c.C).Get(`CheckSwitch_FansMedal`)
 
        if v, _ := c.C.K_v.LoadV(`进房弹幕_有粉丝牌时才发`).(bool); v && c.C.Wearing_FansMedal == 0 {
                flog.L(`T: `, `无粉丝牌`)
@@ -1070,7 +1074,7 @@ func AutoSend_silver_gift() {
        }
 
        if c.C.UpUid == 0 {
-               F.Get(&c.C).Get(`UpUid`)
+               F.Get(c.C).Get(`UpUid`)
        }
 
        for _, v := range F.Gift_list() {
@@ -1161,7 +1165,7 @@ func init() {
                        } else if strings.HasSuffix(p, ".html") {
                                w.Header().Set("content-type", "text/html")
                        }
-                       f.CopyToIoWriter(w, humanize.MByte, true)
+                       _ = f.CopyToIoWriter(w, humanize.MByte, true)
                })
 
                // 直播流文件列表api
@@ -1234,7 +1238,7 @@ func init() {
                        } else if strings.HasSuffix(p, ".html") {
                                w.Header().Set("content-type", "text/html")
                        }
-                       f.CopyToIoWriter(w, humanize.MByte, true)
+                       _ = f.CopyToIoWriter(w, humanize.MByte, true)
                })
 
                // 流地址
index 7fb4c0b159b4c6815616d34b92647e25ca1f7482..3e1ab447e902a04b868ba0a69af377d88c687731 100644 (file)
@@ -127,12 +127,16 @@ var Msg_map = map[string]func(replyF, string){
 // 屏蔽不需要的消息
 func init() {
        { //加载不需要的消息
-               bb, err := file.New("config/config_disable_msg.json", 0, true).ReadAll(100, 1<<16)
+               f := file.New("config/config_disable_msg.json", 0, true)
+               if !f.IsExist() {
+                       return
+               }
+               bb, err := f.ReadAll(100, 1<<16)
                if !errors.Is(err, io.EOF) {
                        return
                }
                var buf map[string]interface{}
-               json.Unmarshal(bb, &buf)
+               _ = json.Unmarshal(bb, &buf)
                for k, v := range buf {
                        if able, ok := v.(bool); ok { //设置为true时,使用默认显示
                                if able {
index 61c7111aefbac4b62672624add5589f2b4799fdd..d2cc1f15c93ec9536802d5d07fb2cb6a4ece8cc6 100644 (file)
@@ -333,16 +333,16 @@ func (replyF) user_toast_msg(s string) {
        { //额外 ass 私信
                Assf(fmt.Sprintln(sh...))
                c.C.Danmu_Main_mq.Push_tag(`guard_update`, nil) //使用连续付费的新舰长无法区分,刷新舰长数
-               if uid != 0 {
+               if msg := c.C.K_v.LoadV(`上舰私信`).(string); uid != 0 && msg != "" {
                        c.C.Danmu_Main_mq.Push_tag(`pm`, send.Pm_item{
                                Uid: uid,
-                               Msg: c.C.K_v.LoadV(`上舰私信`).(string),
+                               Msg: msg,
                        }) //上舰私信
                }
-               if c.C.K_v.LoadV(`额外私信对象`).(float64) != 0 {
+               if msg, uid := c.C.K_v.LoadV(`上舰私信(额外)`).(string), c.C.K_v.LoadV(`额外私信对象`).(float64); uid != 0 && msg != "" {
                        c.C.Danmu_Main_mq.Push_tag(`pm`, send.Pm_item{
-                               Uid: int(c.C.K_v.LoadV(`额外私信对象`).(float64)),
-                               Msg: c.C.K_v.LoadV(`上舰私信(额外)`).(string),
+                               Uid: int(uid),
+                               Msg: msg,
                        }) //上舰私信-对额外
                }
        }
@@ -456,7 +456,7 @@ func (replyF) watched_change(s string) {
                return
        }
        var data ws_msg.WATCHED_CHANGE
-       json.Unmarshal([]byte(s), &data)
+       _ = json.Unmarshal([]byte(s), &data)
        // fmt.Printf("\t观看人数:%d\n", watched)
        if data.Data.Num == c.C.Watched {
                return
@@ -1093,7 +1093,7 @@ func (replyF) danmu(s string) {
 
        { //附加功能 弹幕机 封禁 弹幕合并
                //对指定弹幕重新录制
-               danmuReLiveTriger.Init(&c.C)
+               danmuReLiveTriger.Init(c.C)
                danmuReLiveTriger.Check(item.uid, item.msg)
                go Danmujif(item.msg)
                // if Autobanf(item.msg) {
@@ -1172,16 +1172,20 @@ func Msg_showdanmu(item Danmu_item) {
                                })
                        }
                        if i, e := strconv.Atoi(item.uid); e == nil {
-                               c.C.Danmu_Main_mq.Push_tag(`pm`, send.Pm_item{
-                                       Uid: i,
-                                       Msg: c.C.K_v.LoadV(`弹幕私信`).(string),
-                               }) //上舰私信
+                               if msg := c.C.K_v.LoadV(`弹幕私信`).(string); msg != "" {
+                                       c.C.Danmu_Main_mq.Push_tag(`pm`, send.Pm_item{
+                                               Uid: i,
+                                               Msg: msg,
+                                       }) //上舰私信
+                               }
                        }
                        if c.C.K_v.LoadV(`额外私信对象`).(float64) != 0 {
-                               c.C.Danmu_Main_mq.Push_tag(`pm`, send.Pm_item{
-                                       Uid: int(c.C.K_v.LoadV(`额外私信对象`).(float64)),
-                                       Msg: c.C.K_v.LoadV(`弹幕私信(额外)`).(string),
-                               }) //上舰私信-对额外
+                               if msg, uid := c.C.K_v.LoadV(`上舰私信(额外)`).(string), c.C.K_v.LoadV(`额外私信对象`).(float64); uid != 0 && msg != "" {
+                                       c.C.Danmu_Main_mq.Push_tag(`pm`, send.Pm_item{
+                                               Uid: int(uid),
+                                               Msg: msg,
+                                       }) //上舰私信-对额外
+                               }
                        }
                }
        }
index 5fd20ceec795d1e42267f0051df367a3bba4d78a..9912c2dfc675babba498ff9c5441cd07a7a77d78 100644 (file)
@@ -57,7 +57,7 @@ func Search_stream_tag(buf []byte, keyframe *slice.Buf[byte]) (front_buf []byte,
                        front_buf = []byte{}
                }
                if bufl := keyframe.Size(); confirm_num != bufl {
-                       keyframe.RemoveBack(bufl - confirm_num)
+                       _ = keyframe.RemoveBack(bufl - confirm_num)
                }
        }()
 
@@ -141,11 +141,11 @@ func Search_stream_tag(buf []byte, keyframe *slice.Buf[byte]) (front_buf []byte,
                        }
 
                        if keyframe_num >= 0 {
-                               keyframe.Append(buf[tag_offset : tag_offset+tag_size_check+previou_tag_size])
+                               _ = keyframe.Append(buf[tag_offset : tag_offset+tag_size_check+previou_tag_size])
                        }
                } else if buf[tag_offset] == audio_tag {
                        if keyframe_num >= 0 {
-                               keyframe.Append(buf[tag_offset : tag_offset+tag_size_check+previou_tag_size])
+                               _ = keyframe.Append(buf[tag_offset : tag_offset+tag_size_check+previou_tag_size])
                        }
                }
 
index 3ffae5a26b2d0b4abeec29f0cf09fb69851dac3c..f78638d0dd222261149db06d1f2974076da70fc0 100644 (file)
@@ -12,10 +12,10 @@ import (
 )
 
 func Test_FLVdeal(t *testing.T) {
-       flog := file.New("E:\\test\\0.flv.log", 0, false)
-       flog.Delete()
+       flog := file.New("0.flv.log", 0, false)
+       _ = flog.Delete()
        defer flog.Close()
-       f := file.New("E:\\test\\0.flv", 0, false)
+       f := file.New("test/0.flv", 0, false)
        defer f.Close()
 
        if f.IsDir() || !f.IsExist() {
@@ -32,7 +32,7 @@ func Test_FLVdeal(t *testing.T) {
                        t.Log("reach end")
                        break
                }
-               buff.Append(buf[:n])
+               _ = buff.Append(buf[:n])
                if s := buff.Size(); max < s {
                        max = s
                }
@@ -41,9 +41,9 @@ func Test_FLVdeal(t *testing.T) {
                if e != nil {
                        t.Fatal(e)
                }
-               flog.Write([]byte(fmt.Sprintf("%d %d %d %d\n", c, len(front_buf), keyframe.Size(), last_available_offset)), true)
+               _, _ = flog.Write([]byte(fmt.Sprintf("%d %d %d %d\n", c, len(front_buf), keyframe.Size(), last_available_offset)), true)
                t.Log(c, len(front_buf), keyframe.Size())
-               buff.RemoveFront(last_available_offset)
+               _ = buff.RemoveFront(last_available_offset)
        }
        t.Log("max", humanize.Bytes(uint64(max)))
 }
index 938fd7dce96064ceee55c124e930f17323b50871..ba055cd0643f20ccb7873e366a98695d6707b794 100644 (file)
@@ -243,7 +243,7 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte])
                                //deal frame
                                if keyframeMoof {
                                        if v, e := t.buf.HadModified(bufModified); e == nil && v && !t.buf.IsEmpty() {
-                                               keyframe.Append(t.buf.GetPureBuf())
+                                               _ = keyframe.Append(t.buf.GetPureBuf())
                                                cu = m[0].i
                                                t.buf.Reset()
                                        }
@@ -252,7 +252,7 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte])
                                        cu = m[6].e
                                }
                                if haveKeyframe {
-                                       t.buf.Append(buf[m[0].i:m[6].e])
+                                       _ = t.buf.Append(buf[m[0].i:m[6].e])
                                }
                                return false
                        },
@@ -332,7 +332,7 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte])
                                //deal frame
                                if keyframeMoof {
                                        if v, e := t.buf.HadModified(bufModified); e == nil && v && !t.buf.IsEmpty() {
-                                               keyframe.Append(t.buf.GetPureBuf())
+                                               _ = keyframe.Append(t.buf.GetPureBuf())
                                                cu = m[0].i
                                                t.buf.Reset()
                                        }
@@ -341,7 +341,7 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte])
                                        cu = m[10].e
                                }
                                if haveKeyframe {
-                                       t.buf.Append(buf[m[0].i:m[10].e])
+                                       _ = t.buf.Append(buf[m[0].i:m[10].e])
                                }
                                return false
                        }})
index 7ea6ffdff15f6ac283c33ba24cdb808768210b00..6fca601e50b8e507db1431c6319cb78deb444a2a 100644 (file)
@@ -12,10 +12,10 @@ import (
 )
 
 func Test_deal(t *testing.T) {
-       flog := file.New("E:\\test\\0.flv.log", 0, false)
-       flog.Delete()
+       flog := file.New("0.mp4.log", 0, false)
+       _ = flog.Delete()
        defer flog.Close()
-       f := file.New("E:\\test\\0.mp4", 0, false)
+       f := file.New("test/0.mp4", 0, false)
        defer f.Close()
 
        if f.IsDir() || !f.IsExist() {
@@ -33,7 +33,7 @@ func Test_deal(t *testing.T) {
                        t.Log("reach end")
                        break
                }
-               buff.Append(buf[:n])
+               _ = buff.Append(buf[:n])
                if s := buff.Size(); max < s {
                        max = s
                }
@@ -54,9 +54,9 @@ func Test_deal(t *testing.T) {
                        t.Log("front_buf")
                        break
                }
-               flog.Write([]byte(fmt.Sprintf("%d %d\n", c, len(front_buf))), true)
+               _, _ = flog.Write([]byte(fmt.Sprintf("%d %d\n", c, len(front_buf))), true)
                t.Log(c, len(front_buf))
-               buff.RemoveFront(last_available_offset)
+               _ = buff.RemoveFront(last_available_offset)
        }
        t.Log("max", humanize.Bytes(uint64(max)))
 }
index e88cab556114502a14acda6d89735332f00ce9bb..9cd372a7a9e9e2ebb9e1cc46dd107491c02d6aeb 100644 (file)
@@ -47,7 +47,7 @@ type M4SStream struct {
        boot_buf_locker   funcCtrl.BlockFunc
        last_m4s          *m4s_link_item           //最后一个切片
        m4s_pool          *pool.Buf[m4s_link_item] //切片pool
-       common            c.Common                 //通用配置副本
+       common            *c.Common                //通用配置副本
        Current_save_path string                   //明确的直播流保存目录
        // 事件周期 start: 开始实例 startRec:开始录制 load:接收到视频头 cut:切 stopRec:结束录制 stop:结束实例
        msg               *msgq.MsgType[*M4SStream] //实例的各种事件回调
@@ -138,11 +138,11 @@ func (t *M4SStream) putM4s(ms ...*m4s_link_item) {
        t.m4s_pool.Put(ms...)
 }
 
-func (t *M4SStream) Common() c.Common {
+func (t *M4SStream) Common() *c.Common {
        return t.common
 }
 
-func (t *M4SStream) LoadConfig(common c.Common) (e error) {
+func (t *M4SStream) LoadConfig(common *c.Common) (e error) {
        t.common = common
        t.log = common.Log.Base(`直播流保存`)
 
@@ -189,7 +189,7 @@ func (t *M4SStream) getFirstBuf() []byte {
 func (t *M4SStream) fetchCheckStream() bool {
        // 获取流地址
        t.common.Live_want_qn = t.config.want_qn
-       if F.Get(&t.common).Get(`Live`); len(t.common.Live) == 0 {
+       if F.Get(t.common).Get(`Live`); len(t.common.Live) == 0 {
                return false
        }
 
@@ -563,7 +563,7 @@ func (t *M4SStream) getSavepath() {
                t.log.L(`I: `, "保存到", rel+`/0.`+t.stream_type)
                f := file.New(t.config.save_path+"tmp.create", 0, true)
                f.Create()
-               f.Delete()
+               _ = f.Delete()
        } else {
                t.log.L(`W: `, err)
        }
@@ -726,7 +726,7 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                defer ticker.Stop()
                                for {
                                        n, e := rc.Read(buf)
-                                       buff.Append(buf[:n])
+                                       _ = buff.Append(buf[:n])
                                        if e != nil {
                                                t.Stream_msg.PushLock_tag(`close`, nil)
                                                break
@@ -767,7 +767,7 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                                }
                                                if last_available_offset > 1 {
                                                        // fmt.Println("write Sync")
-                                                       buff.RemoveFront(last_available_offset - 1)
+                                                       _ = buff.RemoveFront(last_available_offset - 1)
                                                }
                                        }
                                }
@@ -778,7 +778,7 @@ func (t *M4SStream) saveStreamFlv() (e error) {
 
                        t.log.L(`I: `, `flv下载开始`)
 
-                       r.Reqf(reqf.Rval{
+                       _ = r.Reqf(reqf.Rval{
                                Url:              surl.String(),
                                SaveToPipeWriter: rw,
                                NoResponse:       true,
@@ -908,7 +908,7 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                                                link.status = 3 // 设置切片状态为下载失败
                                        } else {
                                                link.data.Reset()
-                                               link.data.Append(r.Respon)
+                                               _ = link.data.Append(r.Respon)
                                                link.status = 2 // 设置切片状态为下载完成
                                        }
                                }(v)
@@ -970,7 +970,7 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                                continue
                        }
 
-                       buf.Append(download_seq[k].data.GetPureBuf())
+                       _ = buf.Append(download_seq[k].data.GetPureBuf())
                        t.putM4s(download_seq[k])
                        download_seq = append(download_seq[:k], download_seq[k+1:]...)
                        k -= 1
@@ -1005,7 +1005,7 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                                t.Stream_msg.PushLock_tag(`data`, t.boot_buf)
                        }
 
-                       buf.RemoveFront(last_available_offset)
+                       _ = buf.RemoveFront(last_available_offset)
                }
 
                // 停止录制
@@ -1093,7 +1093,7 @@ func (t *M4SStream) Start() bool {
        }
 
        // 是否在直播
-       F.Get(&t.common).Get(`Liveing`)
+       F.Get(t.common).Get(`Liveing`)
        if !t.common.Liveing {
                t.log.L(`W: `, `未直播`)
                return false
@@ -1219,7 +1219,7 @@ func (t *M4SStream) Start() bool {
                // 主循环
                for t.Status.Islive() {
                        // 是否在直播
-                       F.Get(&t.common).Get(`Liveing`)
+                       F.Get(t.common).Get(`Liveing`)
                        if !t.common.Liveing {
                                t.log.L(`W: `, `未直播`)
                                break
@@ -1258,13 +1258,13 @@ func (t *M4SStream) Stop() {
 func (t *M4SStream) PusherToFile(contextC context.Context, filepath string, startFunc func(*M4SStream) error, stopFunc func(*M4SStream) error) error {
        f := file.New(filepath, 0, false)
        defer f.Close()
-       f.Delete()
+       _ = f.Delete()
 
        if e := startFunc(t); e != nil {
                return e
        }
 
-       f.Write(t.getFirstBuf(), true)
+       _, _ = f.Write(t.getFirstBuf(), true)
        t.Stream_msg.Pull_tag(map[string]func([]byte) bool{
                `data`: func(b []byte) bool {
                        select {
@@ -1275,7 +1275,7 @@ func (t *M4SStream) PusherToFile(contextC context.Context, filepath string, star
                        if len(b) == 0 {
                                return true
                        }
-                       f.Write(b, true)
+                       _, _ = f.Write(b, true)
                        return false
                },
                `close`: func(_ []byte) bool {
diff --git a/Reply/test/0.flv b/Reply/test/0.flv
new file mode 100644 (file)
index 0000000..f274b63
Binary files /dev/null and b/Reply/test/0.flv differ
diff --git a/Reply/test/0.mp4 b/Reply/test/0.mp4
new file mode 100644 (file)
index 0000000..e62a4a4
Binary files /dev/null and b/Reply/test/0.mp4 differ
index 670fa3eea1a8f182e3d1b688cae1f7aefffe9d69..d0e3fd50f10979d09b81bcecbd80c427d65ea716 100644 (file)
@@ -78,12 +78,16 @@ func init() {
                        }
                }
 
-               bb, err := file.New("config/config_tts.json", 0, true).ReadAll(100, 1<<16)
+               f := file.New("config/config_tts.json", 0, true)
+               if !f.IsExist() {
+                       return
+               }
+               bb, err := f.ReadAll(100, 1<<16)
                if !errors.Is(err, io.EOF) {
                        return
                }
                var buf map[string]interface{}
-               json.Unmarshal(bb, &buf)
+               _ = json.Unmarshal(bb, &buf)
                if onoff, ok := buf[`onoff`]; ok {
                        for k, v := range onoff.(map[string]interface{}) {
                                tts_setting_string[k] = v.(string)
@@ -404,7 +408,7 @@ func init() {
                                        }
                                }
                                if len(buf) != 0 {
-                                       file.New(sys.Sys().Cdir()+`/tts.mp3`, 0, true).Write(buf, true)
+                                       _, _ = file.New(sys.Sys().Cdir()+`/tts.mp3`, 0, true).Write(buf, true)
                                        play()
                                }
                                xfwsClient.Close()
index e0354ceeed590ae69466ae2e7fcd2dc593fd51e7..7903f0330cc84d2b3b452e86540d9aa412167d23 100644 (file)
@@ -20,12 +20,16 @@ var damnu_official = make(map[string]string)
 
 // 初始化表情代码
 func init() {
-       bb, err := file.New("config/config_danmu_official.json", 0, true).ReadAll(1000, 1<<16)
+       f := file.New("config/config_danmu_official.json", 0, true)
+       if !f.IsExist() {
+               return
+       }
+       bb, err := f.ReadAll(1000, 1<<16)
        if !errors.Is(err, io.EOF) {
                return
        }
        var buf map[string]interface{}
-       json.Unmarshal(bb, &buf)
+       _ = json.Unmarshal(bb, &buf)
        for k, v := range buf {
                if k == v {
                        continue
index e75183188905adf1dc3144bebd6b82524e481594..eb42acacdcf8c6329adfbff0636d085f1c5d616a 100644 (file)
@@ -86,9 +86,9 @@ func Start() {
                //如果连接中断,则等待
                F.KeepConnect()
                //获取cookie
-               F.Get(&c.C).Get(`Cookie`)
+               F.Get(c.C).Get(`Cookie`)
                //获取LIVE_BUVID
-               F.Get(&c.C).Get(`LIVE_BUVID`)
+               F.Get(c.C).Get(`LIVE_BUVID`)
 
                // 房间初始化
                if c.C.Roomid == 0 {
@@ -105,7 +105,7 @@ func Start() {
                //使用带tag的消息队列在功能间传递消息
                c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{
                        `flash_room`: func(_ any) bool { //房间重进
-                               F.Get(&c.C).Get(`WSURL`)
+                               F.Get(c.C).Get(`WSURL`)
                                select {
                                case flash_room_chan <- struct{}{}:
                                default:
@@ -144,7 +144,9 @@ func Start() {
                        },
                        `pm`: func(data any) bool { //私信
                                if tmp, ok := data.(send.Pm_item); ok {
-                                       send.Send_pm(tmp.Uid, tmp.Msg)
+                                       if e := send.Send_pm(tmp.Uid, tmp.Msg); e != nil {
+                                               danmulog.Base_add(`私信`).L(`E: `, e)
+                                       }
                                }
                                return false
                        },
@@ -155,9 +157,9 @@ func Start() {
                //捕获ctrl+c退出
                signal.Notify(interrupt, os.Interrupt)
                //获取uid
-               F.Get(&c.C).Get(`Uid`)
+               F.Get(c.C).Get(`Uid`)
                //兑换硬币
-               F.Get(&c.C).Get(`Silver_2_coin`)
+               F.Get(c.C).Get(`Silver_2_coin`)
                //每日签到
                F.Dosign()
                // //客户版本 不再需要
@@ -175,7 +177,7 @@ func Start() {
                        //如果连接中断,则等待
                        F.KeepConnect()
                        //获取热门榜
-                       F.Get(&c.C).Get(`Note`)
+                       F.Get(c.C).Get(`Note`)
 
                        danmulog.L(`I: `, "连接到房间", c.C.Roomid)
 
@@ -185,9 +187,9 @@ func Start() {
                                return true
                        })
 
-                       F.Get(&c.C).Get(`Liveing`)
+                       F.Get(c.C).Get(`Liveing`)
                        //检查与切换粉丝牌,只在cookie存在时启用
-                       F.Get(&c.C).Get(`CheckSwitch_FansMedal`)
+                       F.Get(c.C).Get(`CheckSwitch_FansMedal`)
 
                        //直播状态
                        if c.C.Liveing {
@@ -197,7 +199,7 @@ func Start() {
                        }
 
                        //对每个弹幕服务器尝试
-                       F.Get(&c.C).Get(`WSURL`)
+                       F.Get(c.C).Get(`WSURL`)
                        for i := 0; i < len(c.C.WSURL); i += 1 {
                                v := c.C.WSURL[i]
                                //ws启动
@@ -248,16 +250,16 @@ func Start() {
                                                }()
 
                                                //订阅消息,以便刷新舰长数
-                                               F.Get(&c.C).Get(`GuardNum`)
+                                               F.Get(c.C).Get(`GuardNum`)
                                                // 在线人数
-                                               F.Get(&c.C).Get(`getOnlineGoldRank`)
+                                               F.Get(c.C).Get(`getOnlineGoldRank`)
                                                //当前ws的消息队列
                                                c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{
                                                        `exit_cu_room`: func(_ any) bool { //退出
                                                                return true
                                                        },
                                                        `guard_update`: func(_ any) bool { //舰长更新
-                                                               go F.Get(&c.C).Get(`GuardNum`)
+                                                               go F.Get(c.C).Get(`GuardNum`)
                                                                return false
                                                        },
                                                        `flash_room`: func(_ any) bool { //重进房时退出当前房间
@@ -271,7 +273,7 @@ func Start() {
                                                                        return false
                                                                }
                                                                // 在线人数
-                                                               F.Get(&c.C).Get(`getOnlineGoldRank`)
+                                                               F.Get(c.C).Get(`getOnlineGoldRank`)
                                                                return false
                                                        },
                                                        `new day`: func(_ any) bool { //日期更换
@@ -280,7 +282,7 @@ func Start() {
                                                                // //获取用户版本  不再需要
                                                                // go F.Get(`VERSION`)
                                                                //每日兑换硬币
-                                                               go F.Get(&c.C).Silver_2_coin()
+                                                               go F.Get(c.C).Silver_2_coin()
                                                                //附加功能 每日发送弹幕
                                                                go reply.Entry_danmu()
                                                                //附加功能 保持牌子点亮
@@ -330,7 +332,7 @@ func Start() {
                                                ws_c.Close()
                                                danmulog.L(`I: `, "停止,等待服务器断开连接")
                                                //刷新WSURL
-                                               F.Get(&c.C).Get(`WSURL`)
+                                               F.Get(c.C).Get(`WSURL`)
                                                i = 0
                                        case <-change_room_chan:
                                                ws_c.Close()
index cdae15c154b235363ac6dc24ac6f74078f1920b1..cd393b85d2f4c68f0c7d23ce85c0b3f61960c1dc 100644 (file)
@@ -133,7 +133,7 @@ func Cmd() {
                        //登陆
                        if strings.Contains(inputs, ` login`) {
                                //获取cookie
-                               F.Get(&c.C).Get(`Cookie`)
+                               F.Get(c.C).Get(`Cookie`)
                                continue
                        }
                        //搜索主播
@@ -192,8 +192,8 @@ func Cmd() {
                                fmt.Println(`Web服务地址:`, c.C.Stream_url.String())
                                var array = reply.StreamOCommon(-1)
                                fmt.Println(`正在录制的房间:`)
-                               for _, v := range array {
-                                       fmt.Println("\t" + v.Uname + "(" + strconv.Itoa(v.Roomid) + ") " + v.Title)
+                               for i := 0; i < len(array); i++ {
+                                       fmt.Println("\t" + array[i].Uname + "(" + strconv.Itoa(array[i].Roomid) + ") " + array[i].Title)
                                }
                                fmt.Print("输入` rec` 来启停当前房间录制")