From fcb9b3f20fd15e2559d59fa2179b59f0cc196a33 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sat, 10 Oct 2020 08:14:39 +0800 Subject: [PATCH] =?utf8?q?cookie=E6=8F=90=E4=BE=9B=E8=80=85=E4=BD=BF?= =?utf8?q?=E7=94=A8=E5=8E=9F=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CV/Var.go | 2 +- F/api.go | 50 +++++++++++++++++++++------- Reply/F.go | 16 +++++++-- _msg_sample/DANMU_MSG.json | 67 ++++++++++++++++++++++++++++++++++++++ demo/go.mod | 2 +- demo/go.sum | 2 ++ 6 files changed, 123 insertions(+), 16 deletions(-) create mode 100644 _msg_sample/DANMU_MSG.json diff --git a/CV/Var.go b/CV/Var.go index c493bf0..11196e8 100644 --- 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 diff --git a/F/api.go b/F/api.go index 4031022..2663d71 100644 --- 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 diff --git a/Reply/F.go b/Reply/F.go index a2e460c..c04c8b5 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -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 index 0000000..9b80a06 --- /dev/null +++ b/_msg_sample/DANMU_MSG.json @@ -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 diff --git a/demo/go.mod b/demo/go.mod index a0114c2..2380cfd 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -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 diff --git a/demo/go.sum b/demo/go.sum index 8d5bab0..e94dc1c 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -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= -- 2.39.2