From cd0121b79aa77fe027e2a1e8a86aaa218697958d Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 10 May 2022 21:03:25 +0800 Subject: [PATCH] =?utf8?q?=E4=BB=85=E4=BF=9D=E5=AD=98=E5=BD=93=E5=89=8D?= =?utf8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E6=B5=81=20=E5=A4=9A=E7=9B=B4?= =?utf8?q?=E6=92=AD=E6=B5=81=E4=BF=9D=E5=AD=98=E4=B8=8Eass=E7=9A=84?= =?utf8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 28 +++++++++++++++++----------- Reply/Reply.go | 8 ++++++-- Reply/stream.go | 4 ++++ bili_danmu.go | 14 +++++++++++--- cmd/cmd.go | 34 ++++++++++++++++++++-------------- demo/config/config_K_v.json | 3 ++- 6 files changed, 60 insertions(+), 31 deletions(-) diff --git a/Reply/F.go b/Reply/F.go index 22dc10b..828046b 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -187,6 +187,9 @@ func init() { //设定字幕文件名,为""时停止输出 func Ass_f(save_path string, file string, st time.Time) { + if !IsOn(`仅保存当前直播间流`) { + return + } ass.file = file if file == "" { return @@ -264,23 +267,23 @@ func StreamOCommon(roomid int) (array []c.Common) { return } +type SavestreamO struct { + Roomid int + IsRec bool +} + // 实例操作 func init() { //使用带tag的消息队列在功能间传递消息 c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{ `savestream`: func(data interface{}) bool { - if roomid, ok := data.(int); ok { - if v, ok := streamO.Load(roomid); ok { - if v.(*M4SStream).Status.Islive() { - v.(*M4SStream).Stop() - streamO.Delete(roomid) - } - } else { + if item, ok := data.(SavestreamO); ok { + if v, ok := streamO.Load(item.Roomid); item.IsRec && !ok { var ( tmp = new(M4SStream) common = c.C ) - common.Roomid = roomid + common.Roomid = item.Roomid tmp.LoadConfig(common, c.C.Log) //关于ass的回调 tmp.Callback_start = func(ms *M4SStream) { @@ -289,11 +292,14 @@ func init() { tmp.Callback_stop = func(ms *M4SStream) { Ass_f("", "", time.Now()) //停止ass } - streamO.Store(roomid, tmp) + streamO.Store(item.Roomid, tmp) go tmp.Start() + } else if !item.IsRec && ok { + if v.(*M4SStream).Status.Islive() { + v.(*M4SStream).Stop() + streamO.Delete(item.Roomid) + } } - } else { - flog.L(`E: `, `savestream必须为数字房间号`) } return false }, diff --git a/Reply/Reply.go b/Reply/Reply.go index 891316e..61c8a60 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -717,12 +717,16 @@ func (replyF) live(s string) { if p.Sys().Type(roomid) == "float64" { //开始录制 go func() { - if v, ok := c.C.K_v.LoadV(`直播流当前房间开播时停止其他流`).(bool); ok && v { + if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v { StreamOStop(-1) //停止其他房间录制 } - c.C.Danmu_Main_mq.Push_tag(`savestream`, int(roomid.(float64))) }() + c.C.Danmu_Main_mq.Push_tag(`savestream`, SavestreamO{ + Roomid: int(roomid.(float64)), + IsRec: true, + }) + Gui_show(Itos([]interface{}{"房间", roomid, "开播了"}), "0room") msglog.L(`I: `, "房间", int(roomid.(float64)), "开播了") return diff --git a/Reply/stream.go b/Reply/stream.go index 348336c..7a30e7a 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -334,6 +334,10 @@ func (t *M4SStream) fetchParseM3U8() (m4s_links []*m4s_link_item, m3u8_addon []b } current_no, _ = t.last_m4s.getNo() + if guess_end_no < current_no { + return + } + t.log.L(`I: `, `发现`, guess_end_no-current_no-1, `个切片遗漏,重新下载`) for guess_no := guess_end_no - 1; guess_no > current_no; guess_no -= 1 { // 补充m3u8 diff --git a/bili_danmu.go b/bili_danmu.go index b2762db..9d3e610 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -275,7 +275,10 @@ func Demo(roomid ...int) { { //附加功能 进房间发送弹幕 直播流保存 营收 go reply.Entry_danmu() - c.C.Danmu_Main_mq.Push_tag(`savestream`, c.C.Roomid) + c.C.Danmu_Main_mq.Push_tag(`savestream`, reply.SavestreamO{ + Roomid: c.C.Roomid, + IsRec: true, + }) go reply.ShowRevf() //小心心 go F.F_x25Kn() @@ -314,13 +317,18 @@ func Demo(roomid ...int) { break } } - { //附加功能 直播流停止 - reply.StreamOStop(-1) + { //附加功能 ws信息保存 reply.Save_to_json(-1, []interface{}{`{}]`}) + if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v { + reply.StreamOStop(-1) //停止其他房间录制 + } } p.Sys().Timeoutf(1) } + { //附加功能 直播流停止 + reply.StreamOStop(-1) + } close(interrupt) danmulog.L(`I: `, "结束退出") } diff --git a/cmd/cmd.go b/cmd/cmd.go index 3016bde..ce3fa38 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -56,13 +56,23 @@ func Cmd() { //录制切换 if strings.Contains(inputs, ` rec`) { if len(inputs) > 4 { + if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v { + cmdlog.L(`W: `, "输入错误", inputs) + continue + } if room, err := strconv.Atoi(inputs[4:]); err == nil { - c.C.Danmu_Main_mq.Push_tag(`savestream`, room) + c.C.Danmu_Main_mq.Push_tag(`savestream`, reply.SavestreamO{ + Roomid: room, + IsRec: !reply.StreamOStatus(room), + }) continue } cmdlog.L(`W: `, "输入错误", inputs) } else { - c.C.Danmu_Main_mq.Push_tag(`savestream`, c.C.Roomid) + c.C.Danmu_Main_mq.Push_tag(`savestream`, reply.SavestreamO{ + Roomid: c.C.Roomid, + IsRec: !reply.StreamOStatus(c.C.Roomid), + }) } continue } @@ -168,22 +178,18 @@ func Cmd() { if c.C.Stream_url != "" { fmt.Println(`直播Web服务:`, c.C.Stream_url) } - if reply.StreamOStatus(c.C.Roomid) { - fmt.Println(`正在录制当前房间`) - } else { - fmt.Println(`未在录制当前房间`) + var array = reply.StreamOCommon(-1) + fmt.Println(`正在录制的房间:`) + for _, v := range array { + fmt.Println("\t" + v.Uname + "(" + strconv.Itoa(v.Roomid) + ") " + v.Title) } + fmt.Print("输入` rec` 来启停当前房间录制") - var array = reply.StreamOCommon(-1) - if len(array) > 1 { - fmt.Println(`正在录制的其他房间:`) - for _, v := range array { - fmt.Println("\t" + v.Uname + "(" + strconv.Itoa(v.Roomid) + ") " + v.Title) - } + if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); !ok || !v { + fmt.Print(" 输入` rec房间号` 来启停其他录制") } - fmt.Println("输入` rec` 来启停当前房间录制, 输入` rec房间号` 来启停其他录制") - fmt.Print("\n") + fmt.Print("\n\n") continue } diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index c2bcbb3..9106365 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -61,7 +61,8 @@ "直播hls流缓冲": 20, "直播hls流均衡-help":"true:使用所有hls服务器", "直播hls流均衡": true, - "直播流当前房间开播时停止其他流": true, + "仅保存当前直播间流-help": "启用此项,才会保存Ass", + "仅保存当前直播间流": true, "直播Web服务口":0, "ass-help": "只有保存直播流时才考虑生成ass,ass编码默认GB18030(可选utf-8)", "生成Ass弹幕": true, -- 2.39.2