]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
reqf包修复
authorqydysky <qydysky@foxmail.com>
Sun, 11 Apr 2021 09:36:43 +0000 (17:36 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 11 Apr 2021 09:36:43 +0000 (17:36 +0800)
扫码登录在命令行也显示二维码

13 files changed:
F/api.go
F/xinxin.go
README.md
Reply/F.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 93dc0317e17001bc96c0f603f7d8bfa9a43adfc4..25fd6dadca1a45f3768a8a2a3bbebc7d717d9344 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -9,17 +9,20 @@ import (
        "encoding/json"
        "net/http"
        "net/url"
-       "errors"
 
-       "github.com/skratchdot/open-golang/open"
-       qr "github.com/skip2/go-qrcode"
        c "github.com/qydysky/bili_danmu/CV"
        J "github.com/qydysky/bili_danmu/Json"
+
+       p "github.com/qydysky/part"
+       g "github.com/qydysky/part/get"
        web "github.com/qydysky/part/web"
+       reqf "github.com/qydysky/part/reqf"
        funcCtrl "github.com/qydysky/part/funcCtrl"
-       g "github.com/qydysky/part/get"
-       p "github.com/qydysky/part"
+
        uuid "github.com/gofrs/uuid"
+       qr "github.com/skip2/go-qrcode"
+       "github.com/mdp/qrterminal/v3"
+       "github.com/skratchdot/open-golang/open"
 )
 
 var apilog = c.Log.Base(`api`)
@@ -234,8 +237,8 @@ func Info(UpUid int) (info J.Info) {
 
        //html
        {
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.bilibili.com/x/space/acc/info?mid=`+strconv.Itoa(UpUid)+`&jsonp=jsonp`,
                        Timeout:10,
                        Retry:2,
@@ -271,7 +274,7 @@ func Html() (missKey []string) {
        
        //html
        {
-               r := g.Get(p.Rval{
+               r := g.Get(reqf.Rval{
                        Url:"https://live.bilibili.com/" + Roomid,
                })
 
@@ -397,8 +400,8 @@ func getInfoByRoom() (missKey []string) {
        Roomid := strconv.Itoa(c.Roomid)
 
        {//使用其他api
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + Roomid,
                        Header:map[string]string{
                                `Referer`:"https://live.bilibili.com/" + Roomid,
@@ -481,12 +484,12 @@ func getRoomPlayInfo() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:"https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?no_playurl=0&mask=1&qn=0&platform=web&protocol=0,1&format=0,2&codec=0,1&room_id=" + Roomid,
                        Header:map[string]string{
                                `Referer`:"https://live.bilibili.com/" + Roomid,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:10,
                        Retry:2,
@@ -588,12 +591,12 @@ func getRoomPlayInfoByQn() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:"https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?no_playurl=0&mask=1&qn="+ strconv.Itoa(c.Live_qn) +"&platform=web&protocol=0,1&format=0,2&codec=0,1&room_id=" + Roomid,
                        Header:map[string]string{
                                `Referer`:"https://live.bilibili.com/" + Roomid,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:10,
                        Retry:2,
@@ -685,12 +688,12 @@ func getDanmuInfo() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?type=0&id=" + Roomid,
                        Header:map[string]string{
                                `Referer`:"https://live.bilibili.com/" + Roomid,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:10,
                });err != nil {
@@ -729,12 +732,12 @@ func Get_face_src(uid string) (string) {
                return true
        })
 
-       req := p.Req()
-       if err := req.Reqf(p.Rval{
+       req := reqf.Req()
+       if err := req.Reqf(reqf.Rval{
                Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuMedalAnchorInfo?ruid=" + uid,
                Header:map[string]string{
                        `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
-                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                },
                Timeout:10,
                Retry:2,
@@ -783,8 +786,8 @@ func Get_HotRank() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/xlive/general-interface/v1/rank/getHotRank?ruid=`+strconv.Itoa(c.UpUid)+`&room_id=`+Roomid+`&is_pre=0&page_size=50&source=2&area_id=`+strconv.Itoa(c.ParentAreaID),
                        Header:map[string]string{
                                `Host`: `api.live.bilibili.com`,
@@ -797,7 +800,7 @@ func Get_HotRank() (missKey []string) {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:"https://live.bilibili.com/" + Roomid,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -852,8 +855,8 @@ func Get_guardNum() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid=`+Roomid+`&page=1&ruid=`+strconv.Itoa(c.UpUid)+`&page_size=29`,
                        Header:map[string]string{
                                `Host`: `api.live.bilibili.com`,
@@ -866,7 +869,7 @@ func Get_guardNum() (missKey []string) {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:"https://live.bilibili.com/" + Roomid,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -904,7 +907,7 @@ func Get_Version() (missKey []string) {
 
        var player_js_url string
        {//获取player_js_url
-               r := g.Get(p.Rval{
+               r := g.Get(reqf.Rval{
                        Url:"https://live.bilibili.com/blanc/" + Roomid,
                })
 
@@ -935,7 +938,7 @@ func Get_Version() (missKey []string) {
        }
 
        {//获取VERSION
-               r := g.Get(p.Rval{
+               r := g.Get(reqf.Rval{
                        Url:player_js_url,
                })
 
@@ -966,7 +969,7 @@ func Get_cookie() (missKey []string) {
        
        if p.Checkfile().IsExist("cookie.txt") {//读取cookie文件
                if cookieString := string(CookieGet());cookieString != ``{
-                       for k,v := range p.Cookies_String_2_Map(cookieString){//cookie存入全局变量syncmap
+                       for k,v := range reqf.Cookies_String_2_Map(cookieString){//cookie存入全局变量syncmap
                                c.Cookie.Store(k, v)
                        }
                        if miss := CookieCheck([]string{
@@ -985,8 +988,8 @@ func Get_cookie() (missKey []string) {
        var img_url string
        var oauth string
        {//获取二维码
-               r := p.Req()
-               if e := r.Reqf(p.Rval{
+               r := reqf.Req()
+               if e := r.Reqf(reqf.Rval{
                        Url:`https://passport.bilibili.com/qrcode/getLoginUrl`,
                        Timeout:10,
                        Retry:2,
@@ -1050,7 +1053,14 @@ func Get_cookie() (missKey []string) {
                defer server.Shutdown(context.Background())
 
                if c.K_v.LoadV(`扫码登录自动打开标签页`).(bool) {open.Run(`http://`+server.Addr+`/qr.png`)}
-               apilog.L(`W: `,`打开链接扫码登录:`,`http://`+server.Addr+`/qr.png`)
+               apilog.L(`W: `,`打开链接扫码登录:`,`http://`+server.Addr+`/qr.png`).Block(1000)
+               //show qr code in cmd
+               qrterminal.GenerateWithConfig(img_url, qrterminal.Config{
+                       Level: qrterminal.L,
+                       Writer: os.Stdout,
+                       BlackChar: qrterminal.BLACK,
+                       WhiteChar: qrterminal.WHITE,
+               })
                p.Sys().Timeoutf(1)
        }
        
@@ -1074,14 +1084,14 @@ func Get_cookie() (missKey []string) {
                        //有新实例,退出
                        if boot_Get_cookie.NeedExit(id) {return}
 
-                       r := p.Req()
-                       if e := r.Reqf(p.Rval{
+                       r := reqf.Req()
+                       if e := r.Reqf(reqf.Rval{
                                Url:`https://passport.bilibili.com/qrcode/getLoginInfo`,
                                PostStr:`oauthKey=`+oauth,
                                Header:map[string]string{
                                        `Content-Type`:`application/x-www-form-urlencoded; charset=UTF-8`,
                                        `Referer`: `https://passport.bilibili.com/login`,
-                                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
                                Timeout:10,
                                Retry:2,        
@@ -1106,7 +1116,7 @@ func Get_cookie() (missKey []string) {
                                        apilog.L(`E: `,`getLoginInfo cookies len == 0`)
                                        return
                                } else {
-                                       cookie = p.Map_2_Cookies_String(p.Cookies_List_2_Map(v))//cookie to string
+                                       cookie = reqf.Map_2_Cookies_String(reqf.Cookies_List_2_Map(v))//cookie to string
                                }
                                if cookie == `` {
                                        apilog.L(`E: `,`getLoginInfo cookies ""`)
@@ -1125,7 +1135,7 @@ func Get_cookie() (missKey []string) {
        if boot_Get_cookie.NeedExit(id) {return}
 
        {//写入cookie.txt
-               for k,v := range p.Cookies_String_2_Map(cookie){
+               for k,v := range reqf.Cookies_String_2_Map(cookie){
                        c.Cookie.Store(k, v)
                }
                //生成cookieString
@@ -1197,11 +1207,11 @@ func Get_list_in_room() (array []TGet_list_in_room) {
        {//获取牌子列表
                var medalList []TGet_list_in_room
                for pageNum:=1; true;pageNum+=1{
-                       r := p.Req()
-                       if e := r.Reqf(p.Rval{
+                       r := reqf.Req()
+                       if e := r.Reqf(reqf.Rval{
                                Url:`https://api.live.bilibili.com/fans_medal/v5/live_fans_medal/iApiMedal?page=`+strconv.Itoa(pageNum)+`&pageSize=10`,
                                Header:map[string]string{
-                                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
                                Timeout:10,
                                Retry:2,
@@ -1276,11 +1286,11 @@ func Get_weared_medal() (item TGet_weared_medal) {
        })
 
        {//获取
-               r := p.Req()
-               if e := r.Reqf(p.Rval{
+               r := reqf.Req()
+               if e := r.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/live_user/v1/UserInfo/get_weared_medal`,
                        Header:map[string]string{
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:10,
                        Retry:2,
@@ -1381,12 +1391,12 @@ func CheckSwitch_FansMedal() (missKey []string) {
                }
        }
        {//切换牌子
-               r := p.Req()
-               if e := r.Reqf(p.Rval{
+               r := reqf.Req()
+               if e := r.Reqf(reqf.Rval{
                        Url:post_url,
                        PostStr:post_str,
                        Header:map[string]string{
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                `Content-Type`:`application/x-www-form-urlencoded; charset=UTF-8`,
                                `Referer`: `https://passport.bilibili.com/login`,
                        },
@@ -1432,8 +1442,8 @@ func Dosign() {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/WebGetSignInfo`,
                        Header:map[string]string{
                                `Host`: `api.live.bilibili.com`,
@@ -1446,7 +1456,7 @@ func Dosign() {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:"https://live.bilibili.com/all",
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -1478,8 +1488,8 @@ func Dosign() {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign`,
                        Header:map[string]string{
                                `Host`: `api.live.bilibili.com`,
@@ -1492,7 +1502,7 @@ func Dosign() {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:"https://live.bilibili.com/all",
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -1534,8 +1544,8 @@ func Get_LIVE_BUVID() (missKey []string) {
        }
 
        for _,roomid := range roomIdList{//获取
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/live/getRoomKanBanModel?roomid=`+roomid,
                        Header:map[string]string{
                                `Host`: `live.bilibili.com`,
@@ -1558,7 +1568,7 @@ func Get_LIVE_BUVID() (missKey []string) {
 
                //cookie
                var has bool
-               for k,v := range p.Cookies_List_2_Map(req.Response.Cookies()){
+               for k,v := range reqf.Cookies_List_2_Map(req.Response.Cookies()){
                        c.Cookie.Store(k, v)
                        if k == `LIVE_BUVID` {has = true}
                }
@@ -1577,7 +1587,7 @@ func Get_LIVE_BUVID() (missKey []string) {
                return true
        })
        
-       CookieSet([]byte(p.Map_2_Cookies_String(Cookie)))
+       CookieSet([]byte(reqf.Map_2_Cookies_String(Cookie)))
 
        c.LIVE_BUVID = true
 
@@ -1681,12 +1691,12 @@ func F_x25Kn() {
                        return true
                })
 
-               req := p.Req()
+               req := reqf.Req()
                for {
                        //新调用,此退出
                        if boot_F_x25Kn.NeedExit(id) {return}
 
-                       if err := req.Reqf(p.Rval{
+                       if err := req.Reqf(reqf.Rval{
                                Url:`https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/E`,
                                Header:map[string]string{
                                        `Host`: `api.live.bilibili.com`,
@@ -1700,13 +1710,13 @@ func F_x25Kn() {
                                        `Pragma`: `no-cache`,
                                        `Cache-Control`: `no-cache`,
                                        `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
-                                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
                                PostStr:url.PathEscape(PostStr),
                                Timeout:5,
                                Retry:2,
                        });err != nil {
-                               if !errors.Is(err, context.DeadlineExceeded) {
+                               if !reqf.IsTimeout(err) {
                                        apilog.L(`E: `,err)
                                        return
                                }
@@ -1793,8 +1803,8 @@ func F_x25Kn() {
                                return true
                        })
 
-                       req := p.Req()
-                       if err := req.Reqf(p.Rval{
+                       req := reqf.Req()
+                       if err := req.Reqf(reqf.Rval{
                                Url:`https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/X`,
                                Header:map[string]string{
                                        `Host`: `api.live.bilibili.com`,
@@ -1808,13 +1818,13 @@ func F_x25Kn() {
                                        `Pragma`: `no-cache`,
                                        `Cache-Control`: `no-cache`,
                                        `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
-                                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                },
                                PostStr:url.PathEscape(PostStr),
                                Timeout:5,
                                Retry:2,
                        });err != nil {
-                               if errors.Is(err, context.DeadlineExceeded) {
+                               if !reqf.IsTimeout(err) {
                                        loop_num -= 1
                                        apilog.L(`W: `,`响应超时,将重试`)
                                        continue
@@ -1876,8 +1886,8 @@ func Gift_list() (list []Gift_list_type_Data_List) {
                return true
        })
 
-       req := p.Req()
-       if err := req.Reqf(p.Rval{
+       req := 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.Roomid),
                Header:map[string]string{
                        `Host`: `api.live.bilibili.com`,
@@ -1890,7 +1900,7 @@ func Gift_list() (list []Gift_list_type_Data_List) {
                        `Pragma`: `no-cache`,
                        `Cache-Control`: `no-cache`,
                        `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
-                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                },
                Timeout:3,
                Retry:2,
@@ -1942,8 +1952,8 @@ func Silver_2_coin() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/pay/v1/Exchange/getStatus`,
                        Header:map[string]string{
                                `Host`: `api.live.bilibili.com`,
@@ -1956,7 +1966,7 @@ func Silver_2_coin() (missKey []string) {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:`https://link.bilibili.com/p/center/index`,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -2001,8 +2011,8 @@ func Silver_2_coin() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/pay/v1/Exchange/getRule`,
                        Header:map[string]string{
                                `Host`: `api.live.bilibili.com`,
@@ -2015,7 +2025,7 @@ func Silver_2_coin() (missKey []string) {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:`https://link.bilibili.com/p/center/index`,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -2061,8 +2071,8 @@ func Silver_2_coin() (missKey []string) {
                        return true
                })
 
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/pay/v1/Exchange/silver2coin`,
                        PostStr:url.PathEscape(post_str),
                        Header:map[string]string{
@@ -2077,7 +2087,7 @@ func Silver_2_coin() (missKey []string) {
                                `Cache-Control`: `no-cache`,
                                `Content-Type`: `application/x-www-form-urlencoded`,
                                `Referer`:`https://link.bilibili.com/p/center/index`,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -2109,7 +2119,7 @@ func Silver_2_coin() (missKey []string) {
 }
 
 func save_cookie(Cookies []*http.Cookie){
-       for k,v := range p.Cookies_List_2_Map(Cookies){
+       for k,v := range reqf.Cookies_List_2_Map(Cookies){
                c.Cookie.Store(k, v)
        }
 
@@ -2118,7 +2128,7 @@ func save_cookie(Cookies []*http.Cookie){
                Cookie[k.(string)] = v.(string)
                return true
        })
-       CookieSet([]byte(p.Map_2_Cookies_String(Cookie)))
+       CookieSet([]byte(reqf.Map_2_Cookies_String(Cookie)))
 }
 
 //正在直播主播
@@ -2146,9 +2156,9 @@ func Feed_list() (Uplist []UpItem) {
                return true
        })
 
-       req := p.Req()
+       req := reqf.Req()
        for pageNum:=1; true; pageNum+=1 {
-               if err := req.Reqf(p.Rval{
+               if err := req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/relation/v1/feed/feed_list?page=`+strconv.Itoa(pageNum)+`&pagesize=10`,
                        Header:map[string]string{
                                `Host`: `api.live.bilibili.com`,
@@ -2161,7 +2171,7 @@ func Feed_list() (Uplist []UpItem) {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:`https://t.bilibili.com/pages/nav/index_new`,
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                        Timeout:3,
                        Retry:2,
@@ -2206,8 +2216,8 @@ func GetHistory(Roomid_int int) (j J.GetHistory) {
        Roomid := strconv.Itoa(Roomid_int)
 
        {//使用其他api
-               req := p.Req()
-               if err := req.Reqf(p.Rval{
+               req := reqf.Req()
+               if err := req.Reqf(reqf.Rval{
                        Url:"https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid=" + Roomid,
                        Header:map[string]string{
                                `Referer`:"https://live.bilibili.com/" + Roomid,
index e3ea50edbf5f94e9e2e8ee7537717c22140e504f..e83456ae782e1f621ea6ccea1001f68d8a8bc271 100644 (file)
@@ -5,12 +5,16 @@ import (
        "strconv"
        "encoding/json"
     "time"
-       "github.com/skratchdot/open-golang/open"
+
+       c "github.com/qydysky/bili_danmu/CV"
+
+       p "github.com/qydysky/part"
        websocket "github.com/qydysky/part/websocket"
        msgq "github.com/qydysky/part/msgq"
        web "github.com/qydysky/part/web"
-       p "github.com/qydysky/part"
-       c "github.com/qydysky/bili_danmu/CV"
+       reqf "github.com/qydysky/part/reqf"
+
+       "github.com/skratchdot/open-golang/open"
 )
 
 /*
@@ -128,7 +132,7 @@ func server() {
        })
        webpath = `http://`+w.Server.Addr
        //提示
-       wslog.L(`I: `,`如需加密,会自动打开`,webpath)
+       wslog.L(`I: `,`使用WebJs`,webpath,`进行加密`)
 }
 
 func Wasm(maxloop int, uid uintptr,s RT) (o string) {//maxloop 超时重试
@@ -136,8 +140,8 @@ func Wasm(maxloop int, uid uintptr,s RT) (o string) {//maxloop 超时重试
 
        {//nodejs
                if nodeJsUrl != "" {
-                       req := p.Req()
-                       if err := req.Reqf(p.Rval{
+                       req := reqf.Req()
+                       if err := req.Reqf(reqf.Rval{
                                Header:map[string]string{
                                        `Content-Type`: `application/json`,
                                },
index d00b6b84b465db207e9b5bef0ed6804a3c2a0efa..dbe7a36a2e11b63d1a210cd12b0f8dbde15923fb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -35,6 +35,7 @@ golang go version go1.15 linux/amd64
 - [github.com/gofrs/uuid](https://github.com/gofrs/uuid) under [MIT](https://github.com/gofrs/uuid/blob/master/LICENSE)
 - [github.com/skratchdot/open-golang/open](https://github.com/skratchdot/open-golang) under [MIT](https://raw.githubusercontent.com/skratchdot/open-golang/master/LICENSE)
 - [7z](https://www.7-zip.org/) under [LICENSE](https://www.7-zip.org/license.txt)
+- [github.com/mdp/qrterminal/v3](github.com/mdp/qrterminal/v3) under [MIT](https://github.com/mdp/qrterminal/blob/master/LICENSE)
 ---
 
 ### 当前支持显示/功能
@@ -68,7 +69,7 @@ golang go version go1.15 linux/amd64
 - [x] 每日有粉丝牌获取小心心
 - [x] 自定义私信
 - [x] 自动切换粉丝牌
-- [x] 扫码登录
+- [x] 扫码登录(qrcode in webServer and cmd)
 - [x] 自定义语音提醒
 - [x] GTK弹幕窗
 - [x] GTK信息窗
index 2b1cc3124c3e71d6ba661191851db4bebf4db7d7..d6d352168d7affd448f52ca2cb2607b92454e2a3 100644 (file)
@@ -13,12 +13,15 @@ import (
        c "github.com/qydysky/bili_danmu/CV"
        F "github.com/qydysky/bili_danmu/F"
        send "github.com/qydysky/bili_danmu/Send"
-       "github.com/christopher-dG/go-obs-websocket"
+       
        p "github.com/qydysky/part"
        funcCtrl "github.com/qydysky/part/funcCtrl"
        msgq "github.com/qydysky/part/msgq"
+       reqf "github.com/qydysky/part/reqf"
        b "github.com/qydysky/part/buf"
        s "github.com/qydysky/part/signal"
+
+       "github.com/christopher-dG/go-obs-websocket"
 )
 
 /*
@@ -271,7 +274,7 @@ func Saveflvf(){
                saveflv.wait = s.Init()
                saveflv.cancel = s.Init()
                
-               rr := p.Req()
+               rr := reqf.Req()
                go func(){
                        saveflv.cancel.Wait()
                        rr.Close()
@@ -286,12 +289,12 @@ func Saveflvf(){
 
                {//重试
                        l.L(`I: `,"尝试连接live")
-                       if e := rr.Reqf(p.Rval{
+                       if e := rr.Reqf(reqf.Rval{
                                Url:c.Live[cuLinkIndex],
                                Retry:10,
                                SleepTime:5,
                                Header:map[string]string{
-                                       `Cookie`:p.Map_2_Cookies_String(CookieM),
+                                       `Cookie`:reqf.Map_2_Cookies_String(CookieM),
                                },
                                Timeout:5,
                                JustResponseCode:true,
@@ -311,12 +314,12 @@ func Saveflvf(){
                Ass_f(saveflv.path, time.Now())
                l.L(`I: `,"保存到", saveflv.path + ".flv")
 
-               if e := rr.Reqf(p.Rval{
+               if e := rr.Reqf(reqf.Rval{
                        Url:c.Live[cuLinkIndex],
                        Retry:10,
                        SleepTime:5,
                        Header:map[string]string{
-                               `Cookie`:p.Map_2_Cookies_String(CookieM),
+                               `Cookie`:reqf.Map_2_Cookies_String(CookieM),
                        },
                        SaveToPath:saveflv.path + ".flv",
                        Timeout:-1,
index 7784d82b3b32e5db8dc000702f04ad5c23451a4f..26da5d717c36235614fa2b83819953a580bcd903 100644 (file)
@@ -13,14 +13,17 @@ import (
        "sync"
        "runtime"
 
-       "github.com/gotk3/gotk3/glib"
-       "github.com/gotk3/gotk3/gtk"
-       "github.com/gotk3/gotk3/gdk"
-       p "github.com/qydysky/part"
-       msgq "github.com/qydysky/part/msgq"
        F "github.com/qydysky/bili_danmu/F"
        c "github.com/qydysky/bili_danmu/CV"
+
+       p "github.com/qydysky/part"
+       msgq "github.com/qydysky/part/msgq"
        s "github.com/qydysky/part/buf"
+       reqf "github.com/qydysky/part/reqf"
+
+       "github.com/gotk3/gotk3/glib"
+       "github.com/gotk3/gotk3/gtk"
+       "github.com/gotk3/gotk3/gdk"
 )
 
 type danmu_item struct {
@@ -468,8 +471,8 @@ func Gtk_danmu() {
                                        if p.Checkfile().IsExist(Gtk_img_path + `/` + uid) {return}
                                        src := F.Get_face_src(uid)
                                        if src == "" {return}
-                                       req := p.Req()
-                                       if e := req.Reqf(p.Rval{
+                                       req := reqf.Req()
+                                       if e := req.Reqf(reqf.Rval{
                                                Url:src,
                                                SaveToPath:Gtk_img_path + `/` + uid,
                                                Timeout:3,
index f1ee2b892af2eeaba2a298796bc114849d27a732..3cd253d03ce5fddc3ddcf6e261c21f42d4e573b0 100644 (file)
@@ -4,10 +4,12 @@ import (
        "os/exec"
        "net/url"
        "strings"
-       p "github.com/qydysky/part"
        c "github.com/qydysky/bili_danmu/CV"
+
+       p "github.com/qydysky/part"
        msgq "github.com/qydysky/part/msgq"
        s "github.com/qydysky/part/buf"
+       reqf "github.com/qydysky/part/reqf"
 )
 
 var tts_setting = map[string]string{
@@ -83,8 +85,8 @@ func TTS(uid,msg string) {
 
        msg = strings.ReplaceAll(v, "{D}", msg)
 
-       req := p.Req()
-       if err := req.Reqf(p.Rval{
+       req := reqf.Req()
+       if err := req.Reqf(reqf.Rval{
                Url:`https://fanyi.baidu.com/gettts?lan=zh&text=`+ url.QueryEscape(msg) +`&spd=5&source=web`,
                SaveToPath:p.Sys().Cdir()+`/tts.mp3`,
                Timeout:3,
index 1dc4d09f9a494798065a00e4b4a7ff3ad9f2725b..dd9d760bdddbbe5f79d4e7ef7e84fdcc61c245f9 100644 (file)
@@ -6,7 +6,9 @@ import (
        "net/url"
 
        c "github.com/qydysky/bili_danmu/CV"
+
        p "github.com/qydysky/part"
+       reqf "github.com/qydysky/part/reqf"
 )
 
 //每5s一个令牌,最多等20秒
@@ -35,8 +37,8 @@ func Danmu_s(msg string, roomid int) {
 
        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
        l.L(`I: `,"发送", msg, "至", roomid)
-       r := p.Req()
-       err := r.Reqf(p.Rval{
+       r := reqf.Req()
+       err := r.Reqf(reqf.Rval{
                Url:"https://api.live.bilibili.com/msg/send",
                PostStr:url.PathEscape(PostStr),
                Retry:2,
@@ -53,7 +55,7 @@ func Danmu_s(msg string, roomid int) {
                        `Pragma`: `no-cache`,
                        `Cache-Control`: `no-cache`,
                        `Referer`:"https://live.bilibili.com/" + strconv.Itoa(roomid),
-                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                },
        })
        if err != nil {
index 4e68b53d347d86caa5d05a69a4df8c9872e94ccb..338f0e83baf6578622da660fa8658c6c791a70d3 100644 (file)
@@ -6,8 +6,10 @@ import (
        "encoding/json"
        "strconv"
 
-       p "github.com/qydysky/part"
        c "github.com/qydysky/bili_danmu/CV"
+
+       p "github.com/qydysky/part"
+       reqf "github.com/qydysky/part/reqf"
 )
 
 //每2s一个令牌,最多等10秒
@@ -48,8 +50,8 @@ func Send_gift(gift_id,bag_id,gift_num int) {
                        return true
                })
                
-               req := p.Req()
-               if e:= req.Reqf(p.Rval{
+               req := reqf.Req()
+               if e:= req.Reqf(reqf.Rval{
                        Url:`https://api.live.bilibili.com/gift/v2/live/bag_send`,
                        PostStr:url.PathEscape(sendStr),
                        Timeout:10,
@@ -65,7 +67,7 @@ func Send_gift(gift_id,bag_id,gift_num int) {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:"https://message.bilibili.com",
-                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                        },
                });e != nil {
                        log.L(`E: `,e)
index 94ba14a882a0be27c75fa62fac676b5193d96e5d..eca5e8150aeb614d964581f6d0132b79e5ff11e2 100644 (file)
@@ -5,8 +5,11 @@ import (
        "errors"
        "strings"
        "strconv"
-       p "github.com/qydysky/part"
        c "github.com/qydysky/bili_danmu/CV"
+
+       p "github.com/qydysky/part"
+       reqf "github.com/qydysky/part/reqf"
+
        uuid "github.com/gofrs/uuid"
 )
 
@@ -56,8 +59,8 @@ func Send_pm(uid int, msg string) error {
                return true
        })
        
-       req := p.Req()
-       if e:= req.Reqf(p.Rval{
+       req := reqf.Req()
+       if e:= req.Reqf(reqf.Rval{
                Url:`https://api.vc.bilibili.com/web_im/v1/web_im/send_msg`,
                PostStr:url.PathEscape(send_str),
                Timeout:10,
@@ -73,7 +76,7 @@ func Send_pm(uid int, msg string) error {
                        `Pragma`: `no-cache`,
                        `Cache-Control`: `no-cache`,
                        `Referer`:"https://message.bilibili.com",
-                       `Cookie`:p.Map_2_Cookies_String(Cookie),
+                       `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                },
        });e != nil {
                log.L(`E: `,e)
index d3c4015724c089922458297c277e9e5e3f435a31..a8bb11c23adb73ce95d44c051004e003f78a873a 100644 (file)
@@ -8,14 +8,16 @@ import (
        "strconv"
        "os"
        "os/signal"
-
-       p "github.com/qydysky/part"
-       ws "github.com/qydysky/part/websocket"
-       msgq "github.com/qydysky/part/msgq"
+               
        reply "github.com/qydysky/bili_danmu/Reply"
        send "github.com/qydysky/bili_danmu/Send"
        c "github.com/qydysky/bili_danmu/CV"
        F "github.com/qydysky/bili_danmu/F"
+       
+       p "github.com/qydysky/part"
+       ws "github.com/qydysky/part/websocket"
+       msgq "github.com/qydysky/part/msgq"
+       reqf "github.com/qydysky/part/reqf"
 )
 
 func init() {
@@ -108,9 +110,6 @@ func Demo(roomid ...int) {
 
                <-change_room_chan
 
-               //ctrl+c退出
-               signal.Notify(interrupt, os.Interrupt)
-
                //获取cookie
                F.Get(`Cookie`)
                //获取uid
@@ -127,7 +126,10 @@ func Demo(roomid ...int) {
                go reply.Keep_medal_light()
                //附加功能 自动发送即将过期礼物
                go reply.AutoSend_silver_gift()
-               
+
+               //捕获ctrl+c退出
+               signal.Notify(interrupt, os.Interrupt)
+
                var exit_sign = 2
                for exit_sign > 0 {
                        exit_sign -= 1
@@ -166,7 +168,7 @@ func Demo(roomid ...int) {
                                        Func_abort_close:func(){danmulog.L(`I: `,`服务器连接中断`)},
                                        Func_normal_close:func(){danmulog.L(`I: `,`服务器连接关闭`)},
                                        Header: map[string]string{
-                                               `Cookie`:p.Map_2_Cookies_String(Cookie),
+                                               `Cookie`:reqf.Map_2_Cookies_String(Cookie),
                                                `Host`: u.Hostname(),
                                                `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`,
                                                `Accept`: `*/*`,
index 4a206811664a92b28886d72f9ba3065b6aacf5ae..accf0a9bfa413f23ca928eaa8c0b34f72441c7a7 100644 (file)
@@ -66,5 +66,5 @@
     "cookie解密私钥": "private.pem",
     "扫码登录-help": "当扫码登陆设置为true时,每次启动会检查,若失败则会要求登录",
     "扫码登录": true,
-    "扫码登录自动打开标签页": true
+    "扫码登录自动打开标签页": false
 }
\ No newline at end of file
index 271fc98c095f410eabbffc7087ebe09cb3022236..73f53b373ac7d297aa66f50f97ae212aab656a3b 100644 (file)
@@ -9,10 +9,11 @@ require (
        github.com/gorilla/websocket v1.4.2 // indirect
        github.com/gotk3/gotk3 v0.5.2 // indirect
        github.com/klauspost/compress v1.11.13 // indirect
+       github.com/mdp/qrterminal/v3 v3.0.0 // indirect
        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.3 // indirect
+       github.com/qydysky/part v0.5.4 // 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 854fe8376ba529cc116b3686b33affd0b9d51511..75ecaea1bd1883ecca0f216347d6091d72d284ff 100644 (file)
@@ -110,6 +110,12 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
 github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
+github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
+github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
+github.com/mdp/qrterminal v1.0.1 h1:07+fzVDlPuBlXS8tB0ktTAyf+Lp1j2+2zK3fBOL5b7c=
+github.com/mdp/qrterminal v1.0.1/go.mod h1:Z33WhxQe9B6CdW37HaVqcRKzP+kByF3q/qLxOGe12xQ=
+github.com/mdp/qrterminal/v3 v3.0.0 h1:ywQqLRBXWTktytQNDKFjhAvoGkLVN3J2tAFZ0kMd9xQ=
+github.com/mdp/qrterminal/v3 v3.0.0/go.mod h1:NJpfAs7OAm77Dy8EkWrtE4aq+cE6McoLXlBqXQEwvE0=
 github.com/miekg/dns v1.1.31 h1:sJFOl9BgwbYAWOGEwr61FU28pqsBNdpRBnhGXtO06Oo=
 github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
 github.com/miekg/dns v1.1.35 h1:oTfOaDH+mZkdcgdIjH6yBajRGtIwcwcaR+rt23ZSrJs=
@@ -249,6 +255,8 @@ github.com/qydysky/part v0.5.1 h1:ocgxbSduBcIVjfRV8PL0E7mj+aSJxRoSLNzKWwiz6MA=
 github.com/qydysky/part v0.5.1/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
 github.com/qydysky/part v0.5.3 h1:bvNvXOdzZr0nd3p+VQDgvGzugwuvk+yNtO6oTD32trw=
 github.com/qydysky/part v0.5.3/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
+github.com/qydysky/part v0.5.4 h1:o7nslWdOM94wGEGGPWK0uscx8NR3UlJpnKTQCQxBPfQ=
+github.com/qydysky/part v0.5.4/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=
@@ -357,6 +365,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -452,6 +461,8 @@ k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8
 k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
 k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
 k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM=
+rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
+rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=
 sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
 sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
 sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=