From 8a08017dd08eb8453cff93245f514687c1b9cb72 Mon Sep 17 00:00:00 2001 From: qydysky Date: Mon, 31 May 2021 23:03:29 +0800 Subject: [PATCH] =?utf8?q?hls=E4=B8=8B=E8=BD=BD=E6=97=B6=E7=BC=93=E5=AD=98?= =?utf8?q?=E5=88=B0=E5=86=85=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 67 +++++++++++++++++++++++++++++------------------------ demo/go.mod | 4 ++-- demo/go.sum | 4 ++++ go.mod | 4 ++-- go.sum | 4 ++++ 5 files changed, 49 insertions(+), 34 deletions(-) diff --git a/Reply/F.go b/Reply/F.go index 1a20663..d6c301b 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -862,8 +862,6 @@ func Savestreamf(){ // } var res []byte - //add header - res = hls_gen.hls_file_header //add m4s block { @@ -883,9 +881,14 @@ func Savestreamf(){ m4s_list_b = append(m4s_list_b, v.Base...) m4s_list_b = append(m4s_list_b, []byte("\n")...) } + //no useable m4s + if m4s == 0 {return false} + //clear if cut := m4s-savestream.m4s_hls;cut > 0 { hls_gen.m4s_list = hls_gen.m4s_list[cut:] } + //add header + res = hls_gen.hls_file_header //add #EXT-X-DISCONTINUITY res = append(res, []byte("#EXT-X-DISCONTINUITY\n")...) //add #EXT-X-MEDIA-SEQUENCE @@ -972,10 +975,11 @@ func Savestreamf(){ links,file_add,exp,e := hls_get_link(c.Live[0],last_download) if e != nil { - l.L(`W: `,e) if reqf.IsTimeout(e) || reqf.IsDnsErr(e) { + l.L(`I: `,e) continue } else { + l.L(`W: `,e) break } } @@ -1063,11 +1067,8 @@ func Savestreamf(){ } else if len(links) > 100 { l.L(`W: `,`重试,等待下载切片:`,len(links)) - F.Get(`Liveing`) - if !c.Liveing {break} - - F.Get(`Live`) - if len(c.Live)==0 {break} + if F.Get(`Liveing`);!c.Liveing {break} + if F.Get(`Live`);len(c.Live) == 0 {break} // no expect qn if c.Live_want_qn < c.Live_qn { @@ -1094,28 +1095,34 @@ func Savestreamf(){ // l.L(`T: `, `处理:`, link.Base) // } - (*link).status = s_loading + link.status = s_loading r := reqf.New() if e := r.Reqf(reqf.Rval{ - Url:(*link).Url, - Retry:0, - SaveToPath:path+(*link).Base, - ConnectTimeout:2000, - ReadTimeout:2000, - Proxy:c.Proxy, + Url: link.Url, + SaveToPath: path + link.Base, + ConnectTimeout: 2000, + ReadTimeout: 2000, + Proxy: c.Proxy, }); e != nil{ if reqf.IsTimeout(e) { - l.L(`I: `,e,`将重试!`) + l.L(`I: `, link.Base, `将重试!`) //避免影响后续猜测 - (*link).Offset_line = 0 + link.Offset_line = 0 miss_download.Lock() miss_download.List = append(miss_download.List, link) miss_download.Unlock() } else { - (*link).status = s_fail + link.status = s_fail } } else { - (*link).status = s_fin + link.status = s_fin + if _,ok := m4s_cache.Load(path + link.Base);!ok{ + m4s_cache.Store(path + link.Base, r.Respon) + go func(){//移除 + time.Sleep(time.Second*time.Duration(savestream.m4s_hls+1)) + m4s_cache.Delete(path + link.Base) + }() + } } }(links[i],savestream.path) @@ -1128,12 +1135,8 @@ func Savestreamf(){ //m3u8_url 将过期 if p.Sys().GetSTime()+60 > expires { - F.Get(`Liveing`) - if !c.Liveing {break} - - F.Get(`Live`) - if len(c.Live)==0 {break} - + if F.Get(`Liveing`);!c.Liveing {break} + if F.Get(`Live`);len(c.Live) == 0 {break} // no expect qn if c.Live_want_qn < c.Live_qn { expires = time.Now().Add(time.Minute*2).Unix() @@ -1662,6 +1665,10 @@ func init(){ Save_to_json(0, []interface{}{`[`}) return false }, + `flash_room`:func(data interface{})(bool){//房间改变 + Save_to_json(0, []interface{}{`[`}) + return false + }, }) } @@ -1783,6 +1790,8 @@ func AutoSend_silver_gift() { } } +var m4s_cache sync.Map//使用内存cache避免频繁io + //直播保存位置Web服务 func init() { flog := flog.Base_add(`直播Web服务`) @@ -1803,8 +1812,6 @@ func init() { addr += strconv.Itoa(port) } - var cache sync.Map//使用内存cache避免频繁io - s := web.New(&http.Server{ Addr: addr, }) @@ -1883,7 +1890,7 @@ func init() { var buf []byte - if b,ok := cache.Load(path);!ok{ + if b,ok := m4s_cache.Load(path);!ok{ f,err := os.OpenFile(path,os.O_RDONLY,0644) if err != nil { flog.L(`E: `,err); @@ -1902,10 +1909,10 @@ func init() { return } else { buf = b[:n] - cache.Store(path,buf) + m4s_cache.Store(path,buf) go func(){//移除 time.Sleep(time.Second*time.Duration(savestream.m4s_hls+1)) - cache.Delete(path) + m4s_cache.Delete(path) }() } } else { diff --git a/demo/go.mod b/demo/go.mod index 66a5574..424614d 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -14,13 +14,13 @@ require ( github.com/miekg/dns v1.1.42 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/qydysky/bili_danmu v0.5.9 - github.com/qydysky/part v0.5.17 // indirect + github.com/qydysky/part v0.5.18 // indirect github.com/shirou/gopsutil v3.21.4+incompatible // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect github.com/tklauser/go-sysconf v0.3.6 // indirect golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect - golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea // indirect + golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 // indirect ) replace ( diff --git a/demo/go.sum b/demo/go.sum index 582b2b8..0953b9e 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -294,6 +294,8 @@ github.com/qydysky/part v0.5.16 h1:6tdS33wS5u13qEfztzKFDrZ9dPTlhRNoJEHkSH1J+YI= github.com/qydysky/part v0.5.16/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part v0.5.17 h1:VT+oPSGViUbbPbnN7X0SfRYpZ/i0H9uS4jbiSqAaCuE= github.com/qydysky/part v0.5.17/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.5.18 h1:izaENzNTwnvhaq3Hd0WXvYsdoGoLcb7cnFLFZCQJbdo= +github.com/qydysky/part v0.5.18/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad h1:Jtzf509lQrkUMGTV0Sc6IDCAiR1VrBcHrIban7hpye4= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8= @@ -467,6 +469,8 @@ golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mU golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea h1:+WiDlPBBaO+h9vPNZi8uJ3k4BkKQB7Iow3aqwHVA5hI= golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 h1:OL5GcZ2XPkte3dpfuFQ9o884vrE3BZQhajdntNMruv4= +golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/go.mod b/go.mod index 1081716..9f6fa1a 100644 --- a/go.mod +++ b/go.mod @@ -12,12 +12,12 @@ require ( github.com/mdp/qrterminal/v3 v3.0.0 github.com/miekg/dns v1.1.42 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect - github.com/qydysky/part v0.5.17 + github.com/qydysky/part v0.5.18 github.com/shirou/gopsutil v3.21.4+incompatible // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/tklauser/go-sysconf v0.3.6 // indirect golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect - golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea // indirect + golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 // indirect ) diff --git a/go.sum b/go.sum index 98e4c1e..ce65227 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/qydysky/part v0.5.16 h1:6tdS33wS5u13qEfztzKFDrZ9dPTlhRNoJEHkSH1J+YI= github.com/qydysky/part v0.5.16/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part v0.5.17 h1:VT+oPSGViUbbPbnN7X0SfRYpZ/i0H9uS4jbiSqAaCuE= github.com/qydysky/part v0.5.17/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.5.18 h1:izaENzNTwnvhaq3Hd0WXvYsdoGoLcb7cnFLFZCQJbdo= +github.com/qydysky/part v0.5.18/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg= github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= @@ -143,6 +145,8 @@ golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mU golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea h1:+WiDlPBBaO+h9vPNZi8uJ3k4BkKQB7Iow3aqwHVA5hI= golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 h1:OL5GcZ2XPkte3dpfuFQ9o884vrE3BZQhajdntNMruv4= +golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -- 2.39.2