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
}
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
}
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
}
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 {
// 找到可用流服务器
for {
+ // 移除失效源
+ t.removeSer()
+
v := t.common.ValidLive()
if v == nil {
return errors.New("未能找到可用流服务器")
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 {
// 下载循环
for download_seq := []*m4s_link_item{}; ; {
+ // 移除失效源
+ t.removeSer()
+
// 获取解析m3u8
{
// 防止过快的下载
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
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=