]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
支持http代理
authorqydysky <qydysky@foxmail.com>
Sat, 24 Apr 2021 14:23:07 +0000 (22:23 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 24 Apr 2021 14:23:07 +0000 (22:23 +0800)
flv bug
小心心避免过多调用浏览器

14 files changed:
CV/Var.go
F/api.go
F/xinxin.go
Reply/F.go
Reply/flvDecode.go
Reply/gtk.go
Reply/tts.go
Send/Send.go
Send/Send_gift.go
Send/Send_pm.go
bili_danmu.go
demo/config/config_K_v.json
demo/go.mod
demo/go.sum

index ff835273fd38a5a6ea3690ed271667e8a695dbf6..489cda9d24c57cc11ed68550cf6b5dbde727da6c 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -59,6 +59,14 @@ func init() {
        }
 }
 
+//constKv
+var (
+       Proxy string//全局代理
+)
+func init() {
+       Proxy,_ = K_v.LoadV("http代理地址").(string)
+}
+
 //日志
 var Log = log.New(log.Config{
        File:`danmu.log`,
index df2f69a4f03bd94d4c7cb547d7414850bbf32552..5e343201a7104a3e851472bc7a9090a8a459ae8c 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -241,6 +241,7 @@ func Info(UpUid int) (info J.Info) {
                req := reqf.Req()
                if err := req.Reqf(reqf.Rval{
                        Url:`https://api.bilibili.com/x/space/acc/info?mid=`+strconv.Itoa(UpUid)+`&jsonp=jsonp`,
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });err != nil {
@@ -277,6 +278,7 @@ func Html() (missKey []string) {
        {
                r := g.Get(reqf.Rval{
                        Url:"https://live.bilibili.com/" + Roomid,
+                       Proxy:c.Proxy,
                })
 
                if tmp := r.S(`<script>window.__NEPTUNE_IS_MY_WAIFU__=`, `</script>`, 0, 0);tmp.Err != nil {
@@ -445,6 +447,7 @@ func getInfoByRoom() (missKey []string) {
                        Header:map[string]string{
                                `Referer`:"https://live.bilibili.com/" + Roomid,
                        },
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });err != nil {
@@ -530,6 +533,7 @@ func getRoomPlayInfo() (missKey []string) {
                                `Referer`:"https://live.bilibili.com/" + Roomid,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });err != nil {
@@ -690,6 +694,7 @@ func getRoomPlayInfoByQn() (missKey []string) {
                                `Referer`:"https://live.bilibili.com/" + Roomid,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });err != nil {
@@ -841,6 +846,7 @@ func getDanmuInfo() (missKey []string) {
                                `Referer`:"https://live.bilibili.com/" + Roomid,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:10,
                });err != nil {
                        apilog.L(`E: `,err)
@@ -885,6 +891,7 @@ func Get_face_src(uid string) (string) {
                        `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
                        `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                },
+               Proxy:c.Proxy,
                Timeout:10,
                Retry:2,
        });err != nil {
@@ -948,6 +955,7 @@ func Get_HotRank() (missKey []string) {
                                `Referer`:"https://live.bilibili.com/" + Roomid,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -1017,6 +1025,7 @@ func Get_guardNum() (missKey []string) {
                                `Referer`:"https://live.bilibili.com/" + Roomid,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -1137,6 +1146,7 @@ func Get_cookie() (missKey []string) {
                r := reqf.Req()
                if e := r.Reqf(reqf.Rval{
                        Url:`https://passport.bilibili.com/qrcode/getLoginUrl`,
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });e != nil {
@@ -1239,6 +1249,7 @@ func Get_cookie() (missKey []string) {
                                        `Referer`: `https://passport.bilibili.com/login`,
                                        `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
+                               Proxy:c.Proxy,
                                Timeout:10,
                                Retry:2,        
                        });e != nil {
@@ -1359,6 +1370,7 @@ func Get_list_in_room() (array []TGet_list_in_room) {
                                Header:map[string]string{
                                        `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
+                               Proxy:c.Proxy,
                                Timeout:10,
                                Retry:2,
                        });e != nil {
@@ -1438,6 +1450,7 @@ func Get_weared_medal() (item TGet_weared_medal) {
                        Header:map[string]string{
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });e != nil {
@@ -1546,6 +1559,7 @@ func CheckSwitch_FansMedal() (missKey []string) {
                                `Content-Type`:`application/x-www-form-urlencoded; charset=UTF-8`,
                                `Referer`: `https://passport.bilibili.com/login`,
                        },
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });e != nil {
@@ -1604,6 +1618,7 @@ func Dosign() {
                                `Referer`:"https://live.bilibili.com/all",
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -1650,6 +1665,7 @@ func Dosign() {
                                `Referer`:"https://live.bilibili.com/all",
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -1705,6 +1721,7 @@ func Get_LIVE_BUVID() (missKey []string) {
                                `DNT`: `1`,
                                `Upgrade-Insecure-Requests`: `1`,
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -1859,6 +1876,7 @@ func F_x25Kn() {
                                        `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
                                PostStr:url.PathEscape(PostStr),
+                               Proxy:c.Proxy,
                                Timeout:5,
                                Retry:2,
                        });err != nil {
@@ -1936,7 +1954,7 @@ func F_x25Kn() {
                        PostStr += `csrf_token=`+csrf+`&csrf=`+csrf+`&`
                        PostStr += `visit_id=`
                        
-                       if wasm := Wasm(3, 0, rt_obj);wasm == `` {//0全局
+                       if wasm := Wasm(0, rt_obj);wasm == `` {//0全局
                                apilog.L(`E: `,`发生错误`)
                                return
                        } else {
@@ -1967,6 +1985,7 @@ func F_x25Kn() {
                                        `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
                                PostStr:url.PathEscape(PostStr),
+                               Proxy:c.Proxy,
                                Timeout:5,
                                Retry:2,
                        });err != nil {
@@ -2048,6 +2067,7 @@ func Gift_list() (list []Gift_list_type_Data_List) {
                        `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
                        `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                },
+               Proxy:c.Proxy,
                Timeout:3,
                Retry:2,
        });err != nil {
@@ -2114,6 +2134,7 @@ func Silver_2_coin() (missKey []string) {
                                `Referer`:`https://link.bilibili.com/p/center/index`,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -2173,6 +2194,7 @@ func Silver_2_coin() (missKey []string) {
                                `Referer`:`https://link.bilibili.com/p/center/index`,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -2235,6 +2257,7 @@ func Silver_2_coin() (missKey []string) {
                                `Referer`:`https://link.bilibili.com/p/center/index`,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -2319,6 +2342,7 @@ func Feed_list() (Uplist []UpItem) {
                                `Referer`:`https://t.bilibili.com/pages/nav/index_new`,
                                `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
+                       Proxy:c.Proxy,
                        Timeout:3,
                        Retry:2,
                });err != nil {
@@ -2368,6 +2392,7 @@ func GetHistory(Roomid_int int) (j J.GetHistory) {
                        Header:map[string]string{
                                `Referer`:"https://live.bilibili.com/" + Roomid,
                        },
+                       Proxy:c.Proxy,
                        Timeout:10,
                        Retry:2,
                });err != nil {
@@ -2406,6 +2431,7 @@ func IsConnected() bool {
        req := reqf.Req()
        if err := req.Reqf(reqf.Rval{
                Url:"https://www.bilibili.com",
+               Proxy:c.Proxy,
                Timeout:10,
                JustResponseCode:true,
        });err != nil {
index 8ff8ff25c3987cd04f51a875cabae3479cfeb2e6..198b66c7b0cb7147d4dd0b3b6c6a87aca786bf0f 100644 (file)
@@ -137,9 +137,7 @@ func server() {
        wslog.L(`I: `,`使用WebJs`,webpath,`进行加密`)
 }
 
-func Wasm(maxloop int, uid uintptr,s RT) (o string) {//maxloop 超时重试
-       if maxloop <= 0 {return}
-
+func Wasm(uid uintptr,s RT) (o string) {//maxloop 超时重试
        {//nodejs
                if nodeJsUrl != "" {
                        req := reqf.Req()
@@ -149,10 +147,11 @@ func Wasm(maxloop int, uid uintptr,s RT) (o string) {//maxloop 超时重试
                                },
                                Url:nodeJsUrl,
                                PostStr:toNodeJsString(s),
+                               Proxy:c.Proxy,
                                Timeout:3,
                        });err != nil {
                                wslog.L(`E: `,err)
-                               o = Wasm(maxloop-1, uid, s)
+                               o = Wasm(uid, s)
                                return
                        }
 
@@ -185,6 +184,11 @@ func Wasm(maxloop int, uid uintptr,s RT) (o string) {//maxloop 超时重试
                        time.Sleep(time.Second*time.Duration(3))
                }
 
+               if ws.Len() == 0 {
+                       wslog.L(`W: `,`浏览器打开`,webpath,`失败,请手动打开`)
+                       return
+               }
+
                //获取websocket操作对象 发送
                ws.Interface().Push_tag(`send`,websocket.Uinterface{
                        Id:uid,
@@ -198,7 +202,6 @@ func Wasm(maxloop int, uid uintptr,s RT) (o string) {//maxloop 超时重试
                                return r.S
                        case <- time.After(time.Second*time.Duration(1)):
                                wslog.L(`E: `,`超时!响应>1s,确认保持`,webpath,`开启`)
-                               o = Wasm(maxloop-1, uid, s)
                                return
                        }
                }
@@ -219,7 +222,7 @@ func Close(uid uintptr){
 
 func test(uid uintptr) bool {
        time.Sleep(time.Second*time.Duration(3))
-       if s := Wasm(3, uid, RT{
+       if s := Wasm(uid, RT{
                R:R{
                Id: "[9,371,1,22613059]",
                Device: "[\"AUTO8216117272375373\",\"77bee604-b591-4664-845b-b69603f8c71c\"]",
index df04a0aa8aa86771eddf69d9a1e060e058506816..2238946c65c68ff37becda0b2da899c70777a5ab 100644 (file)
@@ -288,6 +288,7 @@ func Savestreamf(){
                                Url:m3u8_url,
                                Retry:4,
                                SleepTime:1,
+                               Proxy:c.Proxy,
                                Timeout:3,
                                Header:map[string]string{
                                        `Host`: url_struct.Host,
@@ -417,6 +418,7 @@ func Savestreamf(){
                                Url:c.Live[0],
                                Retry:10,
                                SleepTime:5,
+                               Proxy:c.Proxy,
                                Header:map[string]string{
                                        `Cookie`:reqf.Map_2_Cookies_String(CookieM),
                                },
@@ -443,7 +445,12 @@ func Savestreamf(){
                                byteC := make(chan []byte,1024*1024*30)//传来的关键帧间隔buf为3s,避免超出buf,设为30M
 
                                go func(){
-                                       for !p.Checkfile().IsExist(savestream.path + ".flv.dtmp") {time.Sleep(time.Second)}
+                                       for !p.Checkfile().IsExist(savestream.path + ".flv.dtmp") {
+                                               select {
+                                               case <-exit_chan:return;
+                                               case <-time.After(time.Second):;
+                                               }
+                                       }
                                        for {
                                                if err := Stream(savestream.path + ".flv.dtmp",&savestream.flv_front,byteC,exit_chan);err != nil {
                                                        flog.L(`T: `,err);
@@ -487,6 +494,7 @@ func Savestreamf(){
                        if e := rr.Reqf(reqf.Rval{
                                Url:link,
                                Retry:3,
+                               Proxy:c.Proxy,
                                SleepTime:3,
                                Header:map[string]string{
                                        `Cookie`:reqf.Map_2_Cookies_String(CookieM),
@@ -680,6 +688,7 @@ func Savestreamf(){
                                                        SleepTime:1,
                                                        SaveToPath:path+(*link).Base,
                                                        Timeout:3,
+                                                       Proxy:c.Proxy,
                                                }); e != nil{
                                                        l.L(`I: `,e,`将重试!`)
                                                        //避免影响后续猜测
@@ -1396,12 +1405,10 @@ func init() {
                                                if flushSupport {flusher.Flush()}
 
                                                //写入flv头,首tag
-                                               if n,err := w.Write(savestream.flv_front);err != nil {
+                                               if _,err := w.Write(savestream.flv_front);err != nil {
                                                        return
                                                } else if flushSupport {
                                                        flusher.Flush()
-                                               } else {
-                                                       fmt.Println("pass",n)
                                                }
 
                                                cancel := make(chan struct{})
index 832b306c88cc2a6e5a33a6a0e06bd7e1bf8619a5..d7235f0390340fe6d00b39cb1145b51857aaffe6 100644 (file)
@@ -59,30 +59,28 @@ func Stream(path string,front_buf *[]byte,streamChan chan []byte,cancel chan str
                Buf *[]byte
        }
 
-       var seachtag = func(f *os.File)(offset int64){
-               cur_offset,_ := f.Seek(0,1)
-               defer f.Seek(cur_offset,0)
+       var seachtag = func(f *os.File, begin_offset int64)(available_offset int64){
+               available_offset += begin_offset
+               f.Seek(begin_offset, 0)//seek to begin
 
-               f.Seek(tag_header_size,1)
-               buf := make([]byte, 1024*1024)
-               for {
-                       if size,_ := f.Read(buf);size == 0 {
-                               return
-                       } else {
-                               for offset=0;offset<int64(size); {
-                                       streamid_loc := bytes.Index(buf[offset:], []byte{0x00,0x00,0x00})
-                                       if streamid_loc == -1 {break}
-                                       offset += int64(streamid_loc)
-
-                                       if tag_type := buf[offset-6];tag_type != video_tag && tag_type != audio_tag && tag_type != script_tag {
-                                               continue
-                                       }
-                                       offset += int64(tag_header_size-6)
+               buf := make([]byte, 1024*1024*10)
+               if size,_ := f.Read(buf);size == 0 {
+                       return
+               } else {
+                       for buf_offset:=0;buf_offset<size; {
+                               if tag_offset := bytes.IndexAny(buf[buf_offset:], string([]byte{video_tag,audio_tag,script_tag}));tag_offset == -1 {
+                                       return
+                               } else if streamid_offset := bytes.Index(buf[tag_offset:], []byte{0x00,0x00,0x00});streamid_offset == -1 {
+                                       return
+                               } else if streamid_offset == 8 {
+                                       available_offset += int64(tag_offset + buf_offset)
                                        return
+                               } else {
+                                       buf_offset += tag_offset + 1
                                }
-                               f.Seek(-5,1)
                        }
                }
+               return
        }
 
        //get tag func
@@ -185,8 +183,7 @@ func Stream(path string,front_buf *[]byte,streamChan chan []byte,cancel chan str
                                time.Sleep(time.Second)
                                continue
                        } else if t.PreSize == 0 {
-                               f.Seek(last_available_offset,0)
-                               f.Seek(seachtag(f),1)
+                               f.Seek(seachtag(f, last_available_offset),0)
                                continue
                        } else if t.Tag == video_tag {
                                if t.FirstByte & 0xf0 == 0x10 {
index 26da5d717c36235614fa2b83819953a580bcd903..cdc2fb51607b59d2c6148bce52122dc077670623 100644 (file)
@@ -476,6 +476,7 @@ func Gtk_danmu() {
                                                Url:src,
                                                SaveToPath:Gtk_img_path + `/` + uid,
                                                Timeout:3,
+                                               Proxy:c.Proxy,
                                        }); e != nil{log.Println(e);}
                                }()
                        default:
index edc6b0eebccce5cb81ba5d8559f00034a80bfc7b..9adc2f11c4749f2c804b4de1b506601d8a17ca40 100644 (file)
@@ -93,6 +93,7 @@ func TTS(uid,msg string) {
                Timeout:3,
                Retry:1,
                SleepTime:500,
+               Proxy:c.Proxy,
        });err != nil {
                tts_log.L(`E: `,err)
                return
index 6fd863c5d5446312508db145b85c32fc33293da3..5e17ffaa6a7b6aa79f01fcbbbd5d1e0b94e8011f 100644 (file)
@@ -44,6 +44,7 @@ func Danmu_s(msg string, roomid int) {
                PostStr:url.PathEscape(PostStr),
                Retry:2,
                Timeout:5,
+               Proxy:c.Proxy,
                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`,
index 08570930aaee61db3a15f284102e541648188859..aaeef884e11da6bd04f7544cd9fe1a7ac734a6da 100644 (file)
@@ -55,6 +55,7 @@ func Send_gift(gift_id,bag_id,gift_num int) {
                        Url:`https://api.live.bilibili.com/gift/v2/live/bag_send`,
                        PostStr:url.PathEscape(sendStr),
                        Timeout:10,
+                       Proxy:c.Proxy,
                        Header:map[string]string{
                                `Host`: `api.vc.bilibili.com`,
                                `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
index 338ac0fe38c2128fbb2b19a98d052baa248c67a9..7e70d0074227d45e16e3d582e9722de50b0e81a6 100644 (file)
@@ -65,6 +65,7 @@ func Send_pm(uid int, msg string) error {
                Url:`https://api.vc.bilibili.com/web_im/v1/web_im/send_msg`,
                PostStr:url.PathEscape(send_str),
                Timeout:10,
+               Proxy:c.Proxy,
                Header:map[string]string{
                        `Host`: `api.vc.bilibili.com`,
                        `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
index 7bbacd867b30b1b0bb142fe468cb148a6c47b648..ff2a72f1b2ce705d53b4b7dee93f2e87e261fec2 100644 (file)
@@ -178,6 +178,7 @@ func Demo(roomid ...int) {
                                ws_c := ws.New_client(ws.Client{
                                        Url:v,
                                        TO:35 * 1000,
+                                       Proxy:c.Proxy,
                                        Func_abort_close:func(){danmulog.L(`I: `,`服务器连接中断`)},
                                        Func_normal_close:func(){danmulog.L(`I: `,`服务器连接关闭`)},
                                        Header: map[string]string{
index 8c2c3097ed3e664a4135bc7899349760757f3a86..fffeb66200599e134d8db7f370e482d2cbc9af61 100644 (file)
@@ -72,5 +72,7 @@
     "扫码登录-help": "当扫码登陆设置为true时,每次启动会检查,若失败则会要求登录",
     "扫码登录": true,
     "扫码登录自动打开标签页": false,
-    "网络中断不退出": true
+    "网络中断不退出": true,
+    "http代理地址-help":"例http://127.0.0.1:38223 为空时不使用",
+    "http代理地址":""
 }
\ No newline at end of file
index 9dbd872ef6b11c1c5c5eb14ce4f5703311b964be..ba4c0dfa693bb46bfbb1a86afd488de0efe2fe65 100644 (file)
@@ -13,7 +13,7 @@ require (
        github.com/miekg/dns v1.1.41 // indirect
        github.com/mitchellh/mapstructure v1.4.1 // indirect
        github.com/qydysky/bili_danmu v0.5.7
-       github.com/qydysky/part v0.5.9 // indirect
+       github.com/qydysky/part v0.5.10 // indirect
        github.com/shirou/gopsutil v3.21.3+incompatible // indirect
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
index 8b82e9d1695b49c8d8749179a7ff8e52acbd6180..5cdb2fb5c9f9b71bd4d7e4ad3001b8a8d2aa2cc0 100644 (file)
@@ -267,6 +267,8 @@ github.com/qydysky/part v0.5.8 h1:sEGsa9ftwHSCu1yc9AjG2PCVE/kLHLkUpYTVYWJvV6Y=
 github.com/qydysky/part v0.5.8/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
 github.com/qydysky/part v0.5.9 h1:XZxBs6bBVQCKH48791X8ebrReY50aGw9IFCdaM1QhGA=
 github.com/qydysky/part v0.5.9/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
+github.com/qydysky/part v0.5.10 h1:SYdPGV1DlHFDKjDGBU3dXbuR9WA8NNwTbQ2nDjdyeiA=
+github.com/qydysky/part v0.5.10/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=