From a0f51ec8b5c7855131845ad5978eec787c843682 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sat, 10 Oct 2020 11:49:17 +0800 Subject: [PATCH] =?utf8?q?=E6=B8=85=E6=99=B0=E5=BA=A6=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CV/Var.go | 12 +++++++++++- F/api.go | 27 ++++++++++++++++++++++----- README.md | 2 +- Reply/F.go | 14 ++------------ bili_danmu.go | 3 +++ 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/CV/Var.go b/CV/Var.go index 11196e8..fe4056d 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -2,6 +2,7 @@ package cv var ( Live []string//直播链接 + Live_qn string Roomid int Cookie string Title string @@ -13,4 +14,13 @@ var ( */ var ( VERSION = "2.0.11" -) \ No newline at end of file +) + +var Default_qn = map[string]string{ + "10000":"原画", + "400":"蓝光", + "250":"超清", + "150":"高清", + "80":"流畅", + "0":"自动", +} \ No newline at end of file diff --git a/F/api.go b/F/api.go index 13e2248..80ac91a 100644 --- a/F/api.go +++ b/F/api.go @@ -116,7 +116,7 @@ func (i *api) Get_info() (o *api) { return } -func (i *api) Get_live(qn ...int) (o *api) { +func (i *api) Get_live(qn ...string) (o *api) { o = i if o.Roomid == 0 { apilog.E("还未New_api") @@ -131,10 +131,10 @@ func (i *api) Get_live(qn ...int) (o *api) { Cookie = Cookie[:i] + Cookie[i + d + 1:] } } else { - qn = []int{} + qn = []string{} } - if len(qn) == 0 || qn[0] == 0 {//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, @@ -154,6 +154,8 @@ func (i *api) Get_live(qn ...int) (o *api) { } apilog.W("api version", c.VERSION) } + + cu_qn := "0" {//api获取 req := p.Req() if err := req.Reqf(p.Rval{ @@ -207,10 +209,17 @@ func (i *api) Get_live(qn ...int) (o *api) { o.Live = append(o.Live, v.(string)) } } + if i := p.Json().GetValFrom(res, "data.play_url.current_qn"); i != nil { + cu_qn = strconv.Itoa(int(i.(float64))) + } - if len(qn) != 0 && qn[0] != 0 { + if len(qn) != 0 && qn[0] != "0" { + if _,ok := c.Default_qn[qn[0]];!ok{ + apilog.W("清晰度未找到", qn[0], ",使用默认") + return + } 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", + Url:"https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid=" + strconv.Itoa(o.Roomid) + "&qn=" + qn[0] + "&platform=web&https_url_req=1&ptype=16", Referer:"https://live.bilibili.com/" + strconv.Itoa(o.Roomid), Timeout:10, Cookie:Cookie, @@ -230,8 +239,16 @@ func (i *api) Get_live(qn ...int) (o *api) { o.Live = append(o.Live, v.(string)) } } + if i := p.Json().GetValFrom(res, "data.current_qn"); i != nil { + cu_qn = strconv.Itoa(int(i.(float64))) + c.Live_qn = cu_qn + } } } + + if v,ok := c.Default_qn[cu_qn];ok { + apilog.W("当前清晰度:", v) + } return } diff --git a/README.md b/README.md index ee85186..2c7af6f 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ git clone https://github.com/qydysky/bili_danmu.git cd demo go run main.go 或 -go run main.go -r=此处填房间ID +go run main.go -q 清晰度 -r 房间ID ``` - 未配置[go环境](https://golang.google.cn/dl/) diff --git a/Reply/F.go b/Reply/F.go index 8d4a797..394e2c5 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -233,20 +233,10 @@ 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形式调用,将会获取直播流 @@ -258,7 +248,7 @@ func Saveflvf(){ cuLinkIndex := 0 api := F.New_api(c.Roomid) - for api.Get_live(saveflv.qn).Live_status == 1 && !saveflv.cancel.Islive() { + for api.Get_live(c.Live_qn).Live_status == 1 { c.Live = api.Live saveflv.path = strconv.Itoa(c.Roomid) + "_" + time.Now().Format("2006_01_02_15:04:05.000") @@ -320,7 +310,7 @@ func Saveflvf(){ l.I("结束") Ass_f("", time.Now())//ass - + if !saveflv.cancel.Islive() {break}//cancel /* Saveflv需要外部组件 ffmpeg http://ffmpeg.org/download.html diff --git a/bili_danmu.go b/bili_danmu.go index 9b2cd70..31c4193 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -27,8 +27,11 @@ func Demo(roomid ...int) { { var groomid = flag.Int("r", 0, "roomid") + var live_qn = flag.String("q", "0", "qn") flag.Parse() + if _,ok := c.Default_qn[*live_qn]; ok{c.Live_qn = *live_qn} + var room = *groomid if room == 0 && len(roomid) != 0 { room = roomid[0] -- 2.39.2