From 190d33fde8237806d025032736d0dc07191d650c Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Tue, 17 Jan 2023 22:17:04 +0800 Subject: [PATCH] =?utf8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=20=E6=B7=BB=E5=8A=A0?= =?utf8?q?=E6=9F=A5=E7=9C=8B=E5=8E=86=E5=8F=B2=E4=B8=BB=E6=92=AD=E8=A7=82?= =?utf8?q?=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- F/api.go | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ Json/history.go | 53 +++++++++++++++++++++++++++++++++++ README.md | 4 +-- cmd/cmd.go | 29 +++++++++++++++++++ 4 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 Json/history.go diff --git a/F/api.go b/F/api.go index 24de853..904cfe0 100644 --- 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 index 0000000..0cb9178 --- /dev/null +++ b/Json/history.go @@ -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"` +} diff --git a/README.md b/README.md index 5b1b3b5..9190916 100644 --- 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 diff --git a/cmd/cmd.go b/cmd/cmd.go index ad5d752..d938970 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -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 { -- 2.39.2