]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
cookie提供者使用原画
authorqydysky <qydysky@foxmail.com>
Sat, 10 Oct 2020 00:14:39 +0000 (08:14 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 10 Oct 2020 00:14:39 +0000 (08:14 +0800)
CV/Var.go
F/api.go
Reply/F.go
_msg_sample/DANMU_MSG.json [new file with mode: 0644]
demo/go.mod
demo/go.sum

index c493bf0b9e1684c3b97a9e73c822ece54f340e27..11196e8edd8b00a62b221bce1a124bdf4cff9aba 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -1,7 +1,7 @@
 package cv
  
 var (
-       Live string//直播链接
+       Live []string//直播链接
        Roomid int
        Cookie string
        Title string
index 4031022665e56dc01c4df65b9efc27e7d29537e5..2663d71e158407244cc400d8d2d3aa9528d6f10f 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -12,7 +12,7 @@ type api struct {
        Roomid int
        Uid int
        Url []string
-       Live string
+       Live []string
        Live_status float64
        Locked bool
        Token string
@@ -116,7 +116,7 @@ func (i *api) Get_info() (o *api) {
        return
 }
 
-func (i *api) Get_live() (o *api) {
+func (i *api) Get_live(qn ...int) (o *api) {
        o = i
        if o.Roomid == 0 {
                apilog.E("还未New_api")
@@ -130,18 +130,22 @@ func (i *api) Get_live() (o *api) {
                } else {
                        Cookie = Cookie[:i] + Cookie[i + d + 1:]
                }
+       } else {
+               qn = []int{}
        }
 
-       {//html获取
+       if len(qn) == 0 || qn[0] == 0 {//html获取
                r := p.Get(p.Rval{
                        Url:"https://live.bilibili.com/" + strconv.Itoa(o.Roomid),
                        Cookie:Cookie,
                })
                if e := r.S(`"durl":[`, `]`, 0, 0).Err;e == nil {
-                       if url := p.Json().GetValFromS("[" + r.RS + "]", "[0].url");url != nil {
+                       if urls := p.Json().GetArrayFrom("[" + r.RS + "]", "url");urls != nil {
                                apilog.W("直播中")
                                o.Live_status = 1
-                               o.Live = url.(string)
+                               for _,v := range urls {
+                                       o.Live = append(o.Live, v.(string))
+                               }
                                return
                        }
                }
@@ -150,7 +154,7 @@ func (i *api) Get_live() (o *api) {
                }
                apilog.W("api version", c.VERSION)
        }
-       {//api获取
+       {//api获取https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid=4895312&qn=400&platform=web&https_url_req=1&ptype=16
                req := p.Req()
                if err := req.Reqf(p.Rval{
                        Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomPlayInfo?play_url=1&mask=1&qn=0&platform=web&ptype=16&room_id=" + strconv.Itoa(o.Roomid),
@@ -163,7 +167,7 @@ func (i *api) Get_live() (o *api) {
                        return
                }
                res := string(req.Respon)
-               if code := p.Json().GetValFrom(res, "code");code == nil || code.(float64) != 0 {
+               if code := p.Json().GetValFromS(res, "code");code == nil || code.(float64) != 0 {
                        apilog.E("code", code)
                        return
                }
@@ -193,13 +197,37 @@ func (i *api) Get_live() (o *api) {
                                apilog.W("live_status:", live_status)
                        }
                }
-
-               if url := p.Json().GetValFrom(res, "data.play_url.durl.[0].url");url == nil {
-                       apilog.E("url", url)
+               if urls := p.Json().GetArrayFrom(p.Json().GetValFrom(res, "data.play_url.durl"), "url");urls == nil {
+                       apilog.E("url", urls)
                        return
                } else {
                        apilog.T("ok")
-                       o.Live = url.(string)
+                       for _,v := range urls {
+                               o.Live = append(o.Live, v.(string))
+                       }
+               }
+
+               if len(qn) != 0 && qn[0] != 0 {
+                       if err := req.Reqf(p.Rval{
+                               Url:"https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid=" + strconv.Itoa(o.Roomid) + "&qn=" + strconv.Itoa(qn[0]) + "&platform=web&https_url_req=1&ptype=16",
+                               Referer:"https://live.bilibili.com/" + strconv.Itoa(o.Roomid),
+                               Timeout:10,
+                               Cookie:Cookie,
+                               Retry:2,
+                       });err != nil {
+                               apilog.E(err)
+                               return
+                       }
+                       res = string(req.Respon)
+                       if urls := p.Json().GetArrayFrom(p.Json().GetValFrom(res, "data.durl"), "url");urls == nil {
+                               apilog.E("url", urls)
+                               return
+                       } else {
+                               apilog.T("ok")
+                               for _,v := range urls {
+                                       o.Live = append(o.Live, v.(string))
+                               }
+                       }
                }
        }
        return
index a2e460ca208066662b791daa85ca2a8d12119d81..c04c8b5a872c7625796c5184544ca84f092f1baf 100644 (file)
@@ -233,10 +233,20 @@ type Saveflv struct {
        path string
        wait p.Signal
        cancel p.Signal
+
+       qn int
 }
 
 var saveflv = Saveflv {
        Inuse:IsOn("Saveflv"),
+       qn:10000,
+       /*
+       10000 原画
+       400 蓝光
+       250 超清
+       150 高清
+       80 流畅
+       */
 }
 
 //已go func形式调用,将会获取直播流
@@ -247,7 +257,7 @@ func Saveflvf(){
        l := p.Logf().New().Open("danmu.log").Base(-1, "saveflv")
 
        api := F.New_api(c.Roomid)
-       for api.Get_live().Live_status == 1 {
+       for api.Get_live(saveflv.qn).Live_status == 1 {
                c.Live = api.Live
 
                saveflv.path = strconv.Itoa(c.Roomid) + "_" + time.Now().Format("2006_01_02_15:04:05.000")
@@ -275,7 +285,7 @@ func Saveflvf(){
                        retry := 20
                        for retry > 0 && rr.ResponseCode != 200 {
                                if e := rr.Reqf(p.Rval{
-                                       Url:c.Live,
+                                       Url:c.Live[0],
                                        Retry:10,
                                        SleepTime:5,
                                        Cookie:Cookie,
@@ -297,7 +307,7 @@ func Saveflvf(){
                l.I("保存到", saveflv.path + ".flv")
 
                if e := rr.Reqf(p.Rval{
-                       Url:c.Live,
+                       Url:c.Live[0],
                        Retry:10,
                        SleepTime:5,
                        Cookie:Cookie,
diff --git a/_msg_sample/DANMU_MSG.json b/_msg_sample/DANMU_MSG.json
new file mode 100644 (file)
index 0000000..9b80a06
--- /dev/null
@@ -0,0 +1,67 @@
+{
+    "cmd": "DANMU_MSG",
+    "info": [
+        [
+            0,
+            1,
+            25,
+            16777215,
+            1601981229550,
+            925883313,
+            0,
+            "7a317c96",
+            0,
+            0,
+            0,
+            ""
+        ],
+        "鬼也是玩家吗",
+        [
+            332143945,
+            "爱吃甜食的叱干巧曼",
+            0,
+            0,
+            0,
+            10000,
+            1,
+            ""
+        ],
+        [
+            7,
+            "猫良",
+            "数字猫",
+            3839755,
+            5805790,
+            "",
+            0,
+            5805790,
+            5805790,
+            5805790,
+            0,
+            1,
+            6009977
+        ],
+        [
+            7,
+            0,
+            9868950,
+            "\u003e50000"
+        ],
+        [
+            "",
+            ""
+        ],
+        0,
+        0,
+        null,
+        {
+            "ts": 1601981229,
+            "ct": "EE03F05F"
+        },
+        0,
+        0,
+        null,
+        null,
+        0
+    ]
+}
\ No newline at end of file
index a0114c2adaa5d8376ebe0c00ce3a178ce545789d..2380cfd93b6f2adaaa87ad171f8492cd8372c264 100644 (file)
@@ -8,7 +8,7 @@ require (
        github.com/klauspost/compress v1.11.1 // indirect
        github.com/mitchellh/mapstructure v1.3.3 // indirect
        github.com/qydysky/bili_danmu v0.0.0
-       github.com/qydysky/part v0.0.5 // indirect
+       github.com/qydysky/part v0.0.6 // indirect
        github.com/shirou/gopsutil v2.20.9+incompatible // indirect
        github.com/therecipe/env_darwin_amd64_513 v0.0.0-20190626001412-d8e92e8db4d0 // indirect
        github.com/therecipe/env_linux_amd64_513 v0.0.0-20190626000307-e137a3934da6 // indirect
index 8d5bab045a1d3f678cc0ad9c96ce889f789f7c37..e94dc1c62dc16b4b918a1a784b0d06f380ad0b8c 100644 (file)
@@ -80,6 +80,8 @@ github.com/qydysky/part v0.0.4 h1:MN1SXuP0korwTAFPG+hJmQHGFs9Aj7XBC4zAq6yEjsc=
 github.com/qydysky/part v0.0.4/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/qydysky/part v0.0.5 h1:sbkXXRpviLJ81rav5SfWo/vIq2c0tQDa6kvWTqXgEL0=
 github.com/qydysky/part v0.0.5/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
+github.com/qydysky/part v0.0.6 h1:DEIziO8d9PT+E1OIij3Ua0H8vO9Z5yqCJGb3m8BOGL0=
+github.com/qydysky/part v0.0.6/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
 github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY=
 github.com/shirou/gopsutil v2.20.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=