]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix 未登录搜索主播失败
authorqydysky <qydysky@foxmail.com>
Thu, 27 Apr 2023 02:14:17 +0000 (02:14 +0000)
committerGitHub <noreply@github.com>
Thu, 27 Apr 2023 02:14:17 +0000 (02:14 +0000)
F/api.go
cmd/cmd.go

index 8a9e1b1115839afe7f1b7e94f773eb5101b0cb2b..920c89ab117c3ce2a74f11ab9b8a82724433e142 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -1254,6 +1254,8 @@ func (c *GetFunc) GetNav() (J.Nav, error) {
 // 扫码登录
 func (c *GetFunc) Get_cookie() (missKey []string) {
        apilog := apilog.Base_add(`获取Cookie`)
+       //获取其他Cookie
+       defer c.Get_other_cookie()
 
        if p.Checkfile().IsExist("cookie.txt") { //读取cookie文件
                if cookieString := string(CookieGet()); cookieString != `` {
@@ -1267,9 +1269,6 @@ func (c *GetFunc) Get_cookie() (missKey []string) {
                                if v, e := c.GetNav(); e != nil {
                                        apilog.L(`E: `, e)
                                } else if v.Data.IsLogin {
-                                       //获取其他Cookie
-                                       c.Get_other_cookie()
-
                                        apilog.L(`I: `, `已登录`)
                                        return
                                }
@@ -1365,7 +1364,7 @@ func (c *GetFunc) Get_cookie() (missKey []string) {
                        BlackChar: `  `,
                        WhiteChar: `OO`,
                })
-               apilog.L(`W: `, `手机扫命令行二维码登录`)
+               apilog.L(`W: `, `手机扫命令行二维码登录。如不登录,修改配置文件"扫码登录"为false`)
                time.Sleep(time.Second)
        }
 
@@ -1427,9 +1426,6 @@ func (c *GetFunc) Get_cookie() (missKey []string) {
                                if e := save_cookie(r.Response.Cookies()); e != nil {
                                        apilog.L(`E: `, e)
                                }
-
-                               //获取其他Cookie
-                               c.Get_other_cookie()
                                break
                        }
                }
@@ -2499,7 +2495,7 @@ type searchresult struct {
        Is_live bool
 }
 
-func SearchUP(s string) (list []searchresult) {
+func (c *GetFunc) SearchUP(s string) (list []searchresult) {
        apilog := apilog.Base_add(`搜索主播`)
        if api_limit.TO() {
                apilog.L(`E: `, `超时!`)
@@ -2507,18 +2503,30 @@ func SearchUP(s string) (list []searchresult) {
        } //超额请求阻塞,超时将取消
 
        { //使用其他api
-               req := c.C.ReqPool.Get()
-               defer c.C.ReqPool.Put(req)
+               req := c.ReqPool.Get()
+               defer c.ReqPool.Put(req)
 
                Cookie := make(map[string]string)
-               c.C.Cookie.Range(func(k, v interface{}) bool {
+               c.Cookie.Range(func(k, v interface{}) bool {
                        Cookie[k.(string)] = v.(string)
                        return true
                })
 
+               query := "page=1&page_size=10&order=online&platform=pc&search_type=live_user&keyword=" + url.PathEscape(s)
+               // wbi
+               {
+                       v, e := c.GetNav()
+                       if e != nil {
+                               apilog.L(`E: `, e)
+                               return
+                       }
+                       wrid, wts := c.getWridWts(query, v.Data.WbiImg.ImgURL, v.Data.WbiImg.SubURL)
+                       query += "&w_rid=" + wrid + "&wts=" + wts
+               }
+
                if err := req.Reqf(reqf.Rval{
-                       Url:   "https://api.bilibili.com/x/web-interface/wbi/search/type?page=1&page_size=10&order=online&platform=pc&search_type=live_user&keyword=" + url.PathEscape(s),
-                       Proxy: c.C.Proxy,
+                       Url:   "https://api.bilibili.com/x/web-interface/wbi/search/type?" + query,
+                       Proxy: c.Proxy,
                        Header: map[string]string{
                                `Cookie`: reqf.Map_2_Cookies_String(Cookie),
                        },
index cd393b85d2f4c68f0c7d23ce85c0b3f61960c1dc..38ecf8bd457c10e4172ccf7d1567088eded3b1cd 100644 (file)
@@ -144,7 +144,7 @@ func Cmd() {
                                }
 
                                fmt.Print("\n")
-                               for k, v := range F.SearchUP(inputs[4:]) {
+                               for k, v := range F.Get(c.C).SearchUP(inputs[4:]) {
                                        liveList[` to`+strconv.Itoa(k)] = v.Roomid
                                        if v.Is_live {
                                                fmt.Printf("%d\t%s\t%s(%d)\n", k, `☁`, v.Uname, v.Roomid)