]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve 及时移除失效流
authorqydysky <qydysky@foxmail.com>
Mon, 17 Jun 2024 12:55:43 +0000 (12:55 +0000)
committerqydysky <qydysky@foxmail.com>
Mon, 17 Jun 2024 12:55:43 +0000 (12:55 +0000)
CV/Var.go
F/api.go
Reply/stream.go
go.mod
go.sum

index b87617495da71406f6cbfce883c0e938e55c2f3c..008bd37e58209a9a6f9fda454e2048befeda2b3e 100644 (file)
--- 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
 }
 
index a3694de6fadf359742ce8f42090d31282436f9c4..07b6cae4bccfc2bde1683d189b7a31bc76fb7715 100644 (file)
--- 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 {
index ab48eb210ec752486c0f5f87c1033ea40c992462..d64c12aa346781f0ae8def9feecb99520f340ee7 100644 (file)
@@ -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 83af5ffacca82a9122f5556e5839cb5d49cad638..dfb49054468daa1e3874245403a09a78fbe3e8ac 100644 (file)
--- 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 b9eb8a4679a22d1cbd5cf65881db6c1cdca139b6..60b0dbb5208ea32f10e67ebc7898c080995780fd 100644 (file)
--- 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=