@forward-widget/danmu-universe 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/dist/danmu-universe.js +76 -67
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
### 一键安装
|
|
21
21
|
|
|
22
|
-
[](forward://widget?url=https%3A%2F%2Funpkg.com%2F%40forward-widget%2Fdanmu-universe)
|
|
22
|
+
[](https://gocy.pages.dev/#forward://widget?url=https%3A%2F%2Funpkg.com%2F%40forward-widget%2Fdanmu-universe)
|
|
23
23
|
|
|
24
24
|
### 手动安装
|
|
25
25
|
|
|
@@ -32,7 +32,9 @@ https://unpkg.com/@forward-widget/danmu-universe
|
|
|
32
32
|
|
|
33
33
|
## 开发
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
项目自豪的使用 [forward-widget-libs](https://github.com/baranwang/forward-widget-libs) 开发工具链
|
|
36
|
+
|
|
37
|
+
欢迎社区贡献,如果你想为项目做出贡献可按照以下流程:
|
|
36
38
|
|
|
37
39
|
### 环境要求
|
|
38
40
|
|
|
@@ -41,12 +43,16 @@ https://unpkg.com/@forward-widget/danmu-universe
|
|
|
41
43
|
|
|
42
44
|
### 安装依赖
|
|
43
45
|
|
|
46
|
+
仓库根目录
|
|
47
|
+
|
|
44
48
|
```bash
|
|
45
49
|
pnpm install
|
|
46
50
|
```
|
|
47
51
|
|
|
48
52
|
### 开发模式
|
|
49
53
|
|
|
54
|
+
项目目录
|
|
55
|
+
|
|
50
56
|
```bash
|
|
51
57
|
pnpm dev
|
|
52
58
|
```
|
|
@@ -63,6 +69,10 @@ pnpm build
|
|
|
63
69
|
pnpm test
|
|
64
70
|
```
|
|
65
71
|
|
|
72
|
+
### 提交
|
|
73
|
+
|
|
74
|
+
在仓库根目录执行 `pnpm changeset` 创建 changeset 文件,同时使用标准的 Conventional Commits 提交代码
|
|
75
|
+
|
|
66
76
|
## 鸣谢
|
|
67
77
|
|
|
68
78
|
- [misaka_danmu_server](https://github.com/l429609201/misaka_danmu_server)
|
package/dist/danmu-universe.js
CHANGED
|
@@ -4047,13 +4047,16 @@ class Fetch {
|
|
|
4047
4047
|
}, s), r = storage.getJson(n);
|
|
4048
4048
|
if (r) return console.debug("fetch cache hit", n), Promise.resolve(r);
|
|
4049
4049
|
}
|
|
4050
|
-
let a = o ? void 0 : n, { timeout: u, schema: l,
|
|
4051
|
-
console.debug("fetch", t, a,
|
|
4052
|
-
|
|
4050
|
+
let a = o ? void 0 : n, { timeout: u, schema: l, params: c, ...d } = s, p = t;
|
|
4051
|
+
c && (p = `${t}?${url_parse.qs.stringify(c)}`), console.debug("\u2B06\uFE0F fetch", t, null != a ? a : "", {
|
|
4052
|
+
...d,
|
|
4053
|
+
params: c
|
|
4054
|
+
});
|
|
4055
|
+
let f = o ? Widget.http.get(p, d) : Widget.http.post(p, a, d);
|
|
4053
4056
|
return u && u > 0 ? Promise.race([
|
|
4054
|
-
|
|
4057
|
+
f,
|
|
4055
4058
|
this.createTimeoutPromise(u)
|
|
4056
|
-
]) :
|
|
4059
|
+
]) : f;
|
|
4057
4060
|
}
|
|
4058
4061
|
getCacheKey(e, t) {
|
|
4059
4062
|
var n;
|
|
@@ -4255,29 +4258,6 @@ class BaseScraper {
|
|
|
4255
4258
|
sleep(e) {
|
|
4256
4259
|
return new Promise((t)=>setTimeout(t, e));
|
|
4257
4260
|
}
|
|
4258
|
-
formatComments(e, t) {
|
|
4259
|
-
let n = new Set(), r = new Map();
|
|
4260
|
-
for (let i of e){
|
|
4261
|
-
if (!i) continue;
|
|
4262
|
-
let e = t(i);
|
|
4263
|
-
if (!e || n.has(e.id)) continue;
|
|
4264
|
-
n.add(e.id);
|
|
4265
|
-
let o = e.content, s = r.get(o);
|
|
4266
|
-
s ? (e.timestamp < s.item.timestamp && (s.item = e), s.count += 1) : r.set(o, {
|
|
4267
|
-
item: e,
|
|
4268
|
-
count: 1
|
|
4269
|
-
});
|
|
4270
|
-
}
|
|
4271
|
-
let i = [];
|
|
4272
|
-
return r.forEach((e)=>{
|
|
4273
|
-
let { item: t, count: n } = e, r = n > 1 ? `${t.content} \xd7 ${n}` : t.content;
|
|
4274
|
-
i.push({
|
|
4275
|
-
cid: t.id,
|
|
4276
|
-
p: `${t.timestamp.toFixed(2)},${t.mode},${t.color},[${this.providerName}]`,
|
|
4277
|
-
m: r
|
|
4278
|
-
});
|
|
4279
|
-
}), i;
|
|
4280
|
-
}
|
|
4281
4261
|
getEpisodeIndexFromTitle(e) {
|
|
4282
4262
|
if (!e) return null;
|
|
4283
4263
|
let t = /(?:第)?(\d+)(?:集|话)?$/.exec(e.trim());
|
|
@@ -4361,22 +4341,22 @@ class BilibiliScraper extends BaseScraper {
|
|
|
4361
4341
|
async getComments(e, t) {
|
|
4362
4342
|
var n;
|
|
4363
4343
|
let { aid: r, cid: i, seasonId: o } = null != (n = this.parseIdString(e)) ? n : {};
|
|
4364
|
-
if (!r || !i || !o) return
|
|
4344
|
+
if (!r || !i || !o) return null;
|
|
4365
4345
|
let s = await this.getPgcEpisodes(o);
|
|
4366
|
-
if (!(null == s ? void 0 : s.find((e)=>e.aid === parseInt(r) && e.cid === parseInt(i)))) return
|
|
4346
|
+
if (!(null == s ? void 0 : s.find((e)=>e.aid === parseInt(r) && e.cid === parseInt(i)))) return null;
|
|
4367
4347
|
let a = await this.fetchCommentsForCid(r, i, t);
|
|
4368
|
-
return
|
|
4348
|
+
return a ? a.map((e)=>{
|
|
4369
4349
|
var t, n, r;
|
|
4370
4350
|
if (!e.progress) return null;
|
|
4371
4351
|
let i = (null == (t = e.content) ? void 0 : t.toString().replace(/\0/g, "")) || "";
|
|
4372
4352
|
return i ? {
|
|
4373
|
-
id: e.id,
|
|
4353
|
+
id: e.id.toString(),
|
|
4374
4354
|
timestamp: e.progress / 1000.0,
|
|
4375
4355
|
mode: null != (n = e.mode) ? n : 1,
|
|
4376
4356
|
color: null != (r = e.color) ? r : 16777215,
|
|
4377
4357
|
content: i
|
|
4378
4358
|
} : null;
|
|
4379
|
-
});
|
|
4359
|
+
}) : null;
|
|
4380
4360
|
}
|
|
4381
4361
|
async getPgcEpisodes(e) {
|
|
4382
4362
|
var t;
|
|
@@ -4391,18 +4371,17 @@ class BilibiliScraper extends BaseScraper {
|
|
|
4391
4371
|
})).data) ? void 0 : t.result.episodes;
|
|
4392
4372
|
}
|
|
4393
4373
|
async fetchCommentsForCid(e, t, n) {
|
|
4394
|
-
let r = [];
|
|
4395
4374
|
try {
|
|
4396
|
-
let
|
|
4375
|
+
let r = await this.fetch.get(`https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=${t}&pid=${e}&segment_index=${n}`, {
|
|
4397
4376
|
base64Data: !0
|
|
4398
4377
|
});
|
|
4399
|
-
if (404 ===
|
|
4400
|
-
let
|
|
4401
|
-
|
|
4378
|
+
if (404 === r.statusCode || 304 === r.statusCode) return null;
|
|
4379
|
+
let i = this.DmSegMobileReply.decode(base64ToUint8Array(r.data));
|
|
4380
|
+
return console.log(i), i.elems;
|
|
4402
4381
|
} catch (r) {
|
|
4403
4382
|
console.error(`\u{83B7}\u{53D6}\u{5206}\u{6BB5} ${n} \u{5931}\u{8D25} (aid=${e}, cid=${t}): ${r}`);
|
|
4404
4383
|
}
|
|
4405
|
-
return
|
|
4384
|
+
return null;
|
|
4406
4385
|
}
|
|
4407
4386
|
constructor(){
|
|
4408
4387
|
super(), bilibili_define_property(this, "providerName", "bilibili"), bilibili_define_property(this, "idSchema", bilibiliIdSchema), bilibili_define_property(this, "DmSegMobileReply", dm_proto.biliproto.community.service.dm.v1.DmSegMobileReply), this.fetch.setHeaders({
|
|
@@ -5319,13 +5298,13 @@ class IqiyiScraper extends BaseScraper {
|
|
|
5319
5298
|
let a = await this.fetch.get(s, {
|
|
5320
5299
|
zlibMode: !0
|
|
5321
5300
|
}), u = this.xmlParser.parse(a.data), { success: l, data: c, error: d } = iqiyiCommentsResponseSchema.safeParse(u);
|
|
5322
|
-
return l ?
|
|
5301
|
+
return l ? c.map((e)=>{
|
|
5323
5302
|
let t = 16777215;
|
|
5324
5303
|
try {
|
|
5325
5304
|
t = parseInt(e.color, 16);
|
|
5326
5305
|
} catch (e) {}
|
|
5327
5306
|
return {
|
|
5328
|
-
id: e.contentId,
|
|
5307
|
+
id: e.contentId.toString(),
|
|
5329
5308
|
timestamp: e.showTime,
|
|
5330
5309
|
mode: 1,
|
|
5331
5310
|
color: t,
|
|
@@ -5378,8 +5357,7 @@ class IqiyiScraper extends BaseScraper {
|
|
|
5378
5357
|
entityId: t
|
|
5379
5358
|
}),
|
|
5380
5359
|
episodeTitle: e.title,
|
|
5381
|
-
episodeNumber: null != (p = this.getEpisodeIndexFromTitle(e.short_display_name)) ? p : h
|
|
5382
|
-
url: e.page_url
|
|
5360
|
+
episodeNumber: null != (p = this.getEpisodeIndexFromTitle(e.short_display_name)) ? p : h
|
|
5383
5361
|
}), h += 1));
|
|
5384
5362
|
}
|
|
5385
5363
|
}
|
|
@@ -5507,8 +5485,7 @@ class TencentScraper extends BaseScraper {
|
|
|
5507
5485
|
vid: e.vid
|
|
5508
5486
|
}),
|
|
5509
5487
|
episodeTitle: e.union_title && e.union_title !== e.title ? e.union_title : e.title,
|
|
5510
|
-
episodeNumber: r
|
|
5511
|
-
url: `https://v.qq.com/x/cover/${n.cid}/${e.vid}.html`
|
|
5488
|
+
episodeNumber: r
|
|
5512
5489
|
};
|
|
5513
5490
|
});
|
|
5514
5491
|
if (void 0 !== t) {
|
|
@@ -5552,13 +5529,13 @@ class TencentScraper extends BaseScraper {
|
|
|
5552
5529
|
let n = this.parseIdString(e);
|
|
5553
5530
|
if (!(null == n ? void 0 : n.vid)) return [];
|
|
5554
5531
|
let r = await this.internalGetComments(n.vid, t);
|
|
5555
|
-
return r && 0 !== r.length ?
|
|
5532
|
+
return r && 0 !== r.length ? r.map((e)=>{
|
|
5556
5533
|
let t = 1, n = 16777215;
|
|
5557
5534
|
if (e.content_style && (2 === e.content_style.position ? t = 5 : 3 === e.content_style.position && (t = 4), e.content_style.color)) try {
|
|
5558
5535
|
n = parseInt(e.content_style.color, 10);
|
|
5559
5536
|
} catch (e) {}
|
|
5560
5537
|
return {
|
|
5561
|
-
id: e.id,
|
|
5538
|
+
id: e.id.toString(),
|
|
5562
5539
|
timestamp: parseInt(e.time_offset, 10) / 1000.0,
|
|
5563
5540
|
mode: t,
|
|
5564
5541
|
color: n,
|
|
@@ -5707,8 +5684,7 @@ class YoukuScraper extends BaseScraper {
|
|
|
5707
5684
|
vid: e.id
|
|
5708
5685
|
}),
|
|
5709
5686
|
episodeTitle: e.title,
|
|
5710
|
-
episodeNumber: t + 1
|
|
5711
|
-
url: e.link
|
|
5687
|
+
episodeNumber: t + 1
|
|
5712
5688
|
}));
|
|
5713
5689
|
if (void 0 !== t) {
|
|
5714
5690
|
let e = a.find((e)=>e.episodeNumber === t);
|
|
@@ -5822,7 +5798,7 @@ class YoukuScraper extends BaseScraper {
|
|
|
5822
5798
|
})
|
|
5823
5799
|
})).data) || null == (u = l.data.result) ? void 0 : u.data.result) ? c : [];
|
|
5824
5800
|
if (console.log(`Youku: \u{83B7}\u{53D6}\u{5230}\u{5206}\u{6BB5} ${t} \u{7684}\u{5F39}\u{5E55} ${e.length} \u{6761}`), !e || 0 === e.length) return [];
|
|
5825
|
-
return
|
|
5801
|
+
return e.map((e)=>{
|
|
5826
5802
|
let t = 1, n = 16777215;
|
|
5827
5803
|
try {
|
|
5828
5804
|
let r = e.propertis;
|
|
@@ -5853,26 +5829,34 @@ class YoukuScraper extends BaseScraper {
|
|
|
5853
5829
|
].join("&")).toString().toLowerCase();
|
|
5854
5830
|
}
|
|
5855
5831
|
async ensureTokenCookie() {
|
|
5856
|
-
|
|
5857
|
-
|
|
5832
|
+
this.fetch.cookie = {};
|
|
5833
|
+
try {
|
|
5834
|
+
await this.fetch.get("https://log.mmstat.com/eg.js", {
|
|
5835
|
+
headers: {
|
|
5836
|
+
Cookie: "",
|
|
5837
|
+
"If-None-Match": ""
|
|
5838
|
+
}
|
|
5839
|
+
});
|
|
5858
5840
|
} catch (e) {
|
|
5859
5841
|
console.warn(`Youku: \u{65E0}\u{6CD5}\u{8FDE}\u{63A5}\u{5230} youku.com \u{83B7}\u{53D6} 'cna' cookie\u{3002}\u{9519}\u{8BEF}: ${e}`);
|
|
5860
5842
|
}
|
|
5861
|
-
|
|
5862
|
-
|
|
5843
|
+
try {
|
|
5844
|
+
await this.fetch.get("https://acs.youku.com/h5/mtop.com.youku.aplatform.weakget/1.0/?jsv=2.5.1&appKey=24679788");
|
|
5863
5845
|
} catch (e) {
|
|
5864
5846
|
console.error(`Youku: \u{65E0}\u{6CD5}\u{8FDE}\u{63A5}\u{5230} acs.youku.com \u{83B7}\u{53D6}\u{4EE4}\u{724C} cookie\u{3002}\u{5F39}\u{5E55}\u{83B7}\u{53D6}\u{5F88}\u{53EF}\u{80FD}\u{4F1A}\u{5931}\u{8D25}\u{3002}\u{9519}\u{8BEF}: ${e}`);
|
|
5865
5847
|
}
|
|
5866
5848
|
this.cna && this.token || console.warn(`Youku: \u{672A}\u{80FD}\u{83B7}\u{53D6}\u{5230}\u{5F39}\u{5E55}\u{7B7E}\u{540D}\u{6240}\u{9700}\u{7684}\u{5168}\u{90E8} cookie\u{3002} cna: '${this.cna}', token: '${this.token}'`);
|
|
5867
5849
|
}
|
|
5868
|
-
constructor(
|
|
5869
|
-
super(
|
|
5850
|
+
constructor(){
|
|
5851
|
+
super(), youku_define_property(this, "providerName", "youku"), youku_define_property(this, "idSchema", youkuIdSchema), youku_define_property(this, "EPISODE_BLACKLIST_KEYWORDS", [
|
|
5870
5852
|
"\u5F69\u86CB",
|
|
5871
5853
|
"\u52A0\u66F4",
|
|
5872
5854
|
"\u8D70\u5FC3",
|
|
5873
5855
|
"\u89E3\u5FE7",
|
|
5874
5856
|
"\u7EAF\u4EAB"
|
|
5875
|
-
])
|
|
5857
|
+
]), this.fetch.setHeaders({
|
|
5858
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
5859
|
+
});
|
|
5876
5860
|
}
|
|
5877
5861
|
}
|
|
5878
5862
|
function scrapers_define_property(e, t, n) {
|
|
@@ -5914,16 +5898,41 @@ class scrapers_Scraper {
|
|
|
5914
5898
|
}
|
|
5915
5899
|
async getSegmentWithTime() {
|
|
5916
5900
|
let e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
|
|
5917
|
-
for(var t = arguments.length,
|
|
5918
|
-
let
|
|
5919
|
-
for (let { provider: t, idString:
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5901
|
+
for(var t, n = arguments.length, r = Array(n > 1 ? n - 1 : 0), i = 1; i < n; i++)r[i - 1] = arguments[i];
|
|
5902
|
+
let o = [];
|
|
5903
|
+
for (let { provider: t, idString: n } of r)o.push((async ()=>{
|
|
5904
|
+
let r = await this.getSegmentsByProvider(t, n);
|
|
5905
|
+
if (!r.length) return null;
|
|
5906
|
+
let i = this.findSegmentAtTime(r, e);
|
|
5907
|
+
if (!i) return null;
|
|
5908
|
+
let o = this.scraperMap[t];
|
|
5909
|
+
return o ? {
|
|
5910
|
+
comments: await o.getComments(n, i.segmentId),
|
|
5911
|
+
provider: t
|
|
5912
|
+
} : null;
|
|
5925
5913
|
})());
|
|
5926
|
-
|
|
5914
|
+
let s = await Promise.all(o), a = new Map();
|
|
5915
|
+
for (let e of s)if (null == e || null == (t = e.comments) ? void 0 : t.length) for (let t of e.comments){
|
|
5916
|
+
if (!t) continue;
|
|
5917
|
+
let n = [
|
|
5918
|
+
t.mode,
|
|
5919
|
+
t.color,
|
|
5920
|
+
t.content
|
|
5921
|
+
].join("___"), r = a.get(n);
|
|
5922
|
+
r ? (t.timestamp < r.item.timestamp && (r.item = t), r.count += 1) : a.set(n, {
|
|
5923
|
+
item: t,
|
|
5924
|
+
count: 1,
|
|
5925
|
+
provider: e.provider
|
|
5926
|
+
});
|
|
5927
|
+
}
|
|
5928
|
+
let u = [];
|
|
5929
|
+
return a.forEach((e)=>{
|
|
5930
|
+
let { item: t, count: n, provider: r } = e, i = n > 1 ? `${t.content} \xd7 ${n}` : t.content;
|
|
5931
|
+
u.push({
|
|
5932
|
+
p: `${t.timestamp.toFixed(2)},${t.mode},${t.color},[${r}]`,
|
|
5933
|
+
m: i
|
|
5934
|
+
});
|
|
5935
|
+
}), u;
|
|
5927
5936
|
}
|
|
5928
5937
|
getDanmuWithSegmentTimeByVideoId(e, t) {
|
|
5929
5938
|
let n = e.split(",").map((e)=>{
|
|
@@ -5982,7 +5991,7 @@ WidgetMetadata = {
|
|
|
5982
5991
|
title: "\u901A\u7528\u5F39\u5E55",
|
|
5983
5992
|
description: "\u901A\u7528\u5F39\u5E55\u63D2\u4EF6\uFF0C\u652F\u6301\u817E\u8BAF\u3001\u4F18\u9177\u3001\u7231\u5947\u827A\u3001\u54D4\u54E9\u54D4\u54E9\u7B49\u5E73\u53F0",
|
|
5984
5993
|
author: "Baran",
|
|
5985
|
-
version: "0.0.
|
|
5994
|
+
version: "0.0.5",
|
|
5986
5995
|
site: "https://github.com/baranwang/forward-widgets/tree/main/packages/danmu-universe",
|
|
5987
5996
|
requiredVersion: "0.0.2",
|
|
5988
5997
|
modules: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forward-widget/danmu-universe",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/danmu-universe.js",
|
|
6
6
|
"exports": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"zod": "^4.0.17"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@forward-widget/libs": "^1.8.
|
|
23
|
-
"@forward-widget/rslib-plugin": "^1.8.
|
|
22
|
+
"@forward-widget/libs": "^1.8.4",
|
|
23
|
+
"@forward-widget/rslib-plugin": "^1.8.4",
|
|
24
24
|
"@rslib/core": "^0.12.4",
|
|
25
25
|
"@rstest/core": "^0.3.1",
|
|
26
26
|
"@types/crypto-js": "^4.2.2",
|