From: qydysky Date: Mon, 17 Jun 2024 12:55:43 +0000 (+0000) Subject: Improve 及时移除失效流 X-Git-Tag: v0.14.6~7 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=c7971286e39b9889a9f522b78299682d51b4267b;p=bili_danmu%2F.git Improve 及时移除失效流 --- diff --git a/CV/Var.go b/CV/Var.go index b876174..008bd37 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -46,7 +46,7 @@ type Common struct { PID int `json:"pid"` //进程id Version string `json:"version"` //版本 Uid int `json:"-"` //client uid - Live []*LiveQn `json:"-"` //直播流链接 + Live []*LiveQn `json:"live"` //直播流链接 Live_qn int `json:"liveQn"` //当前直播流质量 Live_want_qn int `json:"-"` //期望直播流质量 Roomid int `json:"roomid"` //房间ID @@ -86,13 +86,31 @@ type Common struct { } type LiveQn struct { - Url string + Url string `json:"-"` Codec string ReUpTime time.Time - disableCount int + DisableCount int Expires time.Time //流到期时间 } +func (t LiveQn) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Host string + Up bool + Codec string + ReUpTime string + Expires string + DisableCount int + }{ + Host: t.Host(), + Up: time.Now().After(t.ReUpTime), + Codec: t.Codec, + ReUpTime: t.ReUpTime.Format(time.DateTime), + Expires: t.Expires.Format(time.DateTime), + DisableCount: t.DisableCount, + }) +} + func (t *LiveQn) SetUrl(url string) { t.Url = url } @@ -114,11 +132,11 @@ func (t *LiveQn) DisableAuto() (hadDisable bool) { if !t.Valid() { return true } - if time.Now().After(t.ReUpTime.Add(time.Minute).Add(time.Second * time.Duration(10*t.disableCount))) { - t.disableCount = 0 + if time.Now().After(t.ReUpTime.Add(time.Minute).Add(time.Second * time.Duration(20*t.DisableCount))) { + t.DisableCount = 0 } - t.disableCount += 1 - t.ReUpTime = time.Now().Add(time.Minute).Add(time.Second * time.Duration(10*t.disableCount)) + t.DisableCount += 1 + t.ReUpTime = time.Now().Add(time.Minute).Add(time.Second * time.Duration(20*t.DisableCount)) return } diff --git a/F/api.go b/F/api.go index a3694de..07b6cae 100644 --- a/F/api.go +++ b/F/api.go @@ -421,11 +421,11 @@ func (t *GetFunc) configStreamType(sts []struct { wantTypes = append(wantTypes, t.AllStreamType[`fmp4`], t.AllStreamType[`flv`]) // t.Live = t.Live[:0] - for i := 0; i < len(t.Live); i++ { - if time.Now().Add(time.Minute).Before(t.Live[i].ReUpTime) { - t.Live = append(t.Live[:i], t.Live[i+1:]...) - } - } + // for i := 0; i < len(t.Live); i++ { + // if time.Now().Add(time.Minute).Before(t.Live[i].ReUpTime) { + // t.Live = append(t.Live[:i], t.Live[i+1:]...) + // } + // } for k, streamType := range wantTypes { for _, v := range sts { diff --git a/Reply/stream.go b/Reply/stream.go index ab48eb2..d64c12a 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -676,6 +676,9 @@ func (t *M4SStream) saveStreamFlv() (e error) { // 找到可用流服务器 for { + // 移除失效源 + t.removeSer() + v := t.common.ValidLive() if v == nil { return errors.New("未能找到可用流服务器") @@ -911,6 +914,17 @@ func (t *M4SStream) saveStreamFlv() (e error) { return } +// 移除失效源 +func (t *M4SStream) removeSer() { + slice.Del(&t.common.Live, func(v **c.LiveQn) (del bool) { + isDel := time.Now().Add(time.Minute).Before((*v).ReUpTime) + if isDel { + t.log.L(`I: `, `移除流服务器`, (*v).Host()) + } + return isDel + }) +} + func (t *M4SStream) saveStreamM4s() (e error) { if v, ok := t.common.K_v.LoadV(`debug模式`).(bool); ok && v { @@ -959,6 +973,9 @@ func (t *M4SStream) saveStreamM4s() (e error) { // 下载循环 for download_seq := []*m4s_link_item{}; ; { + // 移除失效源 + t.removeSer() + // 获取解析m3u8 { // 防止过快的下载 diff --git a/go.mod b/go.mod index 83af5ff..dfb4905 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.2 require ( github.com/gotk3/gotk3 v0.6.3 github.com/mdp/qrterminal/v3 v3.2.0 - github.com/qydysky/part v0.28.20240616030921 + github.com/qydysky/part v0.28.20240617114802 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.16.0 diff --git a/go.sum b/go.sum index b9eb8a4..60b0dbb 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/qydysky/biliApi v0.0.0-20240606223920-b89663690249 h1:23brRdaCzZbh4aH3TWevi/B3MVWbQY3qKcqjEiSmRiA= github.com/qydysky/biliApi v0.0.0-20240606223920-b89663690249/go.mod h1:om024vfxALQ5vxsbaGoMm8IS0esLYBnEOpJI8FsGoDg= -github.com/qydysky/part v0.28.20240616030921 h1:bXOV3i+nYpXF66D6GvsqPImEl4WdyevZq2+ptQwL72A= -github.com/qydysky/part v0.28.20240616030921/go.mod h1:dgagZnPYRFZDbt7XJf7nADOJLoYwlebD9B8Z8g5aHhI= +github.com/qydysky/part v0.28.20240617114802 h1:cmDWin7303nKFQ7HAL2+Ur87vkh8d67xVqudvpXp96E= +github.com/qydysky/part v0.28.20240617114802/go.mod h1:dgagZnPYRFZDbt7XJf7nADOJLoYwlebD9B8Z8g5aHhI= 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=