Skip to content

Commit 1c9a7eb

Browse files
authored
🎨 修改bilibili,bilibiliparse插件结构,添加bilibili动态直播专栏解析 (#319)
* 🎨 修改bilibili,bilibiliparse插件结构,添加bilibili动态直播专栏解析 * 💩 修改大小写 * 🎨 正则全局,错误处理 * 🎨 使用json.NewDecoder() * 💚 空使用 * 💚 修lint
1 parent 31555cb commit 1c9a7eb

File tree

13 files changed

+909
-398
lines changed

13 files changed

+909
-398
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,11 @@ print("run[CQ:image,file="+j["img"]+"]")
387387

388388
</details>
389389
<details>
390-
<summary>b站视频链接解析</summary>
390+
<summary>b站动态、专栏、视频、直播解析</summary>
391391

392-
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_parse"`
392+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili"`
393393

394-
- [x] https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA | https://www.bilibili.com/video/bv1xx411c7BF
394+
- [x] t.bilibili.com/642277677329285174 | bilibili.com/read/cv17134450 | bilibili.com/video/BV13B4y1x7pS | live.bilibili.com/22603245
395395

396396
</details>
397397
<details>

main.go

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -55,65 +55,64 @@ import (
5555
// vvvvvvvvvvvvvv //
5656
// vvvv //
5757

58-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ai_false" // 服务器监控
59-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/aiwife" // 随机老婆
60-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/b14" // base16384加解密
61-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu" // 百度一下
62-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili" // 查询b站用户信息
63-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_parse" // b站视频链接解析
64-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/book_review" // 哀伤雪刃吧推书记录
65-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cangtoushi" // 藏头诗
66-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/choose" // 选择困难症帮手
67-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chouxianghua" // 说抽象话
68-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/coser" // 三次元小姐姐
69-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cpstory" // cp短打
70-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/danbooru" // DeepDanbooru二次元图标签识别
71-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/diana" // 嘉心糖发病
72-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drift_bottle" // 漂流瓶
73-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/emojimix" // 合成emoji
74-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/epidemic" // 城市疫情查询
75-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/font" // 渲染任意文字到图片
76-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/fortune" // 运势
77-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/funny" // 笑话
78-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/genshin" // 原神抽卡
79-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/gif" // 制图
80-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/github" // 搜索GitHub仓库
81-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/guessmusic" // 猜歌
82-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hs" // 炉石
83-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hyaku" // 百人一首
84-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/image_finder" // 关键字搜图
85-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/inject" // 注入指令
86-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan" // 煎蛋网无聊图
87-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/juejuezi" // 绝绝子生成器
88-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon" // lolicon 随机图片
89-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/midicreate" // 简易midi音乐制作
90-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moyu" // 摸鱼
91-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moyu_calendar" // 摸鱼人日历
92-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/music" // 点歌
93-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativesetu" // 本地涩图
94-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativewife" // 本地老婆
95-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nbnhhsh" // 拼音首字母缩写释义工具
96-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
97-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
98-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
99-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
100-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/reborn" // 投胎
101-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
102-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/saucenao" // 以图搜图
103-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/scale" // 叔叔的AI二次元图片放大
104-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/score" // 分数
105-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/setutime" // 来份涩图
106-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shadiao" // 沙雕app
107-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shindan" // 测定
108-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot" // 抽塔罗牌
109-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tiangou" // 舔狗日记
110-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tracemoe" // 搜番
111-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
112-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
113-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
114-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count" // 聊天热词
115-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
116-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
58+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ai_false" // 服务器监控
59+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/aiwife" // 随机老婆
60+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/b14" // base16384加解密
61+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu" // 百度一下
62+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili" // b站相关
63+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/book_review" // 哀伤雪刃吧推书记录
64+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cangtoushi" // 藏头诗
65+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/choose" // 选择困难症帮手
66+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chouxianghua" // 说抽象话
67+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/coser" // 三次元小姐姐
68+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cpstory" // cp短打
69+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/danbooru" // DeepDanbooru二次元图标签识别
70+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/diana" // 嘉心糖发病
71+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drift_bottle" // 漂流瓶
72+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/emojimix" // 合成emoji
73+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/epidemic" // 城市疫情查询
74+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/font" // 渲染任意文字到图片
75+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/fortune" // 运势
76+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/funny" // 笑话
77+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/genshin" // 原神抽卡
78+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/gif" // 制图
79+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/github" // 搜索GitHub仓库
80+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/guessmusic" // 猜歌
81+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hs" // 炉石
82+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hyaku" // 百人一首
83+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/image_finder" // 关键字搜图
84+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/inject" // 注入指令
85+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan" // 煎蛋网无聊图
86+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/juejuezi" // 绝绝子生成器
87+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon" // lolicon 随机图片
88+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/midicreate" // 简易midi音乐制作
89+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moyu" // 摸鱼
90+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moyu_calendar" // 摸鱼人日历
91+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/music" // 点歌
92+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativesetu" // 本地涩图
93+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativewife" // 本地老婆
94+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nbnhhsh" // 拼音首字母缩写释义工具
95+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
96+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
97+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
98+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
99+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/reborn" // 投胎
100+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
101+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/saucenao" // 以图搜图
102+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/scale" // 叔叔的AI二次元图片放大
103+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/score" // 分数
104+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/setutime" // 来份涩图
105+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shadiao" // 沙雕app
106+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shindan" // 测定
107+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tarot" // 抽塔罗牌
108+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tiangou" // 舔狗日记
109+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tracemoe" // 搜番
110+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
111+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
112+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
113+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count" // 聊天热词
114+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
115+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
117116

118117
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/wtf" // 鬼东西
119118

plugin/bilibili/api.go

Lines changed: 51 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package bilibili
33
import (
44
"encoding/json"
55
"errors"
6-
"io"
6+
"fmt"
77
"net/http"
8+
"strconv"
89

910
"github.com/FloatTech/zbputils/binary"
1011
"github.com/FloatTech/zbputils/web"
@@ -15,18 +16,9 @@ var (
1516
errNeedCookie = errors.New("该api需要设置b站cookie,请发送命令设置cookie,例如\"设置b站cookie SESSDATA=82da790d,1663822823,06ecf*31\"")
1617
)
1718

18-
type searchResult struct {
19-
Mid int64 `json:"mid"`
20-
Uname string `json:"uname"`
21-
Gender int64 `json:"gender"`
22-
Usign string `json:"usign"`
23-
Level int64 `json:"level"`
24-
}
25-
26-
// 搜索api:通过把触发指令传入的昵称找出uid返回
27-
func search(keyword string) (r []searchResult, err error) {
28-
searchURL := "http://api.bilibili.com/x/web-interface/search/type?search_type=bili_user&keyword=" + keyword
29-
data, err := web.GetData(searchURL)
19+
// searchUser 查找b站用户
20+
func searchUser(keyword string) (r []searchResult, err error) {
21+
data, err := web.GetData(fmt.Sprintf(searchUserURL, keyword))
3022
if err != nil {
3123
return
3224
}
@@ -42,35 +34,35 @@ func search(keyword string) (r []searchResult, err error) {
4234
return
4335
}
4436

45-
type follower struct {
46-
Mid int `json:"mid"`
47-
Uname string `json:"uname"`
48-
Video int `json:"video"`
49-
Roomid int `json:"roomid"`
50-
Rise int `json:"rise"`
51-
Follower int `json:"follower"`
52-
GuardNum int `json:"guardNum"`
53-
AreaRank int `json:"areaRank"`
37+
// getVtbDetail 查找vtb信息
38+
func getVtbDetail(uid string) (result vtbDetail, err error) {
39+
data, err := web.GetData(fmt.Sprintf(vtbDetailURL, uid))
40+
if err != nil {
41+
return
42+
}
43+
if err = json.Unmarshal(data, &result); err != nil {
44+
return
45+
}
46+
return
5447
}
5548

56-
// 请求api
57-
func fansapi(uid string) (result follower, err error) {
58-
fanURL := "https://api.vtbs.moe/v1/detail/" + uid
59-
data, err := web.GetData(fanURL)
49+
// getMemberCard 获取b站个人详情
50+
func getMemberCard(uid interface{}) (result memberCard, err error) {
51+
data, err := web.GetData(fmt.Sprintf(memberCardURL, uid))
6052
if err != nil {
6153
return
6254
}
63-
if err = json.Unmarshal(data, &result); err != nil {
55+
err = json.Unmarshal(binary.StringToBytes(gjson.ParseBytes(data).Get("card").Raw), &result)
56+
if err != nil {
6457
return
6558
}
6659
return
6760
}
6861

69-
func followings(uid string) (s string, err error) {
70-
followingURL := "https://api.bilibili.com/x/relation/same/followings?vmid=" + uid
71-
method := "GET"
62+
// getMedalwall 用b站uid获得牌子
63+
func getMedalwall(uid string) (result []medal, err error) {
7264
client := &http.Client{}
73-
req, err := http.NewRequest(method, followingURL, nil)
65+
req, err := http.NewRequest("GET", fmt.Sprintf(medalwallURL, uid), nil)
7466
if err != nil {
7567
return
7668
}
@@ -81,99 +73,56 @@ func followings(uid string) (s string, err error) {
8173
return
8274
}
8375
defer res.Body.Close()
84-
body, err := io.ReadAll(res.Body)
76+
var md medalData
77+
err = json.NewDecoder(res.Body).Decode(&md)
8578
if err != nil {
8679
return
8780
}
88-
j := gjson.ParseBytes(body)
89-
s = j.Get("data.list.#.uname").Raw
90-
if j.Get("code").Int() == -101 {
81+
if md.Code == -101 {
9182
err = errNeedCookie
9283
return
9384
}
94-
if j.Get("code").Int() != 0 {
95-
err = errors.New(j.Get("message").String())
96-
return
85+
if md.Code != 0 {
86+
err = errors.New(md.Message)
9787
}
88+
result = md.Data.List
9889
return
9990
}
10091

101-
type userinfo struct {
102-
Name string `json:"name"`
103-
Mid string `json:"mid"`
104-
Face string `json:"face"`
105-
Fans int64 `json:"fans"`
106-
Regtime int64 `json:"regtime"`
107-
Attentions []int64 `json:"attentions"`
108-
}
109-
110-
type medalInfo struct {
111-
Mid int64 `json:"target_id"`
112-
MedalName string `json:"medal_name"`
113-
Level int64 `json:"level"`
114-
MedalColorStart int64 `json:"medal_color_start"`
115-
MedalColorEnd int64 `json:"medal_color_end"`
116-
MedalColorBorder int64 `json:"medal_color_border"`
117-
}
118-
type medal struct {
119-
Uname string `json:"target_name"`
120-
medalInfo `json:"medal_info"`
121-
}
122-
123-
type medalSlice []medal
124-
125-
func (m medalSlice) Len() int {
126-
return len(m)
127-
}
128-
func (m medalSlice) Swap(i, j int) {
129-
m[i], m[j] = m[j], m[i]
130-
}
131-
func (m medalSlice) Less(i, j int) bool {
132-
return m[i].Level > m[j].Level
133-
}
134-
135-
// 获取详情
136-
func card(uid string) (result userinfo, err error) {
137-
cardURL := "https://account.bilibili.com/api/member/getCardByMid?mid=" + uid
138-
data, err := web.GetData(cardURL)
139-
if err != nil {
140-
return
141-
}
142-
err = json.Unmarshal(binary.StringToBytes(gjson.ParseBytes(data).Get("card").Raw), &result)
92+
// getArticleInfo 用id查专栏信息
93+
func getArticleInfo(id string) (card Card, err error) {
94+
var data []byte
95+
data, err = web.GetData(fmt.Sprintf(articleInfoURL, id))
14396
if err != nil {
14497
return
14598
}
99+
err = json.Unmarshal(binary.StringToBytes(gjson.ParseBytes(data).Get("data").Raw), &card)
146100
return
147101
}
148102

149-
// 获得牌子
150-
func medalwall(uid string) (result []medal, err error) {
151-
medalwallURL := "https://api.live.bilibili.com/xlive/web-ucenter/user/MedalWall?target_id=" + uid
152-
method := "GET"
153-
client := &http.Client{}
154-
req, err := http.NewRequest(method, medalwallURL, nil)
103+
// getLiveRoomInfo 用直播间id查直播间信息
104+
func getLiveRoomInfo(roomID string) (card roomCard, err error) {
105+
var data []byte
106+
data, err = web.GetData(fmt.Sprintf(liveRoomInfoURL, roomID))
155107
if err != nil {
156108
return
157109
}
158-
c := vdb.getBilibiliCookie()
159-
req.Header.Add("cookie", c.Value)
160-
res, err := client.Do(req)
161-
if err != nil {
162-
return
110+
err = json.Unmarshal(binary.StringToBytes(gjson.ParseBytes(data).Get("data").Raw), &card)
111+
return
112+
}
113+
114+
// getVideoInfo 用av或bv查视频信息
115+
func getVideoInfo(id string) (card Card, err error) {
116+
var data []byte
117+
_, err = strconv.Atoi(id)
118+
if err == nil {
119+
data, err = web.GetData(fmt.Sprintf(videoInfoURL, id, ""))
120+
} else {
121+
data, err = web.GetData(fmt.Sprintf(videoInfoURL, "", id))
163122
}
164-
defer res.Body.Close()
165-
data, err := io.ReadAll(res.Body)
166123
if err != nil {
167124
return
168125
}
169-
j := gjson.ParseBytes(data)
170-
if j.Get("code").Int() == -101 {
171-
err = errNeedCookie
172-
return
173-
}
174-
if j.Get("code").Int() != 0 {
175-
err = errors.New(j.Get("message").String())
176-
}
177-
_ = json.Unmarshal(binary.StringToBytes(j.Get("data.list").Raw), &result)
126+
err = json.Unmarshal(binary.StringToBytes(gjson.ParseBytes(data).Get("data").Raw), &card)
178127
return
179128
}

0 commit comments

Comments
 (0)