From 33b58cefd60d6f029ceb493ed3e206336714f0f6 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 16 Aug 2022 00:29:06 +0800 Subject: [PATCH] =?utf8?q?=E6=9B=B4=E6=96=B0=E6=AD=A3=E5=9C=A8=E7=9B=B4?= =?utf8?q?=E6=92=AD=E7=9A=84=E4=B8=BB=E6=92=ADapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CV/Const.go | 38 ++++++++++++++++----------------- CV/Var.go | 2 +- F/api.go | 54 +++++++++++++++++++++++------------------------ Json/following.go | 33 +++++++++++++++++++++++++++++ Reply/stream.go | 2 +- Send/Send.go | 6 +++--- Send/Send_gift.go | 4 ++-- Send/Send_pm.go | 4 ++-- 8 files changed, 88 insertions(+), 55 deletions(-) create mode 100644 Json/following.go diff --git a/CV/Const.go b/CV/Const.go index f177009..23a21f0 100644 --- a/CV/Const.go +++ b/CV/Const.go @@ -2,24 +2,24 @@ package cv //from source/player-loader-2.0.11.min.js const ( - WS_OP_HEARTBEAT = 2 - WS_OP_HEARTBEAT_REPLY = 3 - WS_OP_MESSAGE = 5 - WS_OP_USER_AUTHENTICATION = 7 - WS_OP_CONNECT_SUCCESS = 8 - WS_PACKAGE_HEADER_TOTAL_LENGTH = 16 - WS_PACKAGE_OFFSET = 0 - WS_HEADER_OFFSET = 4 - WS_VERSION_OFFSET = 6 - WS_OPERATION_OFFSET = 8 - WS_SEQUENCE_OFFSET = 12 - WS_BODY_PROTOCOL_VERSION_NORMAL = 0 + WS_OP_HEARTBEAT = 2 + WS_OP_HEARTBEAT_REPLY = 3 + WS_OP_MESSAGE = 5 + WS_OP_USER_AUTHENTICATION = 7 + WS_OP_CONNECT_SUCCESS = 8 + WS_PACKAGE_HEADER_TOTAL_LENGTH = 16 + WS_PACKAGE_OFFSET = 0 + WS_HEADER_OFFSET = 4 + WS_VERSION_OFFSET = 6 + WS_OPERATION_OFFSET = 8 + WS_SEQUENCE_OFFSET = 12 + WS_BODY_PROTOCOL_VERSION_NORMAL = 0 WS_BODY_PROTOCOL_VERSION_DEFLATE = 2 - WS_HEADER_DEFAULT_VERSION = 1 - WS_HEADER_DEFAULT_OPERATION = 1 - WS_HEADER_DEFAULT_SEQUENCE = 1 - WS_AUTH_OK = 0 - WS_AUTH_TOKEN_ERROR = -101 + WS_HEADER_DEFAULT_VERSION = 1 + WS_HEADER_DEFAULT_OPERATION = 1 + WS_HEADER_DEFAULT_SEQUENCE = 1 + WS_AUTH_OK = 0 + WS_AUTH_TOKEN_ERROR = -101 ) //from player-loader-2.0.11.min.js @@ -29,5 +29,5 @@ const ( const ( Protover = 2 Platform = "web" - Type = 2 -) \ No newline at end of file + Type = 2 +) diff --git a/CV/Var.go b/CV/Var.go index 1538abf..2007211 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -111,7 +111,7 @@ func (t *Common) init() Common { var C = new(Common).init() -//消息队列 +// 消息队列 type Danmu_Main_mq_item struct { Class string Data interface{} diff --git a/F/api.go b/F/api.go index 8501887..5d60ede 100644 --- a/F/api.go +++ b/F/api.go @@ -976,7 +976,7 @@ func (c *GetFunc) Get_HotRank() (missKey []string) { Url: `https://api.live.bilibili.com/xlive/general-interface/v1/rank/getHotRank?ruid=` + strconv.Itoa(c.UpUid) + `&room_id=` + Roomid + `&is_pre=0&page_size=50&source=2&area_id=` + strconv.Itoa(c.ParentAreaID), Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -1050,7 +1050,7 @@ func (c *GetFunc) Get_guardNum() (missKey []string) { Url: `https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid=` + Roomid + `&page=1&ruid=` + strconv.Itoa(c.UpUid) + `&page_size=29`, Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -1687,7 +1687,7 @@ func Dosign() { Url: `https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/WebGetSignInfo`, Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -1739,7 +1739,7 @@ func Dosign() { Url: `https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign`, Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -1801,7 +1801,7 @@ func (c *GetFunc) Get_LIVE_BUVID() (missKey []string) { Url: `https://api.live.bilibili.com/live/getRoomKanBanModel?roomid=` + roomid, Header: map[string]string{ `Host`: `live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `User-Agent`: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`, `Accept`: `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8`, `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`, @@ -1901,7 +1901,7 @@ func Gift_list() (list []Gift_list_type_Data_List) { Url: `https://api.live.bilibili.com/xlive/web-room/v1/gift/bag_list?t=` + strconv.Itoa(int(sys.Sys().GetMTime())) + `&room_id=` + strconv.Itoa(c.C.Roomid), Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -1972,7 +1972,7 @@ func (c *GetFunc) Silver_2_coin() (missKey []string) { Url: `https://api.live.bilibili.com/xlive/revenue/v1/wallet/getStatus`, Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -2024,7 +2024,7 @@ func (c *GetFunc) Silver_2_coin() (missKey []string) { Url: `https://api.live.bilibili.com/xlive/revenue/v1/wallet/getRule`, Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -2082,7 +2082,7 @@ func (c *GetFunc) Silver_2_coin() (missKey []string) { PostStr: url.PathEscape(post_str), Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -2139,13 +2139,15 @@ func save_cookie(Cookies []*http.Cookie) { // 正在直播主播 type UpItem struct { - Uname string `json:"uname"` - Title string `json:"title"` - Roomid int `json:"roomid"` + Uname string `json:"uname"` + Title string `json:"title"` + Roomid int `json:"roomid"` + LiveStatus int `json:"live_status"` } -func Feed_list() (Uplist []UpItem) { +func Feed_list() (Uplist []J.FollowingDataList) { apilog := apilog.Base_add(`正在直播主播`).L(`T: `, `获取中`) + defer apilog.L(`T: `, `完成`) //验证cookie if missKey := CookieCheck([]string{ `bili_jct`, @@ -2171,10 +2173,10 @@ func Feed_list() (Uplist []UpItem) { req := reqi.Item.(*reqf.Req) for pageNum := 1; true; pageNum += 1 { if err := req.Reqf(reqf.Rval{ - Url: `https://api.live.bilibili.com/xlive/web-ucenter/v1/xfetter/FeedList?page=` + strconv.Itoa(pageNum) + `&pagesize=10`, + Url: `https://api.live.bilibili.com/xlive/web-ucenter/user/following?page=` + strconv.Itoa(pageNum) + `&page_size=10`, Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `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`, @@ -2193,15 +2195,7 @@ func Feed_list() (Uplist []UpItem) { return } - var res struct { - Code int `json:"code"` - Msg string `json:"msg"` - Message string `json:"message"` - Data struct { - Results int `json:"results"` - List []UpItem `json:"list"` - } `json:"data"` - } + var res J.Following if e := json.Unmarshal(req.Respon, &res); e != nil { apilog.L(`E: `, e) @@ -2213,15 +2207,21 @@ func Feed_list() (Uplist []UpItem) { return } - Uplist = append(Uplist, res.Data.List...) + // 提前结束获取,仅获取当前正在直播的主播 + for _, item := range res.Data.List { + if item.LiveStatus == 0 { + break + } else { + Uplist = append(Uplist, item) + } + } - if pageNum*10 > res.Data.Results { + if pageNum*10 > res.Data.TotalPage { break } time.Sleep(time.Second) } - apilog.L(`T: `, `完成`) return } diff --git a/Json/following.go b/Json/following.go new file mode 100644 index 0000000..888e56b --- /dev/null +++ b/Json/following.go @@ -0,0 +1,33 @@ +package part + +type Following struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data FollowingData `json:"data"` +} +type FollowingDataList struct { + Roomid int `json:"roomid"` + UID int `json:"uid"` + Uname string `json:"uname"` + Title string `json:"title"` + Face string `json:"face"` + LiveStatus int `json:"live_status"` + RecordNum int `json:"record_num"` + RecentRecordID string `json:"recent_record_id"` + IsAttention int `json:"is_attention"` + Clipnum int `json:"clipnum"` + FansNum int `json:"fans_num"` + AreaName string `json:"area_name"` + AreaValue string `json:"area_value"` + Tags string `json:"tags"` + RecentRecordIDV2 string `json:"recent_record_id_v2"` + RecordNumV2 int `json:"record_num_v2"` +} +type FollowingData struct { + Title string `json:"title"` + PageSize int `json:"pageSize"` + TotalPage int `json:"totalPage"` + List []FollowingDataList `json:"list"` + Count int `json:"count"` +} diff --git a/Reply/stream.go b/Reply/stream.go index 2cb5140..03cd9d0 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -198,7 +198,7 @@ func (t *M4SStream) fetchParseM3U8() (m4s_links []*m4s_link_item, m3u8_addon []b Proxy: c.C.Proxy, Header: map[string]string{ `Host`: m3u8_url.Host, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `User-Agent`: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`, `Accept`: `*/*`, `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`, diff --git a/Send/Send.go b/Send/Send.go index 7d9ed4f..e91aa04 100644 --- a/Send/Send.go +++ b/Send/Send.go @@ -12,10 +12,10 @@ import ( sys "github.com/qydysky/part/sys" ) -//每5s一个令牌,最多等20秒 +// 每5s一个令牌,最多等20秒 var danmu_s_limit = limit.New(1, 5000, 20000) -//弹幕发送 +// 弹幕发送 func Danmu_s(msg string, roomid int) { //等待令牌时阻塞,超时返回true if danmu_s_limit.TO() { @@ -55,7 +55,7 @@ func Danmu_s(msg string, roomid int) { Proxy: c.C.Proxy, Header: map[string]string{ `Host`: `api.live.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `User-Agent`: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`, `Accept`: `application/json, text/javascript, */*; q=0.01`, `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`, diff --git a/Send/Send_gift.go b/Send/Send_gift.go index e8980d3..7d5165c 100644 --- a/Send/Send_gift.go +++ b/Send/Send_gift.go @@ -12,7 +12,7 @@ import ( reqf "github.com/qydysky/part/reqf" ) -//每2s一个令牌,最多等10秒 +// 每2s一个令牌,最多等10秒 var gift_limit = limit.New(1, 2000, 10000) func Send_gift(gift_id, bag_id, gift_num int) { @@ -68,7 +68,7 @@ func Send_gift(gift_id, bag_id, gift_num int) { Proxy: c.C.Proxy, Header: map[string]string{ `Host`: `api.vc.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `User-Agent`: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`, `Accept`: `application/json, text/javascript, */*; q=0.01`, `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`, diff --git a/Send/Send_pm.go b/Send/Send_pm.go index 8e0dff5..d54838b 100644 --- a/Send/Send_pm.go +++ b/Send/Send_pm.go @@ -21,7 +21,7 @@ type Pm_item struct { Msg string } -//每5s一个令牌,最多等10秒 +// 每5s一个令牌,最多等10秒 var pm_limit = limit.New(1, 5000, 10000) func Send_pm(uid int, msg string) error { @@ -76,7 +76,7 @@ func Send_pm(uid int, msg string) error { Proxy: c.C.Proxy, Header: map[string]string{ `Host`: `api.vc.bilibili.com`, - `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `User-Agent`: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`, `Accept`: `application/json, text/javascript, */*; q=0.01`, `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`, -- 2.39.2