-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy path我的哔哩[官].js
342 lines (336 loc) · 11.7 KB
/
我的哔哩[官].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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/**
* 已知问题:
* [推荐]页面:'雷电模拟器'播放部份影片会出错,'播放器'改成'ijk' & '解码方式'改成'软解',即可正常播放
* 影视TV 超連結跳轉支持
* 影视TV 弹幕支持
* https://t.me/fongmi_offical/
* https://github.com/FongMi/Release/tree/main/apk
* 皮皮虾DMBox 弹幕支持
* 设置 > 窗口预览 > 开启
* https://t.me/pipixiawerun
* vod_area:'bilidanmu'
* Cookie设置
* Cookie获取方法 https://ghproxy.net/https://raw.githubusercontent.com/UndCover/PyramidStore/main/list.md
* Cookie设置方法1: DR-PY 后台管理界面
* CMS后台管理 > 设置中心 > 环境变量 > {"bili_cookie":"XXXXXXX","vmid":"XXXXXX"} > 保存
* Cookie设置方法2: 手动替换Cookie
* 底下代码 headers的
* "Cookie":"$bili_cookie"
* 手动替换为
* "Cookie":"将获取的Cookie黏贴在这"
* 客户端长期Cookie设置教程:
* 抓包哔哩手机端搜索access_key,取任意链接里的access_key和appkey在drpy环境变量中增加同名的环境变量即可
* 此时哔哩.js这个解析可用于此源的解析线路用
* 传参 ?render=1&type=url¶ms=../json/哔哩教育.json@哔哩教育[官]
* 传参 ?render=1&type=url¶ms=../json/哔哩大全.json@哔哩大全[官]
*/
var rule = {
title: '我的哔哩[官]',
host: 'https://api.bilibili.com',
homeUrl: '/x/web-interface/ranking/v2?rid=0&type=origin',
url: '/x/web-interface/search/type?search_type=video&fyfilter',
filter_url: 'keyword=fyclass{{fl.tid}}&page=fypage&duration={{fl.duration}}&order={{fl.order}}',
class_parse: async function () {
// let html = request('{{host}}/files/json/哔哩教育.json');
let html = await request(rule.params);
let json = dealJson(html);
let classes = json.classes;
let filters = json.filter;
return {
class: classes,
filters,
}
},
filterable: 1,
detailUrl: '/x/web-interface/view/detail?aid=fyid',
searchUrl: '/x/web-interface/search/type?search_type=video&keyword=**&page=fypage',
searchable: 2,
quickSearch: 0,
// params: '?render=1&type=url¶ms=../json/哔哩教育.json@哔哩教育[官]',
// params: '?render=1&type=url¶ms=../json/哔哩大全.json@哔哩大全[官]',
headers: {
"User-Agent": "PC_UA",
"Referer": "https://www.bilibili.com",
"Cookie": "buvid3=666"
},
timeout: 5000,
limit: 8,
play_parse: true,
double: false,
lazy: async function () {
let {input} = this;
let ids = input.split('_');
let dan = 'https://api.bilibili.com/x/v1/dm/list.so?oid=' + ids[1];
let result = {};
let iurl = 'https://api.bilibili.com:443/x/player/playurl?avid=' + ids[0] + '&cid=' + ids[1] + '&qn=116';
let html = await request(iurl);
let jRoot = JSON.parse(html);
let jo = jRoot.data;
let ja = jo.durl;
let maxSize = -1;
let position = -1;
ja.forEach(function (tmpJo, i) {
if (maxSize < Number(tmpJo.size)) {
maxSize = Number(tmpJo.size);
position = i
}
});
let purl = '';
if (ja.length > 0) {
if (position === -1) {
position = 0
}
purl = ja[position].url
}
result.parse = 0;
result.playUrl = '';
result.url = unescape(purl);
result.header = {
'Referer': 'https://live.bilibili.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
};
if (/\\.flv/.test(purl)) {
result.contentType = 'video/x-flv';
} else {
result.contentType = '';
}
result.danmaku = dan;
return result
},
推荐: async function () {
let {input} = this;
let html = await request(input);
let vodList = JSON.parse(html).data.list;
let videos = [];
vodList.forEach(function (vod) {
let aid = vod.aid;
let title = misc.stripHtmlTag(vod.title);
let img = vod.pic;
if (img.startsWith('//')) {
img = 'https:' + img;
}
let remark = turnDHM(vod.duration) + ' ▶' + ConvertNum(vod.stat.view) + ' 🆙' + vod.owner.name;
videos.push({
vod_id: aid,
vod_name: title,
vod_pic: img,
vod_remarks: remark
})
});
return videos;
},
一级: async function () {
let {input, MY_CATE, MY_PAGE} = this;
if (MY_CATE.endsWith('_clicklink')) {
MY_CATE = MY_CATE.split('_')[0];
input = rule.host + '/x/web-interface/search/type?search_type=video&keyword=' + MY_CATE + '&page=' + MY_PAGE;
}
let data = [];
let vodList = [];
if (MY_CATE === '推荐') {
input = rule.host + '/x/web-interface/index/top/rcmd?ps=14&fresh_idx=' + MY_PAGE + '&fresh_idx_1h=' + MY_PAGE;
data = JSON.parse(await request(input)).data;
vodList = data.item;
} else if (MY_CATE === '历史记录') {
input = rule.host + '/x/v2/history?pn=' + MY_PAGE;
data = JSON.parse(await request(input)).data;
vodList = data;
} else {
data = JSON.parse(await request(input)).data;
vodList = data.result;
}
let videos = [];
vodList.forEach(function (vod) {
let aid = vod.aid ? vod.aid : vod.id;
let title = misc.stripHtmlTag(vod.title);
let img = vod.pic;
if (img.startsWith('//')) {
img = 'https:' + img;
}
let play = '';
let danmaku = '';
if (MY_CATE === '推荐') {
play = ConvertNum(vod.stat.view);
danmaku = vod.stat.danmaku;
} else if (MY_CATE === '历史记录') {
play = ConvertNum(vod.stat.view);
danmaku = vod.stat.danmaku;
} else {
play = ConvertNum(vod.play);
danmaku = vod.video_review;
}
let remark = turnDHM(vod.duration) + ' ▶' + play + ' 💬' + danmaku;
videos.push({
vod_id: aid,
vod_name: title,
vod_pic: img,
vod_remarks: remark
})
});
return videos
},
二级: async function () {
let {input} = this;
let html = await request(input);
let jo = JSON.parse(html).data.View;
// 历史记录
let cookies = rule.headers.Cookie.split(';');
let bili_jct = '';
cookies.forEach(cookie => {
if (cookie.includes('bili_jct')) {
bili_jct = cookie.split('=')[1];
}
});
if (bili_jct !== '') {
let historyReport = 'https://api.bilibili.com/x/v2/history/report';
let dataPost = {
aid: jo.aid,
cid: jo.cid,
csrf: bili_jct,
};
await post(historyReport, dataPost, 'form');
}
let stat = jo.stat;
let up_info = JSON.parse(html).data.Card;
let relation = up_info.following ? '已关注' : '未关注';
let aid = jo.aid;
let title = misc.stripHtmlTag(jo.title);
let pic = jo.pic;
let desc = jo.desc;
let date = new Date(jo.pubdate * 1000);
let yy = date.getFullYear().toString();
let mm = date.getMonth() + 1;
mm = mm < 10 ? ('0' + mm) : mm;
let dd = date.getDate();
dd = dd < 10 ? ('0' + dd) : dd;
let up_name = jo.owner.name;
let typeName = jo.tname;
// let remark = jo.duration;
let vod = {
vod_id: aid,
vod_name: title,
vod_pic: pic,
type_name: typeName,
vod_year: yy + mm + dd,
vod_area: 'bilidanmu',
// vod_remarks: remark,
vod_tags: 'mv',
// vod_director: '🆙 ' + up_name + ' 👥 ' + up_info.follower + ' ' + relation,
vod_director: '🆙 ' + '[a=cr:' + JSON.stringify({
'id': up_name + '_clicklink',
'name': up_name
}) + '/]' + up_name + '[/a]' + ' 👥 ' + up_info.follower + ' ' + relation,
vod_actor: '▶' + stat.view + ' ' + '💬' + stat.danmaku + ' ' + '👍' + stat.like + ' ' + '💰' + stat.coin + ' ' + '⭐' + stat.favorite,
vod_content: desc
};
let ja = jo.pages;
let treeMap = {};
let playurls = [];
ja.forEach(function (tmpJo) {
let cid = tmpJo.cid;
let part = tmpJo.part.replaceAll('#', '﹟').replaceAll('$', '﹩');
playurls.push(
part + '$' + aid + '_' + cid
)
});
treeMap['B站'] = playurls.join('#');
let relatedData = JSON.parse(html).data.Related;
playurls = [];
relatedData.forEach(function (rd) {
let ccid = rd.cid;
let title = rd.title.replaceAll('#', '﹟').replaceAll('$', '﹩');
let aaid = rd.aid;
playurls.push(
title + '$' + aaid + '_' + ccid
)
});
treeMap['相关推荐'] = playurls.join('#');
vod.vod_play_from = Object.keys(treeMap).join("$$$");
vod.vod_play_url = Object.values(treeMap).join("$$$");
return vod;
},
搜索: async function () {
let {input} = this;
let html = await request(input);
let videos = [];
let vodList = JSON.parse(html).data.result;
vodList.forEach(function (vod) {
let aid = vod.aid;
let title = misc.stripHtmlTag(vod.title);
let img = vod.pic;
if (img.startsWith('//')) {
img = 'https:' + img;
}
let remark = turnDHM(vod.duration);
videos.push({
vod_id: aid,
vod_name: title,
vod_pic: img,
vod_remarks: remark
})
});
return videos;
},
}
function turnDHM(duration) {
let min = '';
let sec = '';
try {
min = duration.split(':')[0];
sec = duration.split(':')[1];
} catch (e) {
min = Math.floor(duration / 60);
sec = duration % 60;
}
if (isNaN(parseInt(duration))) {
return '无效输入';
}
if (min == 0) {
return sec + '秒'
} else if (0 < min && min < 60) {
return min + '分'
} else if (60 <= min && min < 1440) {
if (min % 60 == 0) {
let h = min / 60;
return h + '小时'
} else {
let h = min / 60;
h = (h + '').split('.')[0];
let m = min % 60;
return h + '小时' + m + '分';
}
} else if (min >= 1440) {
let d = min / 60 / 24;
d = (d + '').split('.')[0];
let h = min / 60 % 24;
h = (h + '').split('.')[0];
let m = min % 60;
let dhm = '';
if (d > 0) {
dhm = d + '天'
}
if (h >= 1) {
dhm = dhm + h + '小时'
}
if (m > 0) {
dhm = dhm + m + '分'
}
return dhm
}
return null
}
function ConvertNum(num) {
let _ws = Math.pow(10, 1);
let _b = 1e4;
if (num < _b) {
return num.toString();
}
let _r = '';
let _strArg = ['', '万', '亿', '万亿'];
let _i = Math.floor(Math.log(num) / Math.log(_b));
if (_i > 3) {
_i = 3;
}
_r = Math.floor(num / Math.pow(_b, _i) * _ws) / _ws + _strArg[_i];
return _r;
}