From: qydysky Date: Fri, 25 Sep 2020 09:15:17 +0000 (+0800) Subject: 23 X-Git-Tag: v0.0.0~15 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=dfb47417ba7296c2898b98b0829d1e06ab431625;p=bili_danmu%2F.git 23 --- diff --git a/Const/Const.go b/CV/Const.go similarity index 95% rename from Const/Const.go rename to CV/Const.go index 8d7bbce..e9e6b5f 100644 --- a/Const/Const.go +++ b/CV/Const.go @@ -1,5 +1,9 @@ package constf +const ( + LogLevel = 1 +) + //from source/player-loader-2.0.7.min.js L2885 const ( WS_OP_HEARTBEAT = 2 diff --git a/Const/Var.go b/CV/Var.go similarity index 100% rename from Const/Var.go rename to CV/Var.go diff --git a/F/F.go b/F/F.go index 937552b..33d8e11 100644 --- a/F/F.go +++ b/F/F.go @@ -5,7 +5,7 @@ import ( "strconv" p "github.com/qydysky/part" - . "github.com/qydysky/bili_danmu/Const" + . "github.com/qydysky/bili_danmu/CV" ) var flog = p.Logf().New().Open("danmu.log").Base(-1, "F.go") diff --git a/api.go b/F/api.go similarity index 97% rename from api.go rename to F/api.go index 7575612..07fb5a1 100644 --- a/api.go +++ b/F/api.go @@ -1,8 +1,9 @@ -package bili_danmu +package F import ( "strconv" + c "github.com/qydysky/bili_danmu/CV" p "github.com/qydysky/part" ) @@ -14,7 +15,7 @@ type api struct { Token string } -var apilog = p.Logf().New().Base(-1, "api.go").Level(LogLevel) +var apilog = p.Logf().New().Base(-1, "api.go").Level(c.LogLevel) func New_api(Roomid int) (o *api) { apilog.Base(-1, "新建") defer apilog.Base(0) diff --git a/Reply/F.go b/Reply/F.go index 45ac545..8efacd3 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -9,7 +9,8 @@ import ( "time" "os/exec" - c "github.com/qydysky/bili_danmu/Const" + c "github.com/qydysky/bili_danmu/CV" + F "github.com/qydysky/bili_danmu/F" "github.com/christopher-dG/go-obs-websocket" p "github.com/qydysky/part" ) @@ -106,7 +107,7 @@ var ( Ass_width = 1280 Ass_font = 50 Ass_T = 7 - Ass_loc = 1//小键盘对应的位置 + Ass_loc = 7//小键盘对应的位置 ) var ass = Ass { @@ -121,21 +122,23 @@ PlayResY: `+strconv.Itoa(Ass_width)+` [V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding -Style: Default,,`+strconv.Itoa(Ass_font)+`,&H60FFFFFF,&H000017FF,&H80000000,&H79000000,0,0,0,0,100,100,0,0,1,1,1,`+strconv.Itoa(Ass_loc)+`,15,15,15,1 +Style: Default,,`+strconv.Itoa(Ass_font)+`,&H40FFFFFF,&H000017FF,&H80000000,&H70000000,0,0,0,0,100,100,0,0,1,4,4,`+strconv.Itoa(Ass_loc)+`,20,20,50,1 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text `, } +func Ass_f(file string){ + ass.file = file +} -func Assf(s,file string){ +func Assf(s string){ if !ass.Inuse {return} - if file == "" && ass.file == "" {return} + if ass.file == "" {return} if ass.startT.Equal(time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)) { - p.Logf().New().Open("danmu.log").Base(1, "Ass").I("弹幕转Ass保存至", file + ".ass") + p.Logf().New().Open("danmu.log").Base(1, "Ass").I("弹幕转Ass保存至", ass.file + ".ass") - ass.file = file p.File().FileWR(p.Filel{ File:ass.file + ".ass", Write:true, @@ -154,7 +157,7 @@ func Assf(s,file string){ // b += "Comment: " + strconv.Itoa(loc) + " "+ Dtos(showedt) + "\n" b += `Dialogue: 0,` b += Dtos(st) + `,` + Dtos(et) - b += `,Default,,0,0,0,,{\fad(500,500)\blur3}` + s + "\n" + b += `,Default,,0,0,0,,{\fad(200,500)\blur3}` + s + "\n" p.File().FileWR(p.Filel{ File:ass.file + ".ass", @@ -175,8 +178,8 @@ func Dtos(t time.Duration) string { type Saveflv struct { Inuse bool path string - wait chan bool - cancel chan interface{} + wait chan struct{} + cancel chan struct{} } var saveflv = Saveflv { @@ -185,17 +188,21 @@ var saveflv = Saveflv { func Saveflvf(){ if !saveflv.Inuse || saveflv.path != "" {return} - l := p.Logf().New().Open("danmu.log").Base(1, "saveflv") - defer l.BC() + l := p.Logf().New().Open("danmu.log").Base(-1, "saveflv") + defer l.Base(0).BC() if saveflv.path != "" || c.Live == "" {return} + + api := F.New_api(c.Roomid).Get_host_Token().Get_live() + c.Live = api.Live + saveflv.path = strconv.Itoa(c.Roomid) + "_" + time.Now().Format(time.RFC3339) l.I("直播流保存到", saveflv.path) - saveflv.wait = make(chan bool,1) - saveflv.cancel = make(chan interface{},1) + saveflv.wait = make(chan struct{}) + saveflv.cancel = make(chan struct{}) - Assf("",saveflv.path)//ass + Ass_f(saveflv.path)//ass rr := p.Req() go func(){ @@ -209,8 +216,10 @@ func Saveflvf(){ SaveToPath:saveflv.path + ".flv", Timeout:-1, }); e != nil{l.E(e)} - Saveflv_transcode() l.I("结束") + Ass_f("")//ass + Saveflv_transcode() + l.I("转码结束") close(saveflv.wait) } @@ -351,23 +360,25 @@ func Autobanf(s string) bool { }() var res []float32 - - pt := float32(len([]rune(s))) - if pt <= 5 {return false}//字数过少去除 - res = append(res, pt) - - pt = selfcross(s); - if pt > 0.5 {return false}//自身重复高去除 - res = append(res, pt) - - pt = cross(s, autoban.buf); - if pt > 0.7 {return false}//历史重复高去除 - res = append(res, pt) - - pt = cross(s, autoban.Banbuf); - if pt < 0.8 {return false}//ban字符重复低去除 - res = append(res, pt) - + { + pt := float32(len([]rune(s))) + if pt <= 5 {return false}//字数过少去除 + res = append(res, pt) + } + { + pt := selfcross(s); + // if pt > 0.5 {return false}//自身重复高去除 + // res = append(res, pt) + + pt1 := cross(s, autoban.buf); + if pt + pt1 > 0.5 {return false}//历史重复高去除 + res = append(res, pt, pt1) + } + { + pt := cross(s, autoban.Banbuf); + if pt < 0.8 {return false}//ban字符重复低去除 + res = append(res, pt) + } l := p.Logf().New().Open("danmu.log").Base(1, "autoban") l.W(res).Block() return true diff --git a/Reply/Reply.go b/Reply/Reply.go index 8f41844..9a9801f 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -8,7 +8,7 @@ import ( p "github.com/qydysky/part" F "github.com/qydysky/bili_danmu/F" S "github.com/qydysky/bili_danmu/Send" - c "github.com/qydysky/bili_danmu/Const" + c "github.com/qydysky/bili_danmu/CV" ) var replylog = p.Logf().New().Open("danmu.log").Base(-1, "Reply.go") @@ -81,7 +81,9 @@ func (replyF) special_gift(s string){ if content != nil { sh = append(sh, "节奏风暴", content, "¥ 100") } - + {//额外 + Assf(fmt.Sprintln(sh...)) + } fmt.Println("\n====") fmt.Println(sh...) fmt.Print("====\n\n") @@ -105,7 +107,9 @@ func (replyF) guard_buy(s string){ if price != nil { sh = append(sh, "¥", int(price.(float64)) / 1000) } - + {//额外 ass + Assf(fmt.Sprintln(sh...)) + } fmt.Println("\n====") fmt.Println(sh...) fmt.Print("====\n\n") @@ -187,7 +191,9 @@ func (replyF) send_gift(s string){ //小于3万金瓜子 if allprice < 30000 {msglog.T(sh...);return} - + {//额外 + Assf(fmt.Sprintln(sh...)) + } fmt.Println("\n====") fmt.Println(sh...) fmt.Print("====\n\n") @@ -271,7 +277,9 @@ func (replyF) super_chat_message(s string){ } msglog.Fileonly(true) defer msglog.Fileonly(false) - + {//额外 + Assf(fmt.Sprintln(sh...)) + } fmt.Println("\n====") fmt.Println(sh...) fmt.Print("====\n\n") @@ -348,8 +356,8 @@ func (replyF) danmu(s string) { {//附加功能 弹幕机 封禁 弹幕合并 Danmujif(msg) if Autobanf(msg) { - fmt.Println("风险", msg) - msglog.Base(1, "风险").I(msg) + fmt.Println("风险", auth, ":", msg) + msglog.Base(1, "风险").I(auth, ":", msg) return } if i := Autoskipf(msg, 50, 15); i > 0 { @@ -373,7 +381,7 @@ func Msg_showdanmu(auth interface{}, msg string) { return } msg = Shortdanmuf(msg) - Assf(msg,"")//ass + Assf(msg)//ass } fmt.Println(msg) if auth != nil {msglog.I(auth, ":", msg)} diff --git a/bili_danmu.go b/bili_danmu.go index 7302da7..8c56ed3 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -9,12 +9,11 @@ import ( p "github.com/qydysky/part" reply "github.com/qydysky/bili_danmu/Reply" - c "github.com/qydysky/bili_danmu/Const" + c "github.com/qydysky/bili_danmu/CV" F "github.com/qydysky/bili_danmu/F" ) -const LogLevel = 1 -var danmulog = p.Logf().New().Open("danmu.log").Base(-1, "bili_danmu.go").Level(LogLevel) +var danmulog = p.Logf().New().Open("danmu.log").Base(-1, "bili_danmu.go").Level(c.LogLevel) func Demo() { @@ -45,7 +44,7 @@ func Demo() { var break_sign bool for !break_sign { //获取房间相关信息 - api := New_api(room).Get_host_Token().Get_live() + api := F.New_api(room).Get_host_Token().Get_live() if len(api.Url) == 0 || api.Roomid == 0 || api.Token == "" || api.Uid == 0 { danmulog.E("some err") return diff --git a/ws.go b/ws.go index 3645acd..2aa1b66 100644 --- a/ws.go +++ b/ws.go @@ -5,6 +5,7 @@ import ( "github.com/gorilla/websocket" + c "github.com/qydysky/bili_danmu/CV" p "github.com/qydysky/part" ) @@ -18,7 +19,7 @@ type ws struct { } func New_ws(url string) (o *ws) { - l := p.Logf().New().Base(-1, "ws.go>新建").Level(LogLevel).T("New_ws") + l := p.Logf().New().Base(-1, "ws.go>新建").Level(c.LogLevel).T("New_ws") defer l.Block() l.T("ok") @@ -31,7 +32,7 @@ func New_ws(url string) (o *ws) { func (i *ws) Handle() (o *ws) { o = i - l := p.Logf().New().Base(-1, "ws.go>处理").Level(LogLevel).T("*ws.handle") + l := p.Logf().New().Base(-1, "ws.go>处理").Level(c.LogLevel).T("*ws.handle") defer l.Block() if o.used { @@ -118,7 +119,7 @@ func (i *ws) Handle() (o *ws) { func (i *ws) Heartbeat(Millisecond int, msg []byte) (o *ws) { o = i - l := p.Logf().New().Base(-1, "ws.go>心跳").Level(LogLevel).T("*ws.heartbeat") + l := p.Logf().New().Base(-1, "ws.go>心跳").Level(c.LogLevel).T("*ws.heartbeat") defer l.Block() if !o.used { @@ -147,7 +148,7 @@ func (i *ws) Heartbeat(Millisecond int, msg []byte) (o *ws) { } func (o *ws) Close() { - l := p.Logf().New().Base(-1, "ws.go>关闭").Level(LogLevel) + l := p.Logf().New().Base(-1, "ws.go>关闭").Level(c.LogLevel) defer l.Block() if !o.used {