]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
进入房间api
authorqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 17 Jan 2023 15:13:20 +0000 (23:13 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 17 Jan 2023 15:13:20 +0000 (23:13 +0800)
F/api.go
Json/roomEntryAction.go [new file with mode: 0644]
bili_danmu.go

index 904cfe058b704c950f34c2e5122bdf77cb2e2d17..6a57c22487ba9845dba4b8d4fdc5ae8e298ca386 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -3,6 +3,7 @@ package F
 import (
        "context"
        "encoding/json"
+       "fmt"
        "net/http"
        "net/url"
        "os"
@@ -2309,6 +2310,76 @@ func GetHisStream() (Uplist []UpItem) {
        return
 }
 
+// 进入房间
+func RoomEntryAction(roomId int) {
+       apilog := apilog.Base_add(`进入房间`)
+       //验证cookie
+       if missKey := CookieCheck([]string{
+               `bili_jct`,
+               `DedeUserID`,
+               `LIVE_BUVID`,
+       }); len(missKey) != 0 {
+               apilog.L(`T: `, `Cookie无Key:`, missKey)
+               return
+       }
+       if api_limit.TO() {
+               apilog.L(`E: `, `超时!`)
+               return
+       } //超额请求阻塞,超时将取消
+
+       Cookie := make(map[string]string)
+       c.C.Cookie.Range(func(k, v interface{}) bool {
+               Cookie[k.(string)] = v.(string)
+               return true
+       })
+
+       csrf := Cookie[`bili_jct`]
+       if csrf == `` {
+               apilog.L(`E: `, "Cookie错误,无bili_jct=")
+               return
+       }
+
+       reqi := c.C.ReqPool.Get()
+       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/index/roomEntryAction`,
+               PostStr: fmt.Sprintf("room_id=%d&platform=pc&csrf_token=%s&csrf=%s&visit_id=", roomId, csrf, csrf),
+               Header: map[string]string{
+                       `Host`:            `api.live.bilibili.com`,
+                       `User-Agent`:      `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`,
+                       `Accept`:          `application/json, text/plain, */*`,
+                       `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
+                       `Accept-Encoding`: `gzip, deflate, br`,
+                       `Origin`:          `https://live.bilibili.com`,
+                       `Connection`:      `keep-alive`,
+                       `Pragma`:          `no-cache`,
+                       `Cache-Control`:   `no-cache`,
+                       `Referer`:         fmt.Sprintf("https://live.bilibili.com/%d", roomId),
+                       `Cookie`:          reqf.Map_2_Cookies_String(Cookie),
+               },
+               Proxy:   c.C.Proxy,
+               Timeout: 3 * 1000,
+               Retry:   2,
+       }); err != nil {
+               apilog.L(`E: `, err)
+               return
+       }
+
+       var res J.RoomEntryAction
+
+       if e := json.Unmarshal(req.Respon, &res); e != nil {
+               apilog.L(`E: `, e)
+               return
+       }
+
+       if res.Code != 0 {
+               apilog.L(`E: `, res.Message)
+               return
+       }
+}
+
 func Feed_list() (Uplist []J.FollowingDataList) {
        apilog := apilog.Base_add(`正在直播主播`).L(`T: `, `获取中`)
        defer apilog.L(`T: `, `完成`)
diff --git a/Json/roomEntryAction.go b/Json/roomEntryAction.go
new file mode 100644 (file)
index 0000000..18386b6
--- /dev/null
@@ -0,0 +1,8 @@
+package part
+
+type RoomEntryAction struct {
+       Code    int         `json:"code"`
+       Message string      `json:"message"`
+       TTL     int         `json:"ttl"`
+       Data    interface{} `json:"data"`
+}
index 66868ace865c3629dcef9b8784fdd25e58af4cf9..76db64202fb9ab1546158d15e00834dc185be00a 100644 (file)
@@ -89,7 +89,7 @@ func Start() {
                // 房间初始化
                if c.C.Roomid == 0 {
                        c.C.Log.Block(1000) //等待所有日志输出完毕
-                       fmt.Println("输入房间号或` live`获取正在直播的主播")
+                       fmt.Println("回车查看指令")
                } else {
                        fmt.Print("房间号: ", strconv.Itoa(c.C.Roomid), "\n")
                        go func() { change_room_chan <- struct{}{} }()
@@ -290,6 +290,7 @@ func Start() {
                                                                IsRec:  true,
                                                        })
                                                        go reply.ShowRevf()
+                                                       go F.RoomEntryAction(c.C.Roomid)
                                                }
                                        }()
                                }