From d91ebb637315ac1a96fb71f72d52b7ed95a58b95 Mon Sep 17 00:00:00 2001 From: qydysky Date: Fri, 13 May 2022 00:43:01 +0800 Subject: [PATCH] sys --- CV/Var.go | 2 +- F/api.go | 21 ++++++++++++--------- F/xinxin.go | 6 +++--- Reply/F.go | 29 +++++++++++++++++------------ Reply/gtk.go | 3 ++- Reply/stream.go | 4 +++- Reply/tts.go | 9 +++++---- Send/Send.go | 4 ++-- Send/Send_pm.go | 3 ++- bili_danmu.go | 8 ++++---- cmd/cmd.go | 4 ++-- demo/go.mod | 2 +- demo/go.sum | 4 ++++ go.mod | 2 +- go.sum | 4 ++++ 15 files changed, 63 insertions(+), 42 deletions(-) diff --git a/CV/Var.go b/CV/Var.go index b47d919..1538abf 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -36,7 +36,7 @@ type Common struct { Token string //弹幕钥 WSURL []string //弹幕链接 LIVE_BUVID bool //cookies含LIVE_BUVID - Stream_url string //直播Web服务 + Stream_url []string //直播Web服务 Proxy string //全局代理 AcceptQn map[int]string //允许的直播流质量 Qn map[int]string //全部直播流质量 diff --git a/F/api.go b/F/api.go index 2a1cb9c..b91fcd5 100644 --- a/F/api.go +++ b/F/api.go @@ -19,6 +19,7 @@ import ( g "github.com/qydysky/part/get" limit "github.com/qydysky/part/limit" reqf "github.com/qydysky/part/reqf" + sys "github.com/qydysky/part/sys" web "github.com/qydysky/part/web" uuid "github.com/gofrs/uuid" @@ -1269,7 +1270,7 @@ func (c *GetFunc) Get_cookie() (missKey []string) { } var server = &http.Server{ - Addr: p.Sys().GetIntranetIp() + ":" + strconv.Itoa(p.Sys().GetFreePort()), + Addr: "0.0.0.0:" + strconv.Itoa(sys.Sys().GetFreePort()), } { //生成二维码 qr.WriteFile(img_url, qr.Medium, 256, `qr.png`) @@ -1305,8 +1306,10 @@ func (c *GetFunc) Get_cookie() (missKey []string) { WhiteChar: `OO`, }) apilog.L(`W: `, `手机扫命令行二维码登录`) - apilog.L(`W: `, `或打开链接扫码登录:`, `http://`+server.Addr+`/qr.png`) - p.Sys().Timeoutf(1) + for _, v := range sys.GetIntranetIp(``) { + apilog.L(`W: `, `或打开链接扫码登录:`, strings.Replace(`http://`+s.Server.Addr+`/qr.png`, `0.0.0.0`, v, -1)) + } + sys.Sys().Timeoutf(1) } //有新实例,退出 @@ -1324,7 +1327,7 @@ func (c *GetFunc) Get_cookie() (missKey []string) { for { //3s刷新查看是否通过 - p.Sys().Timeoutf(3) + sys.Sys().Timeoutf(3) //有新实例,退出 if boot_Get_cookie.NeedExit(id) { @@ -1904,7 +1907,7 @@ func F_x25Kn() { { //查看今天小心心数量 var num = 0 for _, v := range Gift_list() { - if v.Gift_id == 30607 && v.Expire_at-int(p.Sys().GetSTime()) > 6*86400 { + if v.Gift_id == 30607 && v.Expire_at-int(sys.Sys().GetSTime()) > 6*86400 { num = v.Gift_num } } @@ -1949,7 +1952,7 @@ func F_x25Kn() { PostStr := `id=[` + strconv.Itoa(c.C.ParentAreaID) + `,` + strconv.Itoa(c.C.AreaID) + `,` + strconv.Itoa(loop_num) + `,` + strconv.Itoa(c.C.Roomid) + `]&` PostStr += `device=["` + LIVE_BUVID + `","` + new_uuid + `"]&` - PostStr += `ts=` + strconv.Itoa(int(p.Sys().GetMTime())) + PostStr += `ts=` + strconv.Itoa(int(sys.Sys().GetMTime())) PostStr += `&is_patch=0&` PostStr += `heart_beat=[]&` PostStr += `ua=Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&` @@ -2022,7 +2025,7 @@ func F_x25Kn() { { //查看今天小心心数量 var num = 0 for _, v := range Gift_list() { - if v.Gift_id == 30607 && v.Expire_at-int(p.Sys().GetSTime()) > 6*86400 { + if v.Gift_id == 30607 && v.Expire_at-int(sys.Sys().GetSTime()) > 6*86400 { num = v.Gift_num } } @@ -2051,7 +2054,7 @@ func F_x25Kn() { Ets: res.Data.Timestamp, Benchmark: res.Data.Secret_key, Time: res.Data.Heartbeat_interval, - Ts: int(p.Sys().GetMTime()), + Ts: int(sys.Sys().GetMTime()), Ua: `Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`, }, T: res.Data.Secret_rule, @@ -2178,7 +2181,7 @@ func Gift_list() (list []Gift_list_type_Data_List) { defer c.C.ReqPool.Put(reqi) req := reqi.Item.(*reqf.Req) if err := req.Reqf(reqf.Rval{ - Url: `https://api.live.bilibili.com/xlive/web-room/v1/gift/bag_list?t=` + strconv.Itoa(int(p.Sys().GetMTime())) + `&room_id=` + strconv.Itoa(c.C.Roomid), + Url: `https://api.live.bilibili.com/xlive/web-room/v1/gift/bag_list?t=` + strconv.Itoa(int(sys.Sys().GetMTime())) + `&room_id=` + strconv.Itoa(c.C.Roomid), Header: map[string]string{ `Host`: `api.live.bilibili.com`, `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, diff --git a/F/xinxin.go b/F/xinxin.go index 93a501c..a7ed537 100644 --- a/F/xinxin.go +++ b/F/xinxin.go @@ -9,9 +9,9 @@ import ( c "github.com/qydysky/bili_danmu/CV" - p "github.com/qydysky/part" msgq "github.com/qydysky/part/msgq" reqf "github.com/qydysky/part/reqf" + sys "github.com/qydysky/part/sys" web "github.com/qydysky/part/web" websocket "github.com/qydysky/part/websocket" @@ -117,7 +117,7 @@ func server() { } w := web.New(&http.Server{ - Addr: "127.0.0.1:" + strconv.Itoa(p.Sys().GetFreePort()), + Addr: "127.0.0.1:" + strconv.Itoa(sys.Sys().GetFreePort()), }) //新建web实例 w.Handle(map[string]func(http.ResponseWriter, *http.Request){ //路径处理函数 `/`: func(w http.ResponseWriter, r *http.Request) { @@ -197,7 +197,7 @@ func Wasm(uid uintptr, rt RT) (so RT, o string) { //maxloop 超时重试 } if !strings.Contains(so.R.Ua, `Test`) { - so.R.Ts = int(p.Sys().GetMTime()) + so.R.Ts = int(sys.Sys().GetMTime()) } b, e := json.Marshal(so) if e != nil { diff --git a/Reply/F.go b/Reply/F.go index 5b455bc..03c4112 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -27,6 +27,7 @@ import ( limit "github.com/qydysky/part/limit" msgq "github.com/qydysky/part/msgq" psync "github.com/qydysky/part/sync" + sys "github.com/qydysky/part/sys" web "github.com/qydysky/part/web" websocket "github.com/qydysky/part/websocket" @@ -130,7 +131,7 @@ func ShowRevf() { for { c.C.Log.Base(`功能`).L(`I: `, fmt.Sprintf("营收 ¥%.2f", c.C.Rev)) for c.C.Rev == ShowRev_old { - p.Sys().Timeoutf(60) + sys.Sys().Timeoutf(60) } ShowRev_old = c.C.Rev } @@ -352,18 +353,18 @@ func Obsf(on bool) { l := c.C.Log.Base(`obs`) if on { - if p.Sys().CheckProgram("obs")[0] != 0 { + if sys.Sys().CheckProgram("obs")[0] != 0 { l.L(`W: `, "obs已经启动") return } - if p.Sys().CheckProgram("obs")[0] == 0 { + if sys.Sys().CheckProgram("obs")[0] == 0 { if obs.Prog == "" { l.L(`E: `, "未知的obs程序位置") return } l.L(`I: `, "启动obs") p.Exec().Start(exec.Command(obs.Prog)) - p.Sys().Timeoutf(3) + sys.Sys().Timeoutf(3) } // Connect a client. @@ -372,7 +373,7 @@ func Obsf(on bool) { return } } else { - if p.Sys().CheckProgram("obs")[0] == 0 { + if sys.Sys().CheckProgram("obs")[0] == 0 { l.L(`W: `, "obs未启动") return } @@ -387,7 +388,7 @@ func Obs_R(on bool) { l := c.C.Log.Base("obs_R") - if p.Sys().CheckProgram("obs")[0] == 0 { + if sys.Sys().CheckProgram("obs")[0] == 0 { l.L(`W: `, "obs未启动") return } else { @@ -425,7 +426,7 @@ func Obs_R(on bool) { if resp.Status() == "ok" { l.L(`I: `, "停止录制") } - p.Sys().Timeoutf(3) + sys.Sys().Timeoutf(3) } } @@ -565,7 +566,7 @@ func Danmuji_auto() { if msg := list[i]; msg != `` { Msg_senddanmu(msg) } - p.Sys().Timeoutf(timeout) + sys.Sys().Timeoutf(timeout) } }() } @@ -1025,7 +1026,7 @@ func init() { addr := "0.0.0.0:" if port == 0 { - addr += strconv.Itoa(p.Sys().GetFreePort()) + addr += strconv.Itoa(sys.Sys().GetFreePort()) } else { addr += strconv.Itoa(port) } @@ -1121,9 +1122,13 @@ func init() { s.Server.Shutdown(context.Background()) }, }) - host := p.Sys().GetIntranetIp() - c.C.Stream_url = strings.Replace(`http://`+s.Server.Addr, `0.0.0.0`, host, -1) - flog.L(`I: `, `启动于`, c.C.Stream_url) + + c.C.Stream_url = []string{} + for _, v := range sys.GetIntranetIp(``) { + var url = strings.Replace(`http://`+s.Server.Addr, `0.0.0.0`, v, -1) + c.C.Stream_url = append(c.C.Stream_url, url) + flog.L(`I: `, `启动于`, url) + } } } diff --git a/Reply/gtk.go b/Reply/gtk.go index 2413c39..996ca1d 100644 --- a/Reply/gtk.go +++ b/Reply/gtk.go @@ -18,6 +18,7 @@ import ( c "github.com/qydysky/bili_danmu/CV" F "github.com/qydysky/bili_danmu/F" + sys "github.com/qydysky/part/sys" p "github.com/qydysky/part" msgq "github.com/qydysky/part/msgq" @@ -125,7 +126,7 @@ func Gtk_danmu() { ) application, err := gtk.ApplicationNew( - "com.github.qydysky.bili_danmu.reply"+p.Sys().GetTime(), //时间戳允许多开 + "com.github.qydysky.bili_danmu.reply"+sys.Sys().GetTime(), //时间戳允许多开 glib.APPLICATION_FLAGS_NONE) if err != nil { diff --git a/Reply/stream.go b/Reply/stream.go index 19fbf07..5ce9875 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -395,7 +395,9 @@ func (t *M4SStream) saveStream() { } else { t.log.L(`W: `, err) } - t.log.L(`I: `, "流地址:", t.common.Stream_url) + for _, v := range t.common.Stream_url { + t.log.L(`I: `, "流地址:", v) + } //开始,结束回调 t.Callback_start(t) diff --git a/Reply/tts.go b/Reply/tts.go index 62ee463..b62afa1 100644 --- a/Reply/tts.go +++ b/Reply/tts.go @@ -21,6 +21,7 @@ import ( msgq "github.com/qydysky/part/msgq" reqf "github.com/qydysky/part/reqf" pstrings "github.com/qydysky/part/strings" + sys "github.com/qydysky/part/sys" ws "github.com/qydysky/part/websocket" ) @@ -177,7 +178,7 @@ func TTS(msg string) { func play() { var prog = []string{} - prog = append(prog, p.Sys().Cdir()+"/tts.mp3") + prog = append(prog, sys.Sys().Cdir()+"/tts.mp3") prog = append(prog, strings.Split(tts_prog_set, " ")...) p.Exec().Run(false, tts_prog, prog...) @@ -189,7 +190,7 @@ func baidu(msg string) error { req := reqi.Item.(*reqf.Req) if err := req.Reqf(reqf.Rval{ Url: `https://fanyi.baidu.com/gettts?lan=zh&text=` + url.PathEscape(msg) + `&spd=5&source=web`, - SaveToPath: p.Sys().Cdir() + `/tts.mp3`, + SaveToPath: sys.Sys().Cdir() + `/tts.mp3`, Timeout: 3 * 1000, Retry: 1, SleepTime: 5000, @@ -247,7 +248,7 @@ func youdao(msg string) error { if err := req.Reqf(reqf.Rval{ Url: `https://openapi.youdao.com/ttsapi`, PostStr: url.PathEscape(postS), - SaveToPath: p.Sys().Cdir() + `/tts.mp3`, + SaveToPath: sys.Sys().Cdir() + `/tts.mp3`, Timeout: 3 * 1000, Retry: 1, SleepTime: 5000, @@ -408,7 +409,7 @@ func init() { } if len(buf) != 0 { p.File().FileWR(p.Filel{ - File: p.Sys().Cdir() + `/tts.mp3`, + File: sys.Sys().Cdir() + `/tts.mp3`, Context: []interface{}{buf}, }) play() diff --git a/Send/Send.go b/Send/Send.go index 2a8e85e..7d9ed4f 100644 --- a/Send/Send.go +++ b/Send/Send.go @@ -7,9 +7,9 @@ import ( c "github.com/qydysky/bili_danmu/CV" - p "github.com/qydysky/part" limit "github.com/qydysky/part/limit" reqf "github.com/qydysky/part/reqf" + sys "github.com/qydysky/part/sys" ) //每5s一个令牌,最多等20秒 @@ -41,7 +41,7 @@ func Danmu_s(msg string, roomid int) { return true }) - PostStr := `color=16777215&fontsize=25&mode=1&msg=` + msg + `&rnd=` + strconv.Itoa(int(p.Sys().GetSTime())) + `&roomid=` + strconv.Itoa(roomid) + `&bubble=0&csrf_token=` + csrf + `&csrf=` + csrf + PostStr := `color=16777215&fontsize=25&mode=1&msg=` + msg + `&rnd=` + strconv.Itoa(int(sys.Sys().GetSTime())) + `&roomid=` + strconv.Itoa(roomid) + `&bubble=0&csrf_token=` + csrf + `&csrf=` + csrf l.L(`I: `, "发送", msg, "至", roomid) reqi := c.C.ReqPool.Get() diff --git a/Send/Send_pm.go b/Send/Send_pm.go index 7cd6ee4..8e0dff5 100644 --- a/Send/Send_pm.go +++ b/Send/Send_pm.go @@ -11,6 +11,7 @@ import ( p "github.com/qydysky/part" limit "github.com/qydysky/part/limit" reqf "github.com/qydysky/part/reqf" + sys "github.com/qydysky/part/sys" uuid "github.com/gofrs/uuid" ) @@ -57,7 +58,7 @@ func Send_pm(uid int, msg string) error { return errors.New("TO") } - var send_str = `msg[sender_uid]=` + strconv.Itoa(c.C.Uid) + `&msg[receiver_id]=` + strconv.Itoa(uid) + `&msg[receiver_type]=1&msg[msg_type]=1&msg[msg_status]=0&msg[content]={"content":"` + msg + `"}&msg[timestamp]=` + strconv.Itoa(int(p.Sys().GetSTime())) + `&msg[new_face_version]=0&msg[dev_id]=` + strings.ToUpper(new_uuid) + `&from_firework=0&build=0&mobi_app=web&csrf_token=` + csrf + `&csrf=` + csrf + var send_str = `msg[sender_uid]=` + strconv.Itoa(c.C.Uid) + `&msg[receiver_id]=` + strconv.Itoa(uid) + `&msg[receiver_type]=1&msg[msg_type]=1&msg[msg_status]=0&msg[content]={"content":"` + msg + `"}&msg[timestamp]=` + strconv.Itoa(int(sys.Sys().GetSTime())) + `&msg[new_face_version]=0&msg[dev_id]=` + strings.ToUpper(new_uuid) + `&from_firework=0&build=0&mobi_app=web&csrf_token=` + csrf + `&csrf=` + csrf Cookie := make(map[string]string) c.C.Cookie.Range(func(k, v interface{}) bool { diff --git a/bili_danmu.go b/bili_danmu.go index 1858902..5deaee0 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -14,8 +14,8 @@ import ( reply "github.com/qydysky/bili_danmu/Reply" send "github.com/qydysky/bili_danmu/Send" Cmd "github.com/qydysky/bili_danmu/cmd" + sys "github.com/qydysky/part/sys" - p "github.com/qydysky/part" msgq "github.com/qydysky/part/msgq" reqf "github.com/qydysky/part/reqf" ws "github.com/qydysky/part/websocket" @@ -38,7 +38,7 @@ func Start(roomid ...int) { var danmulog = c.C.Log.Base(`bilidanmu`) defer danmulog.Block(1000) - var stop = p.Sys().PreventSleep() + var stop = sys.Sys().PreventSleep() defer stop.Done() //ctrl+c退出 @@ -220,7 +220,7 @@ func Start(roomid ...int) { } //30s获取一次人气 go func() { - p.Sys().MTimeoutf(500) //500ms + sys.Sys().MTimeoutf(500) //500ms danmulog.L(`T: `, "获取人气") go func() { heartbeatmsg, heartinterval := F.Heartbeat() @@ -323,7 +323,7 @@ func Start(roomid ...int) { reply.StreamOStop(-1) //停止其他房间录制 } } - p.Sys().Timeoutf(1) + sys.Sys().Timeoutf(1) } { //附加功能 直播流停止 diff --git a/cmd/cmd.go b/cmd/cmd.go index ce3fa38..2f8cfc4 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -175,8 +175,8 @@ func Cmd() { } fmt.Println(`舰长数:`, c.C.GuardNum) fmt.Println(`分区排行:`, c.C.Note, `人气:`, c.C.Renqi, `观看人数:`, c.C.Watched) - if c.C.Stream_url != "" { - fmt.Println(`直播Web服务:`, c.C.Stream_url) + for _, v := range c.C.Stream_url { + fmt.Println(`直播Web服务:`, v) } var array = reply.StreamOCommon(-1) fmt.Println(`正在录制的房间:`) diff --git a/demo/go.mod b/demo/go.mod index 9fcc41f..bd954d4 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -4,7 +4,7 @@ go 1.14 require ( github.com/qydysky/bili_danmu v0.5.9 - github.com/qydysky/part v0.9.7 // indirect + github.com/qydysky/part v0.9.9 // indirect github.com/stretchr/testify v1.7.1 // indirect ) diff --git a/demo/go.sum b/demo/go.sum index 95edbb6..b54424e 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -60,6 +60,10 @@ github.com/qydysky/part v0.9.6 h1:O2hnPQGUFSfWb8eXsNrR0rXHbK0tUoMTjCEP+9E0I+0= github.com/qydysky/part v0.9.6/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part v0.9.7 h1:XaMB1QF5lCK5EsL30ffeaNw8/QpDPCs2MxWSWwTLR4s= github.com/qydysky/part v0.9.7/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.9.8 h1:9mfT7ZrwnfRI1PWds38DjGuTxMenaC0aiFGMO6aFNNQ= +github.com/qydysky/part v0.9.8/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.9.9 h1:7MWPq5WnFqHyE8owATgl90cdnxbPMVQWspvv1Fz7nts= +github.com/qydysky/part v0.9.9/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/shirou/gopsutil v3.20.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.21.5+incompatible h1:OloQyEerMi7JUrXiNzy8wQ5XN+baemxSl12QgIzt0jc= github.com/shirou/gopsutil v3.21.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= diff --git a/go.mod b/go.mod index 63030a3..6947fcb 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ 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.9.7 + github.com/qydysky/part v0.9.9 github.com/shirou/gopsutil v3.21.5+incompatible // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 diff --git a/go.sum b/go.sum index 2dc677e..2c7ab7c 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/qydysky/part v0.9.7 h1:XaMB1QF5lCK5EsL30ffeaNw8/QpDPCs2MxWSWwTLR4s= github.com/qydysky/part v0.9.7/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.9.8 h1:9mfT7ZrwnfRI1PWds38DjGuTxMenaC0aiFGMO6aFNNQ= +github.com/qydysky/part v0.9.8/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.9.9 h1:7MWPq5WnFqHyE8owATgl90cdnxbPMVQWspvv1Fz7nts= +github.com/qydysky/part v0.9.9/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/shirou/gopsutil v3.20.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.21.5+incompatible h1:OloQyEerMi7JUrXiNzy8wQ5XN+baemxSl12QgIzt0jc= github.com/shirou/gopsutil v3.21.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -- 2.39.2