]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
清晰度选项
authorqydysky <qydysky@foxmail.com>
Sat, 10 Oct 2020 03:49:17 +0000 (11:49 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 10 Oct 2020 03:49:17 +0000 (11:49 +0800)
CV/Var.go
F/api.go
README.md
Reply/F.go
bili_danmu.go

index 11196e8edd8b00a62b221bce1a124bdf4cff9aba..fe4056de7bf694e56ad4f81ccc0e28b27e798353 100644 (file)
--- 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
index 13e2248a8d40fdd852412076fba6209314bd6eea..80ac91a74e60392c47991042ef78334a17e4ecb0 100644 (file)
--- 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
 }
 
index ee8518666ffe43718c3b8ce123bd069ae8b40943..2c7af6f139553829c28aa4c53494b55d9f04071f 100644 (file)
--- 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/)
index 8d4a797f375471d72fd7551b4ab752713b081fa6..394e2c5e84c17d20baf16ed9debe8eb16a9a8496 100644 (file)
@@ -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
index 9b2cd7011da12495e544aee8378b6392d6033843..31c41934113716c97406bb6c3e9666c9dc1a6c63 100644 (file)
@@ -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]