-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilitv.js
178 lines (172 loc) · 7.33 KB
/
bilitv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import plugin from '../../lib/plugins/plugin.js'
import _ from 'lodash'
const regB23 = /(b23\.tv|bili2233.cn)\\?\/\w{7}/
const regBV = /BV1\w{9}/
const regAV = /av\d+/
const regMD = /md\d+/ // media_id 番剧md号
const regSS = /ss\d+/ // season_id 番剧id
const regEP = /ep\d+/ // episode_id 番剧剧集编号
function formatNumber(num) {
if(num < 10000){
return num
}else{
return (num/10000).toFixed(1) + "万"
}
}
export class bilitv extends plugin {
constructor(){
super({
name: "bilitv",
dsc: "b站解析",
event: "message",
priority: -114514,
rule:[
{
reg: regBV,
fnc: "jxsp"
},
{
reg: regAV,
fnc: "jxsp"
},
{
reg: regB23,
fnc: "jxsp"
},
{
reg: regSS,
fnc: "jxfj"
},
{
reg: regMD,
fnc: "jxfj"
},
{
reg: regEP,
fnc: "jxfj"
}
]
})
}
async jxsp(e){
let bvid = ""
if(e.msg.match(regAV)){
let table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
let tr = {}
for (let i = 0; i < 58; i++) { tr[table[i]] = i }
const s = [11, 10, 3, 8, 4, 6]
const xor = 177451812
const add = 8728348608
let x = (regAV.exec(e.msg))[0].replace(/av/g,"")
x = (x ^ xor) + add
const r = Array.from('BV1 4 1 7 ')
for (let i = 0; i < 6; i++) {
r[s[i]] = table[Math.floor(x / 58 ** i) % 58]
}
bvid = r.join("")
if(!(bvid.match(regBV))){
return true
}
}
if(e.msg.includes("点赞" && "投币")){ return true }
if(e.msg.match(regB23)){
try{
bvid = regBV.exec((await fetch("https://"+(regB23.exec(e.msg)[0]).replace(/\\/g,""))).url)
if(bvid == null){
e.reply("解析失败",true)
return true
}
}catch(e){
e.reply("解析失败",true)
return true
}
}
if(e.msg.match(regBV)){
bvid = regBV.exec(e.msg)
}
let res = await fetch(`https://api.bilibili.com/x/web-interface/view?bvid=${bvid}`,{
headers: {
'referer': 'https://www.bilibili.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
})
res = await res.json()
if(res.code != 0){
return e.reply(bvid + "解析失败\n信息:" + res.message)
}else{
e.reply([segment.image(res.data.pic),`${res.data.title}\nhttps://www.bilibili.com/video/${bvid}\n作者: ${res.data.owner.name}\n播放: ${formatNumber(res.data.stat.view)} | 弹幕: ${formatNumber(res.data.stat.danmaku)}\n点赞: ${formatNumber(res.data.stat.like)} | 投币: ${formatNumber(res.data.stat.coin)}\n收藏: ${formatNumber(res.data.stat.favorite)} | 评论: ${formatNumber(res.data.stat.reply)}`],true)
}
res = await fetch(`https://api.bilibili.com/x/player/playurl?avid=${res.data.aid}&cid=${res.data.cid}&qn=16&type=mp4&platform=html5`,{
headers: {
'referer': 'https://www.bilibili.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
})
res = await res.json()
if(!res || res.code != 0){
e.reply("视频解析失败")
return true
}
e.reply(segment.video(Buffer.from(await (await fetch(res.data.durl[0].url,{
headers: {
'referer': 'https://www.bilibili.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
})).arrayBuffer())))
return true
}
async jxfj(e){
let epid = ""
let ssid = ""
if(e.msg.includes("点赞" && "投币")){ return true }
if(!(e.msg.match(regEP))){
if(e.msg.match(regMD)){
try{
let temp = await (await fetch(`https://api.bilibili.com/pgc/review/user?media_id=${(regMD.exec(e.msg))[0].replace("md", "")}`,{
headers: {
'referer': 'https://www.bilibili.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
})).json()
if(temp.code != 0){
return e.reply("解析失败\n信息:" + temp.message)
}
ssid = temp.result.media.season_id
}catch(e){
e.reply("解析失败")
return true
}
}else{
ssid = (regSS.exec(e.msg))[0].replace("ss", "")
}
let temp = await (await fetch(`https://api.bilibili.com/pgc/web/season/section?season_id=${ssid}`,{
headers: {
'referer': 'https://www.bilibili.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
})).json()
if(temp.code != 0){
return e.reply("解析失败\n信息:" + temp.message)
}
epid = (temp.result.main_section.episodes[0].share_url).replace("https://www.bilibili.com/bangumi/play/ep","")
}else{
epid = (regEP.exec(e.msg))[0].replace("ep", "")
}
let res = await (await fetch(`https://api.bilibili.com/pgc/view/web/season?ep_id=${epid}`,{
headers: {
'referer': 'https://www.bilibili.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
})).json()
if(res.code != 0){
return e.reply("解析失败\n信息:" + res.message)
}
e.reply([
segment.image(res.result.cover),
`${res.result.title}\n评分: ${res.result.rating.score} / ${res.result.rating.count}\n${res.result.new_ep.desc}, ${res.result.seasons[0].new_ep.index_show}\n`,
"---\n",
`${res.result.link}\n播放: ${formatNumber(res.result.stat.views)} | 弹幕: ${formatNumber(res.result.stat.danmakus)}\n点赞: ${formatNumber(res.result.stat.likes)} | 投币: ${formatNumber(res.result.stat.coins)}\n追番: ${formatNumber(res.result.stat.favorites)} | 收藏: ${formatNumber(res.result.stat.favorite)}\n`
],true)
return true
}
}