]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
config.json控制附加功能
authorqydysky <qydysky@foxmail.com>
Sun, 11 Oct 2020 02:01:45 +0000 (10:01 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 11 Oct 2020 02:01:45 +0000 (10:01 +0800)
CV/Var.go
Reply/F.go
demo/config.json [new file with mode: 0644]
demo/go.mod
demo/go.sum
go.mod
go.sum

index fe4056de7bf694e56ad4f81ccc0e28b27e798353..fd79c86b9bcd1d0bad109eefd7ebda521ed9fc2d 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -22,5 +22,4 @@ var Default_qn = map[string]string{
        "250":"超清",
        "150":"高清",
        "80":"流畅",
-       "0":"自动",
 }
\ No newline at end of file
index 394e2c5e84c17d20baf16ed9debe8eb16a9a8496..d2b526a3f000d10080f5b5031861b0bf6718f9ca 100644 (file)
@@ -14,6 +14,7 @@ import (
        F "github.com/qydysky/bili_danmu/F"
        "github.com/christopher-dG/go-obs-websocket"
        p "github.com/qydysky/part"
+       s "github.com/qydysky/part/setting"
 )
 
 /*
@@ -22,7 +23,7 @@ import (
 
 //功能开关
 var AllF = map[string]bool{
-       "Qtd":true,//Qt弹幕窗口
+       "Qtd":false,//Qt弹幕窗口
        "Saveflv":true,//保存直播流(默认高清,有cookie默认蓝光)
        "Ass":true,//Ass弹幕生成,由于时间对应关系,仅开启流保存时生效
        "Obs":false,//obs组件(仅录播)
@@ -41,6 +42,15 @@ var AllF = map[string]bool{
        "Shortdanmu":true,//上下文相同文字缩减
 }
 
+//从config.json初始化
+func init(){
+       buf := s.New()
+       buf.Load("config.json")
+       for k,v := range buf.B {
+               AllF[k] = v.(bool)
+       }
+}
+
 //功能开关选取函数
 func IsOn(s string) bool {
        if v, ok := AllF[s]; ok && v {
@@ -108,7 +118,6 @@ func selfcross2(a []string) (float32, string) {
 
 //Qtd 弹幕Qt窗口
 type Qtd struct {
-       Inuse bool
        Qt_MaxMun int 
        Qt_LineHeight float64 
        Qt_BlockMargin float64 
@@ -118,7 +127,6 @@ type Qtd struct {
 }
 
 var qtd = Qtd {
-       Inuse:IsOn("Qtd"),
        Qt_MaxMun:30,//danmu max limit
        Qt_LineHeight:90,//percent
        Qt_BlockMargin:7,
@@ -139,13 +147,12 @@ var qtd = Qtd {
 }
 
 func Qtdf(){
-       if !qtd.Inuse {return}
+       if !IsOn("Qtd") {return}
        go Qtdanmu()
 }
 
 //Ass 弹幕转字幕
 type Ass struct {
-       Inuse bool
        
        file string//弹幕ass文件名
        startT time.Time//开始记录的基准时间
@@ -161,7 +168,6 @@ var (
 )
 
 var ass = Ass {
-       Inuse:IsOn("Ass"),
 header:`[Script Info]
 Title: Default Ass file
 ScriptType: v4.00+
@@ -196,7 +202,7 @@ func Ass_f(file string, st time.Time){
 
 //传入要显示的单条字幕
 func Assf(s string){
-       if !ass.Inuse {return}
+       if !IsOn("Ass") {return}
        if ass.file == "" {return}
 
        if s == "" {return}
@@ -229,19 +235,17 @@ func dtos(t time.Duration) string {
 
 //直播流保存
 type Saveflv struct {
-       Inuse bool
        path string
        wait p.Signal
        cancel p.Signal
 }
 
 var saveflv = Saveflv {
-       Inuse:IsOn("Saveflv"),
 }
 
 //已go func形式调用,将会获取直播流
 func Saveflvf(){
-       if !saveflv.Inuse {return}
+       if !IsOn("Saveflv") {return}
        if saveflv.cancel.Islive() {return}
 
        l := p.Logf().New().Open("danmu.log").Base(-1, "saveflv")
@@ -331,26 +335,24 @@ func Saveflvf(){
 
 //已func形式调用,将会停止保存直播流
 func Saveflv_wait(){
-       if !saveflv.Inuse {return}
+       if !IsOn("Saveflv") {return}
        saveflv.cancel.Done()
        p.Logf().New().Open("danmu.log").Base(-1, "saveflv").I("等待").Block()
        saveflv.wait.Wait()
 }
 
 type Obs struct {
-       Inuse bool
        c obsws.Client
        Prog string//程序路径
 }
 
 var obs = Obs {
-       Inuse:IsOn("Obs"),
        c:obsws.Client{Host: "127.0.0.1", Port: 4444},
        Prog:"obs",
 }
 
 func Obsf(on bool){
-       if !obs.Inuse {return}
+       if !IsOn("Obs") {return}
        l := p.Logf().New().Open("danmu.log").Base(1, "obs")
        defer l.BC()
 
@@ -378,7 +380,7 @@ func Obsf(on bool){
 }
 
 func Obs_R(on bool){
-       if !obs.Inuse {return}
+       if !IsOn("Obs") {return}
 
        l := p.Logf().New().Open("danmu.log").Base(1, "obs_R")
        defer l.BC()
@@ -428,15 +430,13 @@ func Obs_R(on bool){
 type Autoban struct {
        Banbuf []string
        buf []string
-       Inuse bool
 }
 
 var autoban = Autoban {
-       Inuse:IsOn("Autoban"),
 }
 
 func Autobanf(s string) bool {
-       if !autoban.Inuse {return false}
+       if !IsOn("Autoban") {return false}
 
        if len(autoban.Banbuf) == 0 {
                f := p.File().FileWR(p.Filel{
@@ -483,14 +483,12 @@ func Autobanf(s string) bool {
 
 type Danmuji struct {
        buf map[string]string
-       Inuse bool
        Inuse_auto bool
 
        mute bool
 }
 
 var danmuji = Danmuji{
-       Inuse:IsOn("Danmuji"),
        Inuse_auto:IsOn("Danmuji_auto"),
        buf:map[string]string{
                "弹幕机在么":"在",
@@ -498,14 +496,14 @@ var danmuji = Danmuji{
 }
 
 func Danmujif(s string) {
-       if !danmuji.Inuse {return}
+       if !IsOn("Danmuji") {return}
        if v, ok := danmuji.buf[s]; ok {
                Msg_senddanmu(v)
        }
 }
 
 func Danmuji_auto(sleep int) {
-       if !danmuji.Inuse || !danmuji.Inuse_auto || danmuji.mute {return}
+       if !IsOn("Danmuji") || !IsOn("Danmuji_auto") || danmuji.mute {return}
        if sleep == 0 {return}
 
        danmuji.mute = true
@@ -523,19 +521,17 @@ func Danmuji_auto(sleep int) {
 }
 
 type Autoskip struct {
-       Inuse bool
        num int
        buf sync.Map
        bufbreak chan bool
 }
 
 var autoskip = Autoskip{
-       Inuse:IsOn("Autoskip"),
        bufbreak:make(chan bool, 10),
 }
 
 func Autoskipf(s string, maxNum,muteSecond int) int {
-       if !autoskip.Inuse || s == "" || maxNum <= 0 || muteSecond <= 0 {return 0}
+       if !IsOn("Autoskip") || s == "" || maxNum <= 0 || muteSecond <= 0 {return 0}
        if v, ok := autoskip.buf.LoadOrStore(s, 0); ok {
                autoskip.buf.Store(s, v.(int) + 1)
                return v.(int) + 1
@@ -557,16 +553,14 @@ func Autoskipf(s string, maxNum,muteSecond int) int {
 }
 
 type Lessdanmu struct {
-       Inuse bool
        buf []string
 }
 
 var lessdanmu = Lessdanmu{
-       Inuse:IsOn("Lessdanmu"),
 }
 
 func Lessdanmuf(s string, bufsize int) float32 {
-       if !lessdanmu.Inuse {return 0}
+       if !IsOn("Lessdanmu") {return 0}
        if len(lessdanmu.buf) < bufsize {
                lessdanmu.buf = append(lessdanmu.buf, s)
                return 0
@@ -586,12 +580,10 @@ func Lessdanmuf(s string, bufsize int) float32 {
        原理:留存弹幕,称为buf。将当前若干弹幕在buf中的位置找出,根据位置聚集情况及该位置出现语句的频率,选择发送的弹幕
 */
 // type Moredanmu struct {
-//     Inuse bool
 //     buf []string
 // }
 
 // var moredanmu = Moredanmu{
-//     Inuse:IsOn("Moredanmu"),
 // }
 // func moredanmuf(s string) {
 //     if !moredanmu.Inuse {return}
@@ -637,16 +629,14 @@ func Lessdanmuf(s string, bufsize int) float32 {
 // }
 
 type Shortdanmu struct {
-       Inuse bool
        lastdanmu []rune
 }
 
 var shortdanmu = Shortdanmu{
-       Inuse:IsOn("Shortdanmu"),
 }
 
 func Shortdanmuf(s string) string {
-       if !shortdanmu.Inuse {return s}
+       if !IsOn("Shortdanmu") {return s}
        if len(shortdanmu.lastdanmu) == 0 {shortdanmu.lastdanmu = []rune(s);return s}
 
        var new string
@@ -670,7 +660,6 @@ func Shortdanmuf(s string) string {
 }
 
 type Jiezou struct {
-       Inuse bool
        alertdanmu string
        skipS map[string]interface{}
 
@@ -680,7 +669,6 @@ type Jiezou struct {
 }
 
 var jiezou = Jiezou{
-       Inuse:IsOn("Jiezou"),
        alertdanmu:"",
        skipS:map[string]interface{}{//常见语气词忽略
                "了":nil,
@@ -693,7 +681,7 @@ var jiezou = Jiezou{
 }
 
 func Jiezouf(s []string) bool {
-       if !jiezou.Inuse {return false}
+       if !IsOn("Jiezou") {return false}
        now,S := selfcross2(s)
        jiezou.avg = (8 * jiezou.avg + 2 * now)/10
        if jiezou.turn < len(s) {jiezou.turn += 1;return false}
diff --git a/demo/config.json b/demo/config.json
new file mode 100644 (file)
index 0000000..af2d0ed
--- /dev/null
@@ -0,0 +1,14 @@
+{
+    "Qtd": true,
+    "Saveflv": true,
+    "Ass": true,
+    "Obs": false,
+    "Autoban": true,
+    "Jiezou": true,
+    "Danmuji": true,
+    "Danmuji_auto": false,
+    "Autoskip": true,
+    "Lessdanmu": true,
+    "Moredanmu": false,
+    "Shortdanmu": true
+}
\ No newline at end of file
index 2380cfd93b6f2adaaa87ad171f8492cd8372c264..21f70e555041950d71b588460338376579e9b90b 100644 (file)
@@ -8,7 +8,7 @@ require (
        github.com/klauspost/compress v1.11.1 // indirect
        github.com/mitchellh/mapstructure v1.3.3 // indirect
        github.com/qydysky/bili_danmu v0.0.0
-       github.com/qydysky/part v0.0.6 // indirect
+       github.com/qydysky/part v0.0.7 // indirect
        github.com/shirou/gopsutil v2.20.9+incompatible // indirect
        github.com/therecipe/env_darwin_amd64_513 v0.0.0-20190626001412-d8e92e8db4d0 // indirect
        github.com/therecipe/env_linux_amd64_513 v0.0.0-20190626000307-e137a3934da6 // indirect
index e94dc1c62dc16b4b918a1a784b0d06f380ad0b8c..fd236c82a7dfea37471105d37251cab736148ad9 100644 (file)
@@ -82,6 +82,8 @@ github.com/qydysky/part v0.0.5 h1:sbkXXRpviLJ81rav5SfWo/vIq2c0tQDa6kvWTqXgEL0=
 github.com/qydysky/part v0.0.5/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/qydysky/part v0.0.6 h1:DEIziO8d9PT+E1OIij3Ua0H8vO9Z5yqCJGb3m8BOGL0=
 github.com/qydysky/part v0.0.6/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
+github.com/qydysky/part v0.0.7 h1:nT7Y5WIMvKv/AhW+AyQJ+RccMO5zAML9SZZyCeWZs24=
+github.com/qydysky/part v0.0.7/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY=
 github.com/shirou/gopsutil v2.20.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
diff --git a/go.mod b/go.mod
index f6e0fc1b3bc49681fd0113da48f3c1f14de173e2..b2e1f642638820b8442f02c18ad83d8f48f3dcfc 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
        github.com/christopher-dG/go-obs-websocket v0.0.0-20200720193653-c4fed10356a5
        github.com/gorilla/websocket v1.4.2
        github.com/klauspost/compress v1.11.0 // indirect
-       github.com/qydysky/part v0.0.4
+       github.com/qydysky/part v0.0.6
        github.com/shirou/gopsutil v2.20.8+incompatible // indirect
        github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d
        golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
diff --git a/go.sum b/go.sum
index 335fece10934b7fef6b2f16cefd0d6ed7d622040..b94f2cb214381703329c76013c5f4f6c2b305016 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -39,6 +39,8 @@ github.com/qydysky/part v0.0.0-20200917071511-9f829642b501 h1:KYRfCW7+5t3Sj2+j8n
 github.com/qydysky/part v0.0.0-20200917071511-9f829642b501/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/qydysky/part v0.0.4 h1:MN1SXuP0korwTAFPG+hJmQHGFs9Aj7XBC4zAq6yEjsc=
 github.com/qydysky/part v0.0.4/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
+github.com/qydysky/part v0.0.6 h1:DEIziO8d9PT+E1OIij3Ua0H8vO9Z5yqCJGb3m8BOGL0=
+github.com/qydysky/part v0.0.6/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/shirou/gopsutil v2.20.7+incompatible h1:Ymv4OD12d6zm+2yONe39VSmp2XooJe8za7ngOLW/o/w=
 github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY=