From db9049db2671199a37ecbd6fa0d2aa15d7ca4156 Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Thu, 19 Jan 2023 21:59:10 +0800 Subject: [PATCH] =?utf8?q?Add=20Feature=20fmp4=E8=87=AA=E5=8A=A8=E5=88=B7?= =?utf8?q?=E6=96=B0=E6=B5=81=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CV/Var.go | 1 + F/api.go | 36 ++++++++++++++++++++++++++++++++---- Reply/stream.go | 31 +++++++++++-------------------- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/CV/Var.go b/CV/Var.go index d06fe37..0036b21 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -55,6 +55,7 @@ type Common struct { type LiveQn struct { Url string ReUpTime time.Time + Expires int //流到期时间 } func (t *Common) Init() Common { diff --git a/F/api.go b/F/api.go index f19f3bd..4815792 100644 --- a/F/api.go +++ b/F/api.go @@ -362,9 +362,17 @@ func (c *GetFunc) Html() (missKey []string) { //直播流链接 c.Live = []cv.LiveQn{} for _, v1 := range v.URLInfo { - c.Live = append(c.Live, cv.LiveQn{ + item := cv.LiveQn{ Url: v1.Host + v.BaseURL + v1.Extra, - }) + } + + if query, e := url.ParseQuery(v1.Extra); e == nil { + if expires, e := strconv.Atoi(query.Get("expires")); e == nil { + item.Expires = expires + } + } + + c.Live = append(c.Live, item) } } } @@ -631,7 +639,17 @@ func (c *GetFunc) getRoomPlayInfo() (missKey []string) { //直播流链接 c.Live = []cv.LiveQn{} for _, v1 := range v.URLInfo { - c.Live = append(c.Live, cv.LiveQn{Url: v1.Host + v.BaseURL + v1.Extra}) + item := cv.LiveQn{ + Url: v1.Host + v.BaseURL + v1.Extra, + } + + if query, e := url.ParseQuery(v1.Extra); e == nil { + if expires, e := strconv.Atoi(query.Get("expires")); e == nil { + item.Expires = expires + } + } + + c.Live = append(c.Live, item) } //找到配置格式,跳出 @@ -813,7 +831,17 @@ func (c *GetFunc) getRoomPlayInfoByQn() (missKey []string) { //直播流链接 c.Live = []cv.LiveQn{} for _, v1 := range v.URLInfo { - c.Live = append(c.Live, cv.LiveQn{Url: v1.Host + v.BaseURL + v1.Extra}) + item := cv.LiveQn{ + Url: v1.Host + v.BaseURL + v1.Extra, + } + + if query, e := url.ParseQuery(v1.Extra); e == nil { + if expires, e := strconv.Atoi(query.Get("expires")); e == nil { + item.Expires = expires + } + } + + c.Live = append(c.Live, item) } } } diff --git a/Reply/stream.go b/Reply/stream.go index 6d79d28..51b3f75 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -201,15 +201,6 @@ func (t *M4SStream) fetchCheckStream() bool { t.stream_type = "flv" } - // // 保存流地址过期时间 - // if m3u8_url, err := url.Parse(t.common.Live[0]); err != nil { - // t.log.L(`E: `, err.Error()) - // return false - // } else { - // expires, _ := strconv.Atoi(m3u8_url.Query().Get("expires")) - // t.stream_expires = int64(expires) - // } - // 检查是否可以获取 CookieM := make(map[string]string) t.common.Cookie.Range(func(k, v interface{}) bool { @@ -746,11 +737,22 @@ func (t *M4SStream) saveStreamM4s() (e error) { fmp4KeyFrames = slice.New[byte]() fmp4KeyFramesBuf []byte fmp4Decoder = &Fmp4Decoder{} + flashingSer bool ) // 下载循环 for download_seq := []*m4s_link_item{}; ; { + // 刷新流地址 + if !flashingSer && int64(t.common.Live[0].Expires)-time.Now().Unix() < 60 { + flashingSer = true + t.log.L(`T: `, `刷新流地址...`) + go func() { + t.fetchCheckStream() + flashingSer = false + }() + } + // 存在待下载切片 if len(download_seq) != 0 { @@ -955,17 +957,6 @@ func (t *M4SStream) saveStreamM4s() (e error) { } } - // 刷新流地址 - // 偶尔刷新后的切片编号与原来不连续,故不再提前检查,直到流获取失败再刷新 - // if time.Now().Unix()+60 > t.stream_expires { - // t.stream_expires = time.Now().Add(time.Minute * 2).Unix() // 临时的流链接过期时间 - // go func() { - // if t.fetchCheckStream() { - // t.last_m4s = nil - // } - // }() - // } - // 获取解析m3u8 var m4s_links, m3u8_addon, err = t.fetchParseM3U8() if err != nil { -- 2.39.2