]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Add 配置 直播流停用服务器
authorqydysky <qydysky@foxmail.com>
Sat, 15 Jun 2024 17:10:16 +0000 (17:10 +0000)
committerqydysky <qydysky@foxmail.com>
Sat, 15 Jun 2024 17:10:16 +0000 (17:10 +0000)
README.md
Reply/stream.go
demo/config/config_K_v.json

index f12118a0f263f687716d917061196acac9690eaa..4a3dfd60abf48ea9cb9bf04aea275ee924302708 100644 (file)
--- a/README.md
+++ b/README.md
 ### 说明
 本项目使用github action自动构建,构建过程详见[yml](https://github.com/qydysky/bili_danmu/blob/master/.github/workflows/go.yml)
 
+#### 直播流停用服务器
+配置文件中添加配置项`直播流停用服务器`(>v0.14.3)。默认为空,编写正则字符串,当获取到的服务器链接与字符串匹配时,将会停用。
+
+```json
+{
+  "直播流不使用mcdn": false,
+  "直播流停用服务器": [
+      "\\.mcdn\\."
+  ],
+}
+```
+
 #### fmp4相关优化
 配置文件中添加配置项`fmp4获取更多服务器`(>v0.14.2)。当直播流类型为fmp4,为`true`时,会在可用切片服务器仅剩1个时,获取更多服务器,但总数超过5个后,将不会再获取。默认为`true`。
 
index cb3cca94f0d5643badfc9aa2768e1f971c40bfda..faa10b3c5c6988eee49971252c2d63eb709dec18 100644 (file)
@@ -17,6 +17,7 @@ import (
        "os"
        "os/exec"
        "path/filepath"
+       "regexp"
        "strconv"
        "strings"
        "sync"
@@ -247,16 +248,39 @@ func (t *M4SStream) fetchCheckStream() bool {
                return true
        })
 
-       var nomcdn bool
+       var (
+               noSer  []*regexp.Regexp
+               noSerF = func(url string) (ban bool) {
+                       for i := 0; i < len(noSer) && !ban; i++ {
+                               ban = noSer[i].MatchString(url)
+                       }
+                       return
+               }
+       )
        if v, ok := t.common.K_v.LoadV("直播流不使用mcdn").(bool); ok && v {
-               nomcdn = true
+               if reg, err := regexp.Compile(`\.mcdn\.`); err != nil {
+                       t.log.L(`W: `, `停用流服务器`, `正则错误`, err)
+               } else {
+                       noSer = append(noSer, reg)
+               }
+       }
+       if v, ok := t.common.K_v.LoadV("直播流停用服务器").([]any); ok {
+               for i := 0; i < len(v); i++ {
+                       if s, ok := v[i].(string); ok {
+                               if reg, err := regexp.Compile(s); err != nil {
+                                       t.log.L(`W: `, `停用流服务器`, `正则错误`, err)
+                               } else {
+                                       noSer = append(noSer, reg)
+                               }
+                       }
+               }
        }
 
        r := t.reqPool.Get()
        defer t.reqPool.Put(r)
 
        for _, v := range t.common.Live {
-               if nomcdn && strings.Contains(v.Url, ".mcdn.") {
+               if noSerF(v.Url) {
                        v.Disable(time.Now().Add(time.Hour * 100))
                        t.log.L(`I: `, `停用流服务器`, F.ParseHost(v.Url))
                        continue
@@ -788,8 +812,8 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                                        leastReadUnix.Store(time.Now().Unix())
                                                }
                                                if len(front_buf) != 0 && len(t.first_buf) == 0 {
-                                                       t.first_buf = make([]byte, len(front_buf))
-                                                       copy(t.first_buf, front_buf)
+                                                       t.first_buf = t.first_buf[:0]
+                                                       t.first_buf = append(t.first_buf, front_buf...)
                                                        // fmt.Println("write front_buf")
                                                        // t.Stream_msg.PushLock_tag(`data`, t.first_buf)
                                                        t.msg.Push_tag(`load`, t)
@@ -799,11 +823,13 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                                                switch v.Codec {
                                                                case "hevc":
                                                                        t.log.L(`W: `, `flv未接收到起始段,使用内置头`)
-                                                                       t.first_buf = flvHeaderHevc
+                                                                       t.first_buf = t.first_buf[:0]
+                                                                       t.first_buf = append(t.first_buf, flvHeaderHevc...)
                                                                        t.msg.Push_tag(`load`, t)
                                                                case "avc":
                                                                        t.log.L(`W: `, `flv未接收到起始段,使用内置头`)
-                                                                       t.first_buf = flvHeader
+                                                                       t.first_buf = t.first_buf[:0]
+                                                                       t.first_buf = append(t.first_buf, flvHeader...)
                                                                        t.msg.Push_tag(`load`, t)
                                                                default:
                                                                }
index 1f9652c329e11e37cd2597f439e004c40f57135e..4ae5106e2f8120de6afd7e84bfb73c8da5f65376 100644 (file)
@@ -70,6 +70,8 @@
     "直播流类型-help": "flv,fmp4,flvH,fmp4H,带H后缀的为Hevc格式编码",
     "直播流类型": "fmp4",
     "直播流不使用mcdn": false,
+    "直播流停用服务器-help": "正则字符串数组",
+    "直播流停用服务器": [],
     "直播流接收n帧才保存": 3,
     "flv断流超时s": 5,
     "flv断流续接": true,