]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
命令行 添加查看历史主播观看
authorqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 17 Jan 2023 14:17:04 +0000 (22:17 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 17 Jan 2023 14:17:04 +0000 (22:17 +0800)
F/api.go
Json/history.go [new file with mode: 0644]
README.md
cmd/cmd.go

index 24de853542cafdbde9eebb2cb60180af6fb22e1d..904cfe058b704c950f34c2e5122bdf77cb2e2d17 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -2235,6 +2235,80 @@ type UpItem struct {
        LiveStatus int    `json:"live_status"`
 }
 
+// 获取历史观看 直播
+func GetHisStream() (Uplist []UpItem) {
+       apilog := apilog.Base_add(`历史直播主播`).L(`T: `, `获取中`)
+       defer apilog.L(`T: `, `完成`)
+       //验证cookie
+       if missKey := CookieCheck([]string{
+               `bili_jct`,
+               `DedeUserID`,
+               `LIVE_BUVID`,
+       }); len(missKey) != 0 {
+               apilog.L(`T: `, `Cookie无Key:`, missKey)
+               return
+       }
+       if api_limit.TO() {
+               apilog.L(`E: `, `超时!`)
+               return
+       } //超额请求阻塞,超时将取消
+
+       Cookie := make(map[string]string)
+       c.C.Cookie.Range(func(k, v interface{}) bool {
+               Cookie[k.(string)] = v.(string)
+               return true
+       })
+
+       reqi := c.C.ReqPool.Get()
+       defer c.C.ReqPool.Put(reqi)
+       req := reqi.Item.(*reqf.Req)
+       if err := req.Reqf(reqf.Rval{
+               Url: `https://api.bilibili.com/x/web-interface/history/cursor?type=live&ps=10`,
+               Header: map[string]string{
+                       `Host`:            `api.live.bilibili.com`,
+                       `User-Agent`:      `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`,
+                       `Accept`:          `application/json, text/plain, */*`,
+                       `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`,
+                       `Accept-Encoding`: `gzip, deflate, br`,
+                       `Origin`:          `https://t.bilibili.com`,
+                       `Connection`:      `keep-alive`,
+                       `Pragma`:          `no-cache`,
+                       `Cache-Control`:   `no-cache`,
+                       `Referer`:         `https://t.bilibili.com/pages/nav/index_new`,
+                       `Cookie`:          reqf.Map_2_Cookies_String(Cookie),
+               },
+               Proxy:   c.C.Proxy,
+               Timeout: 3 * 1000,
+               Retry:   2,
+       }); err != nil {
+               apilog.L(`E: `, err)
+               return
+       }
+
+       var res J.History
+
+       if e := json.Unmarshal(req.Respon, &res); e != nil {
+               apilog.L(`E: `, e)
+               return
+       }
+
+       if res.Code != 0 {
+               apilog.L(`E: `, res.Message)
+               return
+       }
+
+       // 提前结束获取,仅获取当前正在直播的主播
+       for _, item := range res.Data.List {
+               Uplist = append(Uplist, UpItem{
+                       Uname:      item.AuthorName,
+                       Title:      item.Title,
+                       Roomid:     item.Kid,
+                       LiveStatus: item.LiveStatus,
+               })
+       }
+       return
+}
+
 func Feed_list() (Uplist []J.FollowingDataList) {
        apilog := apilog.Base_add(`正在直播主播`).L(`T: `, `获取中`)
        defer apilog.L(`T: `, `完成`)
diff --git a/Json/history.go b/Json/history.go
new file mode 100644 (file)
index 0000000..0cb9178
--- /dev/null
@@ -0,0 +1,53 @@
+package part
+
+type History struct {
+       Code    int    `json:"code"`
+       Message string `json:"message"`
+       TTL     int    `json:"ttl"`
+       Data    struct {
+               Cursor struct {
+                       Max      int    `json:"max"`
+                       ViewAt   int    `json:"view_at"`
+                       Business string `json:"business"`
+                       Ps       int    `json:"ps"`
+               } `json:"cursor"`
+               Tab []struct {
+                       Type string `json:"type"`
+                       Name string `json:"name"`
+               } `json:"tab"`
+               List []struct {
+                       Title     string      `json:"title"`
+                       LongTitle string      `json:"long_title"`
+                       Cover     string      `json:"cover"`
+                       Covers    interface{} `json:"covers"`
+                       URI       string      `json:"uri"`
+                       History   struct {
+                               Oid      int    `json:"oid"`
+                               Epid     int    `json:"epid"`
+                               Bvid     string `json:"bvid"`
+                               Page     int    `json:"page"`
+                               Cid      int    `json:"cid"`
+                               Part     string `json:"part"`
+                               Business string `json:"business"`
+                               Dt       int    `json:"dt"`
+                       } `json:"history"`
+                       Videos     int    `json:"videos"`
+                       AuthorName string `json:"author_name"`
+                       AuthorFace string `json:"author_face"`
+                       AuthorMid  int    `json:"author_mid"`
+                       ViewAt     int    `json:"view_at"`
+                       Progress   int    `json:"progress"`
+                       Badge      string `json:"badge"`
+                       ShowTitle  string `json:"show_title"`
+                       Duration   int    `json:"duration"`
+                       Current    string `json:"current"`
+                       Total      int    `json:"total"`
+                       NewDesc    string `json:"new_desc"`
+                       IsFinish   int    `json:"is_finish"`
+                       IsFav      int    `json:"is_fav"`
+                       Kid        int    `json:"kid"`
+                       TagName    string `json:"tag_name"`
+                       LiveStatus int    `json:"live_status"`
+               } `json:"list"`
+       } `json:"data"`
+}
index 5b1b3b5d0d9eee80d0538f0e3080a661c7a30562..9190916ce7ddb2ef08d1422bb48047be8e3725de 100644 (file)
--- a/README.md
+++ b/README.md
@@ -96,7 +96,7 @@
 - [x] 直播流断流再保存
 - [x] 直播hls流均衡负载
 - [x] 多房间直播流保存
-- [x] 命令行支持房间切换、弹幕发送、表情发送、启停录制、重载弹幕
+- [x] 命令行支持房间切换、弹幕发送、表情发送、启停录制、重载弹幕、查看历史记录、查看正在直播的主播
 - [x] GTK信息窗支持房间切换、弹幕格式化发送、时长统计
 - [x] GTK弹幕窗支持自定义人/事件消息停留
 
@@ -258,7 +258,7 @@ I: 2021/04/13 20:04:56 命令行操作 [分区排行: 50+ 人气: 41802746]
 I: 2021/04/13 20:04:56 命令行操作 [直播Web服务: http://192.168.31.245:38259]
 ```
 
-还支持登录、搜索主播直播间、保存直播流等功能
+还支持登录、搜索主播直播间、查看历史记录、保存直播流等功能
 
 #### cookie加密
 保护cookie.txt
index ad5d7527c15e0e537ebc1ed9f32f615387bcfa19..d9389708cde91037a2bb0e1365c882259a8d731e 100644 (file)
@@ -29,6 +29,7 @@ func Cmd() {
                        if c.C.Roomid == 0 {
                                if _, ok := c.C.Cookie.LoadV(`bili_jct`).(string); ok {
                                        fmt.Println("查看直播中主播->输入' live'回车")
+                                       fmt.Println("查看历史观看主播->输入' his'回车")
                                } else {
                                        fmt.Println("登陆->输入' login'回车")
                                }
@@ -99,6 +100,34 @@ func Cmd() {
                                fmt.Print("\n")
                                continue
                        }
+                       //直播间历史
+                       if strings.Contains(inputs, ` his`) {
+                               if _, ok := c.C.Cookie.LoadV(`bili_jct`).(string); !ok {
+                                       cmdlog.L(`W: `, "尚未登陆,未能获取关注主播")
+                                       continue
+                               }
+                               fmt.Print("\n")
+                               if len(inputs) > 4 {
+                                       if room, ok := liveList[inputs]; ok {
+                                               c.C.Roomid = room
+                                               c.C.Danmu_Main_mq.Push_tag(`change_room`, nil)
+                                               continue
+                                       }
+                                       cmdlog.L(`W: `, "输入错误", inputs)
+                                       continue
+                               }
+                               for k, v := range F.GetHisStream() {
+                                       liveList[` his`+strconv.Itoa(k)] = v.Roomid
+                                       if v.LiveStatus == 1 {
+                                               fmt.Printf("%d\t%s\t%s(%d)\n\t\t\t%s\n", k, `☁`, v.Uname, v.Roomid, v.Title)
+                                       } else {
+                                               fmt.Printf("%d\t%s\t%s(%d)\n\t\t\t%s\n", k, ` `, v.Uname, v.Roomid, v.Title)
+                                       }
+                               }
+                               fmt.Println("回复' his(序号)'进入直播间")
+                               fmt.Print("\n")
+                               continue
+                       }
                        //登陆
                        if strings.Contains(inputs, ` login`) {
                                if _, ok := c.C.Cookie.LoadV(`bili_jct`).(string); ok {