]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
如有cookie则使用
authorqydysky <qydysky@foxmail.com>
Tue, 22 Dec 2020 08:02:01 +0000 (16:02 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 22 Dec 2020 08:02:01 +0000 (16:02 +0800)
CV/Const.go
CV/Var.go
F/api.go
bili_danmu.go
demo/go.mod
demo/go.sum

index 3d962410d9429c525986e26ce6031066c81331cd..3aab07232964167383de3a3b4b894d501585ada7 100644 (file)
@@ -31,7 +31,6 @@ const (
        customAuthParam
 */
 const (
-       Uid = 0
        Protover = 2
        Platform = "web"
        Type = 2
index aef157dc7a6ec0c8d5f0fee2602005b9f893542e..7985468b9fb3b0ecfca63a1db849fb4d2ad6190b 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -7,6 +7,8 @@ import (
 
 
 var (
+       Uid = 0//client uid
+
        Live []string//直播链接
        Live_qn string
        Roomid int
index 8d54e060f4961a32596a1304ffdc36c22796f82a..e186ab6755cdbd568b30e7689e4887d8a5e1d773 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -94,6 +94,7 @@ func (i *api) Get_info() (o *api) {
                        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,
+                               `Cookie`:c.Cookie,
                        },
                        Timeout:10,
                        Retry:2,
@@ -336,6 +337,7 @@ func (i *api) Get_host_Token() (o *api) {
                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`:c.Cookie,
                },
                Timeout:10,
                Retry:2,
@@ -383,6 +385,7 @@ func Get_face_src(uid string) (string) {
                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`:c.Cookie,
                },
                Timeout:10,
                Retry:2,
@@ -431,6 +434,7 @@ func (i *api) Get_OnlineGoldRank() {
                                `Pragma`: `no-cache`,
                                `Cache-Control`: `no-cache`,
                                `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
+                               `Cookie`:c.Cookie,
                        },
                        Timeout:3,
                        Retry:2,
@@ -511,6 +515,7 @@ func (i *api) Get_guardNum() {
                        `Pragma`: `no-cache`,
                        `Cache-Control`: `no-cache`,
                        `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
+                       `Cookie`:c.Cookie,
                },
                Timeout:3,
                Retry:2,
@@ -623,6 +628,10 @@ func (i *api) Get_cookie() {
        }
        var server *http.Server
        {//生成二维码
+               if p.Checkfile().IsExist(`qr.png`) {
+                       apilog.Base(1,`Get_cookie`).E(`qr.png已存在`)
+                       return
+               }
                qr.WriteFile(img_url,qr.Medium,256,`qr.png`)
                if !p.Checkfile().IsExist(`qr.png`) {
                        apilog.Base(1,`Get_cookie`).E(`qr error`)
@@ -658,6 +667,7 @@ func (i *api) Get_cookie() {
                                Header:map[string]string{
                                        `Content-Type`:`application/x-www-form-urlencoded; charset=UTF-8`,
                                        `Referer`: `https://passport.bilibili.com/login`,
+                                       `Cookie`:c.Cookie,
                                },
                                Timeout:10,
                                Retry:2,        
index 4ebe486ba76e3cbf8e6b6de237aa94f5c13ffd7d..cecabd54ae0637c3dd736c8a61b05fbb8c5301e9 100644 (file)
@@ -4,12 +4,14 @@ import (
        "fmt"
        "flag"
        "time"
+       "net/url"
        "strconv"
        "os"
        "os/signal"
 
        p "github.com/qydysky/part"
        ws "github.com/qydysky/part/websocket"
+       g "github.com/qydysky/part/get"
        reply "github.com/qydysky/bili_danmu/Reply"
        c "github.com/qydysky/bili_danmu/CV"
        F "github.com/qydysky/bili_danmu/F"
@@ -93,10 +95,6 @@ func Demo(roomid ...int) {
                <-change_room_chan
 
                for !exit_sign {
-                       //获取房间相关信息
-                       api := F.New_api(c.Roomid).Get_host_Token().Get_live()
-                       c.Roomid = api.Roomid
-
                        //获取cookies
                        {
                                var q = p.Filel{
@@ -106,10 +104,15 @@ func Demo(roomid ...int) {
                                        q.File = "cookie.txt"
                                        f := p.File().FileWR(q)
                                        c.Cookie = f
+                                       if tmp_uid,e := g.SS(f,`DedeUserID=`,`;`,0,0);e == nil {
+                                               if v,e := strconv.Atoi(tmp_uid);e == nil {
+                                                       c.Uid = v
+                                               } else {danmulog.E(e)}
+                                       } else {danmulog.E(e)}
                                } else {
                                        danmulog.I("未检测到cookie.txt,如果需要登录请在本机打开以下网址扫码登录,不需要请忽略")
                                        go func(){//获取cookie
-                                               api.Get_cookie()
+                                               F.New_api(c.Roomid).Get_cookie()
                                                if c.Cookie != `` {
                                                        danmulog.I("你已登录,刷新房间!")
                                                        c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//刷新
@@ -120,6 +123,11 @@ func Demo(roomid ...int) {
                                        p.Sys().Timeoutf(3)
                                }
                        }
+                       
+                       //获取房间相关信息
+                       api := F.New_api(c.Roomid).Get_host_Token().Get_live()
+                       c.Roomid = api.Roomid
+
                        //获取用户版本
                        api.Get_Version()
                        //切换粉丝牌,只在cookie存在时启用
@@ -133,13 +141,21 @@ func Demo(roomid ...int) {
                        //对每个弹幕服务器尝试
                        for _, v := range api.Url {
                                //ws启动
+                               u, _ := url.Parse(v)
                                ws_c := ws.New_client(ws.Client{
                                        Url:v,
                                        TO:35 * 1000,
                                        Func_abort_close:func(){danmulog.I(`服务器连接中断`)},
                                        Func_normal_close:func(){danmulog.I(`服务器连接关闭`)},
-                                       Header:map[string][]string{
-                                               "Cookie":[]string{c.Cookie},
+                                       Header: map[string]string{
+                                               `Cookie`:c.Cookie,
+                                               `Host`: u.Hostname(),
+                                               `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`,
+                                               `Accept`: `*/*`,
+                                               `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`,
+                                               `Origin`: `https://live.bilibili.com`,
+                                               `Pragma`: `no-cache`,
+                                               `Cache-Control`: `no-cache`,
                                        },
                                }).Handle()
                                if ws_c.Isclose() {
index 87b8c290df8dea5a99d5497935388aa472aab6a6..cdfab1e7ad8f954af4c000f91782b2173d78ec9d 100644 (file)
@@ -10,7 +10,7 @@ require (
        github.com/miekg/dns v1.1.35 // indirect
        github.com/mitchellh/mapstructure v1.4.0 // indirect
        github.com/qydysky/bili_danmu v0.5.4
-       github.com/qydysky/part v0.3.5-0.20201222061900-d0c0ca9fc246 // indirect
+       github.com/qydysky/part v0.3.5-0.20201222075205-70243aca6682 // indirect
        github.com/shirou/gopsutil v3.20.11+incompatible // indirect
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
        golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 // indirect
index ca774b5024fb6923ed6ca6e30c16164c92cd5783..177144ca4baeb16a43c9ed2ec382728183a0f8f1 100644 (file)
@@ -76,6 +76,8 @@ github.com/qydysky/part v0.3.4 h1:LddQ0WfEAZ5Wyi8L+x6BA4hOsZV7YN01gzEhQNy/64M=
 github.com/qydysky/part v0.3.4/go.mod h1:93s9ohLtzULet5ZPEUUWrT9BELC30oDZgRpgGSiDye4=
 github.com/qydysky/part v0.3.5-0.20201222061900-d0c0ca9fc246 h1:MDhL/WQ4fGNjLWncGThw5JpI6AbxCvpiVIASOFIM464=
 github.com/qydysky/part v0.3.5-0.20201222061900-d0c0ca9fc246/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
+github.com/qydysky/part v0.3.5-0.20201222075205-70243aca6682 h1:k7YM2PUXxW96cIAludM1zJ4c9Ru6/W5jxJ67HrUht3w=
+github.com/qydysky/part v0.3.5-0.20201222075205-70243aca6682/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
 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=