From: qydysky Date: Sat, 15 Jun 2024 17:10:16 +0000 (+0000) Subject: Add 配置 直播流停用服务器 X-Git-Tag: v0.14.5~5 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=8b2e35468b5b6b3d5e7b041099d1ef0a0bdf0b97;p=bili_danmu%2F.git Add 配置 直播流停用服务器 --- diff --git a/README.md b/README.md index f12118a..4a3dfd6 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,18 @@ ### 说明 本项目使用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`。 diff --git a/Reply/stream.go b/Reply/stream.go index cb3cca9..faa10b3 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -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: } diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index 1f9652c..4ae5106 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -70,6 +70,8 @@ "直播流类型-help": "flv,fmp4,flvH,fmp4H,带H后缀的为Hevc格式编码", "直播流类型": "fmp4", "直播流不使用mcdn": false, + "直播流停用服务器-help": "正则字符串数组", + "直播流停用服务器": [], "直播流接收n帧才保存": 3, "flv断流超时s": 5, "flv断流续接": true,