}
type LiveQn struct {
- Url string
- ReUpTime time.Time
- Expires int //流到期时间
+ Url string
+ ReUpTime time.Time
+ disableCount int
+ Expires int //流到期时间
}
func (t *LiveQn) Host() string {
return time.Now().After(t.ReUpTime)
}
+// 自动停用机制
+func (t *LiveQn) DisableAuto() {
+ if time.Now().After(t.ReUpTime.Add(time.Minute).Add(time.Second * time.Duration(10*t.disableCount))) {
+ t.disableCount = 0
+ }
+ t.disableCount += 1
+ t.ReUpTime = time.Now().Add(time.Minute).Add(time.Second * time.Duration(10*t.disableCount))
+}
+
func (t *LiveQn) Disable(reUpTime time.Time) {
t.ReUpTime = reUpTime
}
+// 自动停用机制
+func (t *Common) DisableLiveAuto(host string) {
+ for i := 0; i < len(t.Live); i++ {
+ if liveUrl, e := url.Parse(t.Live[i].Url); e == nil {
+ if host == liveUrl.Host {
+ t.Live[i].DisableAuto()
+ break
+ }
+ }
+ }
+}
+
func (t *Common) DisableLive(host string, reUpTime time.Time) {
for i := 0; i < len(t.Live); i++ {
if liveUrl, e := url.Parse(t.Live[i].Url); e == nil {
if err := r.Reqf(rval); err != nil {
// 1min后重新启用
- t.common.Live[k].Disable(time.Now().Add(time.Minute))
+ t.common.Live[k].DisableAuto()
t.log.L("W: ", fmt.Sprintf("服务器 %s 发生故障 %s", m3u8_url.Host, err.Error()))
if t.common.ValidLive() == nil {
e = errors.New("全部流服务器发生故障")
noe, _ := t.last_m4s.getNo()
if timed > 5 && nos-noe == 0 {
// 1min后重新启用
- t.common.Live[k].Disable(time.Now().Add(time.Minute))
+ t.common.Live[k].DisableAuto()
t.log.L("W: ", fmt.Sprintf("服务器 %s 发生故障 %d 秒产出了 %d 切片", m3u8_url.Host, int(timed), nos-noe))
if t.common.ValidLive() == nil {
e = errors.New("全部切片服务器发生故障")
if v.status == 3 {
if linkUrl, e := url.Parse(v.Url); e == nil {
oldHost := linkUrl.Host
- // 将此切片服务器设置1min停用
- t.common.DisableLive(oldHost, time.Now().Add(time.Minute))
+ // 将此切片服务器设置停用
+ t.common.DisableLiveAuto(oldHost)
// 从其他服务器获取此切片
if vl := t.common.ValidLive(); vl == nil {
return errors.New(`全部流服务器故障`)
if e := r.Reqf(reqConfig); e != nil && !errors.Is(e, io.EOF) {
// t.log.L(`T: `, `下载错误`, link.Base, e)
- if !reqf.IsTimeout(e) {
- // 发生非超时错误
- link.err = e
- link.tryDownCount = 3 // 设置切片状态为下载失败
- }
+ // if !reqf.IsTimeout(e) {
+ // // 发生非超时错误
+ // link.err = e
+ // link.tryDownCount = 3 // 设置切片状态为下载失败
+ // }
link.status = 3 // 设置切片状态为下载失败
} else {
// if usedt := r.UsedTime.Seconds(); usedt > 700 {