@dan-uni/dan-any 1.2.2 → 1.2.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.
Files changed (47) hide show
  1. package/README.md +1 -0
  2. package/dist/browser/17.min.js +2 -5
  3. package/dist/browser/705.min.js +77 -0
  4. package/dist/browser/plugins/bili.min.js +1 -0
  5. package/dist/browser/plugins/index.min.js +1 -1
  6. package/dist/browser/src/index.d.ts +1 -4
  7. package/dist/browser/src/plugins/bili/history-danmaku-fast-forward.d.ts +18 -0
  8. package/dist/browser/src/plugins/bili/index.d.ts +2 -0
  9. package/dist/browser/src/plugins/index.d.ts +1 -1
  10. package/dist/node/17.js +2 -5
  11. package/dist/node/705.js +77 -0
  12. package/dist/node/plugins/bili.js +1 -0
  13. package/dist/node/plugins/index.js +1 -1
  14. package/dist/node/src/index.d.ts +1 -4
  15. package/dist/node/src/plugins/bili/history-danmaku-fast-forward.d.ts +18 -0
  16. package/dist/node/src/plugins/bili/index.d.ts +2 -0
  17. package/dist/node/src/plugins/index.d.ts +1 -1
  18. package/dist/umd/index.umd.min.js +9 -7
  19. package/dist/umd/plugins/{bili-dedupe.umd.min.js → bili.umd.min.js} +4623 -12
  20. package/dist/umd/plugins/index.umd.min.js +4625 -14
  21. package/dist/umd/src/index.d.ts +1 -4
  22. package/dist/umd/src/plugins/bili/history-danmaku-fast-forward.d.ts +18 -0
  23. package/dist/umd/src/plugins/bili/index.d.ts +2 -0
  24. package/dist/umd/src/plugins/index.d.ts +1 -1
  25. package/package.json +4 -2
  26. package/rslib.config.ts +1 -1
  27. package/src/index.ts +1 -11
  28. package/src/plugins/bili/README.md +87 -0
  29. package/src/plugins/bili/history-danmaku-fast-forward.ts +86 -0
  30. package/src/plugins/bili/index.test.ts +129 -0
  31. package/src/plugins/bili/index.ts +2 -0
  32. package/src/plugins/index.ts +1 -1
  33. package/src/plugins/stats/README.md +44 -0
  34. package/src/plugins/stats/index.test.ts +1 -1
  35. package/dist/browser/157.min.js +0 -30
  36. package/dist/browser/plugins/bili-dedupe.min.js +0 -1
  37. package/dist/node/157.js +0 -30
  38. package/dist/node/plugins/bili-dedupe.js +0 -1
  39. package/src/plugins/bili-dedupe/index.test.ts +0 -43
  40. /package/dist/browser/src/plugins/{bili-dedupe/index.d.ts → bili/dedupe.d.ts} +0 -0
  41. /package/dist/browser/src/plugins/{bili-dedupe → bili}/index.test.d.ts +0 -0
  42. /package/dist/node/src/plugins/{bili-dedupe/index.d.ts → bili/dedupe.d.ts} +0 -0
  43. /package/dist/node/src/plugins/{bili-dedupe → bili}/index.test.d.ts +0 -0
  44. /package/dist/umd/plugins/{bili-dedupe.umd.min.js.LICENSE.txt → bili.umd.min.js.LICENSE.txt} +0 -0
  45. /package/dist/umd/src/plugins/{bili-dedupe/index.d.ts → bili/dedupe.d.ts} +0 -0
  46. /package/dist/umd/src/plugins/{bili-dedupe → bili}/index.test.d.ts +0 -0
  47. /package/src/plugins/{bili-dedupe/index.ts → bili/dedupe.ts} +0 -0
package/README.md CHANGED
@@ -29,6 +29,7 @@
29
29
  插件的使用方法参见对应路径下README.md
30
30
 
31
31
  - [dan-any-plugin-detaolu](https://github.com/ani-uni/danuni/tree/master/packages/dan-any-plugin-detaolu): 基于pakku.js的弹幕过滤器
32
+ - `src/plugins`下的插件 `bili`(B站弹幕相关) `stats`(统计相关),内部附有使用文档
32
33
 
33
34
  ## 特殊字段提示
34
35
 
@@ -11461,7 +11461,7 @@ __webpack_require__.d(platform_namespaceObject, {
11461
11461
  PlatformVideoSource: ()=>platform_PlatformVideoSource,
11462
11462
  PlatformVideoSources: ()=>PlatformVideoSources
11463
11463
  });
11464
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.2.2","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
11464
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.2.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
11465
11465
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
11466
11466
  const decimalToHex = (n)=>color_pad(n.toString(16));
11467
11467
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -12739,10 +12739,7 @@ class UniPool {
12739
12739
  if (false !== options.dedupe) options.dedupe = true;
12740
12740
  if (this.options.dedupe) this.dedupe();
12741
12741
  }
12742
- async pipe(fn) {
12743
- return fn(this);
12744
- }
12745
- pipeSync(fn) {
12742
+ pipe(fn) {
12746
12743
  return fn(this);
12747
12744
  }
12748
12745
  get shared() {
@@ -0,0 +1,77 @@
1
+ import { __webpack_require__ } from "./rslib-runtime.min.js";
2
+ import { DateTime } from "luxon";
3
+ import { UniPool, platform_PlatformVideoSource } from "./17.min.js";
4
+ var dedupe_namespaceObject = {};
5
+ __webpack_require__.r(dedupe_namespaceObject);
6
+ __webpack_require__.d(dedupe_namespaceObject, {
7
+ bili_dedupe: ()=>bili_dedupe,
8
+ to_bili_deduped: ()=>to_bili_deduped
9
+ });
10
+ var bili_namespaceObject = {};
11
+ __webpack_require__.r(bili_namespaceObject);
12
+ __webpack_require__.d(bili_namespaceObject, {
13
+ bili_dedupe: ()=>dedupe_namespaceObject,
14
+ bili_history_fast_forward: ()=>bili_history_fast_forward
15
+ });
16
+ function main(that) {
17
+ that.dans.forEach((d)=>{
18
+ if (d.platform !== platform_PlatformVideoSource.Bilibili) throw new Error('bili-dedupe: 仅支持B站(主站)的弹幕');
19
+ if (!d.extra.bili?.dmid) throw new Error('bili-dedupe: 弹幕缺少bili extra dmid字段');
20
+ });
21
+ const map = new Map();
22
+ that.dans.forEach((d)=>map.set(d.extra.bili.dmid, d));
23
+ return map;
24
+ }
25
+ function to_bili_deduped(that) {
26
+ const map = main(that);
27
+ return new UniPool([
28
+ ...map.values()
29
+ ], that.options, that.info);
30
+ }
31
+ function bili_dedupe(that) {
32
+ const map = main(that);
33
+ that.dans = [
34
+ ...map.values()
35
+ ];
36
+ }
37
+ function history_danmaku_fast_forward_main(that, query_history_date) {
38
+ const qhd = DateTime.fromFormat(query_history_date, 'yyyy-MM-dd', {
39
+ zone: 'Asia/Shanghai'
40
+ }).setZone('Asia/Shanghai');
41
+ if (!qhd.isValid) throw new Error('Invalid query_history_date');
42
+ const s = qhd.startOf('day');
43
+ const before = that.dans.filter((d)=>d.ctime < s.toJSDate());
44
+ if (0 === before.length) return {
45
+ earliest: null,
46
+ FastForward: [],
47
+ skip: [],
48
+ SpecificDate: qhd.toFormat('yyyy-MM-dd')
49
+ };
50
+ const earliestCtime = before.toSorted((a, b)=>a.ctime.getTime() - b.ctime.getTime())[0].ctime;
51
+ const earliestDate = DateTime.fromJSDate(earliestCtime).setZone('Asia/Shanghai').startOf('day');
52
+ const datesWithDanmaku = new Set();
53
+ for (const dan of before){
54
+ const dateStr = DateTime.fromJSDate(dan.ctime).setZone('Asia/Shanghai').toFormat('yyyy-MM-dd');
55
+ datesWithDanmaku.add(dateStr);
56
+ }
57
+ let current = earliestDate;
58
+ const allDates = [];
59
+ while(current < s){
60
+ allDates.push(current.toFormat('yyyy-MM-dd'));
61
+ current = current.plus({
62
+ days: 1
63
+ });
64
+ }
65
+ const FastForward = allDates.filter((d)=>datesWithDanmaku.has(d));
66
+ const skip = allDates.filter((d)=>!datesWithDanmaku.has(d));
67
+ return {
68
+ earliest: earliestDate.toFormat('yyyy-MM-dd'),
69
+ FastForward,
70
+ skip,
71
+ SpecificDate: qhd.toFormat('yyyy-MM-dd')
72
+ };
73
+ }
74
+ function bili_history_fast_forward(query_history_date) {
75
+ return (that)=>history_danmaku_fast_forward_main(that, query_history_date);
76
+ }
77
+ export { bili_history_fast_forward, bili_namespaceObject as bili, dedupe_namespaceObject as bili_dedupe };
@@ -0,0 +1 @@
1
+ export { bili_dedupe, bili_history_fast_forward } from "../705.min.js";
@@ -1,2 +1,2 @@
1
- export { bili_dedupe } from "../157.min.js";
1
+ export { bili } from "../705.min.js";
2
2
  export { stats } from "../898.min.js";
@@ -120,8 +120,6 @@ export type DM_format = 'danuni.json' | 'danuni.pb.bin' | 'bili.xml' | 'bili.pb.
120
120
  type shareItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'senderID' | 'platform' | 'SOID' | 'pool' | 'mode' | 'color'>>;
121
121
  type statItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'mode' | 'fontsize' | 'color' | 'senderID' | 'content' | 'weight' | 'pool' | 'platform'>>;
122
122
  type Stats<T extends keyof statItems> = Map<statItems[T], number>;
123
- type UniPoolPipe = (that: UniPool) => Promise<any>;
124
- type UniPoolPipeSync = (that: UniPool) => any;
125
123
  export interface Options {
126
124
  dedupe?: boolean;
127
125
  /**
@@ -145,8 +143,7 @@ export declare class UniPool {
145
143
  */
146
144
  fromConverted: boolean;
147
145
  });
148
- pipe<T extends (...args: any) => any = UniPoolPipe>(fn: T): Promise<ReturnType<T>>;
149
- pipeSync<T extends (...args: any) => any = UniPoolPipeSync>(fn: T): ReturnType<T>;
146
+ pipe<T extends (...args: any) => any>(fn: T): ReturnType<T>;
150
147
  /**
151
148
  * @deprecated 使用 `getShared` 代替
152
149
  */
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 注:该方法受BiliPlus全弹幕下载器启发
3
+ * 详情参考以下链接
4
+ * @see https://github.com/HengXin666/BiLiBiLi_DanMu_Crawling/issues/14
5
+ */
6
+ import type { UniPool } from '../..';
7
+ interface BiliHistoryDanmakuFastForwardResult {
8
+ earliest: string | null;
9
+ FastForward: string[];
10
+ skip: string[];
11
+ SpecificDate: string;
12
+ }
13
+ export declare function bili_history_fast_forward(
14
+ /**
15
+ * 请求api时使用的日期(UTC+8, yyyy-MM-dd)
16
+ */
17
+ query_history_date: string): (that: UniPool) => BiliHistoryDanmakuFastForwardResult;
18
+ export {};
@@ -0,0 +1,2 @@
1
+ export * as bili_dedupe from './dedupe';
2
+ export { bili_history_fast_forward } from './history-danmaku-fast-forward';
@@ -1,2 +1,2 @@
1
- export * as bili_dedupe from './bili-dedupe';
1
+ export * as bili from './bili';
2
2
  export * as stats from './stats';
package/dist/node/17.js CHANGED
@@ -39,7 +39,7 @@ __webpack_require__.d(platform_namespaceObject, {
39
39
  PlatformVideoSource: ()=>platform_PlatformVideoSource,
40
40
  PlatformVideoSources: ()=>PlatformVideoSources
41
41
  });
42
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.2.2","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
42
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.2.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
43
43
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
44
44
  const decimalToHex = (n)=>color_pad(n.toString(16));
45
45
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -1314,10 +1314,7 @@ class UniPool {
1314
1314
  if (false !== options.dedupe) options.dedupe = true;
1315
1315
  if (this.options.dedupe) this.dedupe();
1316
1316
  }
1317
- async pipe(fn) {
1318
- return fn(this);
1319
- }
1320
- pipeSync(fn) {
1317
+ pipe(fn) {
1321
1318
  return fn(this);
1322
1319
  }
1323
1320
  get shared() {
@@ -0,0 +1,77 @@
1
+ import { __webpack_require__ } from "./rslib-runtime.js";
2
+ import { DateTime } from "luxon";
3
+ import { UniPool, platform_PlatformVideoSource } from "./17.js";
4
+ var dedupe_namespaceObject = {};
5
+ __webpack_require__.r(dedupe_namespaceObject);
6
+ __webpack_require__.d(dedupe_namespaceObject, {
7
+ bili_dedupe: ()=>bili_dedupe,
8
+ to_bili_deduped: ()=>to_bili_deduped
9
+ });
10
+ var bili_namespaceObject = {};
11
+ __webpack_require__.r(bili_namespaceObject);
12
+ __webpack_require__.d(bili_namespaceObject, {
13
+ bili_dedupe: ()=>dedupe_namespaceObject,
14
+ bili_history_fast_forward: ()=>bili_history_fast_forward
15
+ });
16
+ function main(that) {
17
+ that.dans.forEach((d)=>{
18
+ if (d.platform !== platform_PlatformVideoSource.Bilibili) throw new Error('bili-dedupe: 仅支持B站(主站)的弹幕');
19
+ if (!d.extra.bili?.dmid) throw new Error('bili-dedupe: 弹幕缺少bili extra dmid字段');
20
+ });
21
+ const map = new Map();
22
+ that.dans.forEach((d)=>map.set(d.extra.bili.dmid, d));
23
+ return map;
24
+ }
25
+ function to_bili_deduped(that) {
26
+ const map = main(that);
27
+ return new UniPool([
28
+ ...map.values()
29
+ ], that.options, that.info);
30
+ }
31
+ function bili_dedupe(that) {
32
+ const map = main(that);
33
+ that.dans = [
34
+ ...map.values()
35
+ ];
36
+ }
37
+ function history_danmaku_fast_forward_main(that, query_history_date) {
38
+ const qhd = DateTime.fromFormat(query_history_date, 'yyyy-MM-dd', {
39
+ zone: 'Asia/Shanghai'
40
+ }).setZone('Asia/Shanghai');
41
+ if (!qhd.isValid) throw new Error('Invalid query_history_date');
42
+ const s = qhd.startOf('day');
43
+ const before = that.dans.filter((d)=>d.ctime < s.toJSDate());
44
+ if (0 === before.length) return {
45
+ earliest: null,
46
+ FastForward: [],
47
+ skip: [],
48
+ SpecificDate: qhd.toFormat('yyyy-MM-dd')
49
+ };
50
+ const earliestCtime = before.toSorted((a, b)=>a.ctime.getTime() - b.ctime.getTime())[0].ctime;
51
+ const earliestDate = DateTime.fromJSDate(earliestCtime).setZone('Asia/Shanghai').startOf('day');
52
+ const datesWithDanmaku = new Set();
53
+ for (const dan of before){
54
+ const dateStr = DateTime.fromJSDate(dan.ctime).setZone('Asia/Shanghai').toFormat('yyyy-MM-dd');
55
+ datesWithDanmaku.add(dateStr);
56
+ }
57
+ let current = earliestDate;
58
+ const allDates = [];
59
+ while(current < s){
60
+ allDates.push(current.toFormat('yyyy-MM-dd'));
61
+ current = current.plus({
62
+ days: 1
63
+ });
64
+ }
65
+ const FastForward = allDates.filter((d)=>datesWithDanmaku.has(d));
66
+ const skip = allDates.filter((d)=>!datesWithDanmaku.has(d));
67
+ return {
68
+ earliest: earliestDate.toFormat('yyyy-MM-dd'),
69
+ FastForward,
70
+ skip,
71
+ SpecificDate: qhd.toFormat('yyyy-MM-dd')
72
+ };
73
+ }
74
+ function bili_history_fast_forward(query_history_date) {
75
+ return (that)=>history_danmaku_fast_forward_main(that, query_history_date);
76
+ }
77
+ export { bili_history_fast_forward, bili_namespaceObject as bili, dedupe_namespaceObject as bili_dedupe };
@@ -0,0 +1 @@
1
+ export { bili_dedupe, bili_history_fast_forward } from "../705.js";
@@ -1,2 +1,2 @@
1
- export { bili_dedupe } from "../157.js";
1
+ export { bili } from "../705.js";
2
2
  export { stats } from "../898.js";
@@ -120,8 +120,6 @@ export type DM_format = 'danuni.json' | 'danuni.pb.bin' | 'bili.xml' | 'bili.pb.
120
120
  type shareItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'senderID' | 'platform' | 'SOID' | 'pool' | 'mode' | 'color'>>;
121
121
  type statItems = Partial<Pick<UniDMTools.UniDMObj, 'SOID' | 'mode' | 'fontsize' | 'color' | 'senderID' | 'content' | 'weight' | 'pool' | 'platform'>>;
122
122
  type Stats<T extends keyof statItems> = Map<statItems[T], number>;
123
- type UniPoolPipe = (that: UniPool) => Promise<any>;
124
- type UniPoolPipeSync = (that: UniPool) => any;
125
123
  export interface Options {
126
124
  dedupe?: boolean;
127
125
  /**
@@ -145,8 +143,7 @@ export declare class UniPool {
145
143
  */
146
144
  fromConverted: boolean;
147
145
  });
148
- pipe<T extends (...args: any) => any = UniPoolPipe>(fn: T): Promise<ReturnType<T>>;
149
- pipeSync<T extends (...args: any) => any = UniPoolPipeSync>(fn: T): ReturnType<T>;
146
+ pipe<T extends (...args: any) => any>(fn: T): ReturnType<T>;
150
147
  /**
151
148
  * @deprecated 使用 `getShared` 代替
152
149
  */
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 注:该方法受BiliPlus全弹幕下载器启发
3
+ * 详情参考以下链接
4
+ * @see https://github.com/HengXin666/BiLiBiLi_DanMu_Crawling/issues/14
5
+ */
6
+ import type { UniPool } from '../..';
7
+ interface BiliHistoryDanmakuFastForwardResult {
8
+ earliest: string | null;
9
+ FastForward: string[];
10
+ skip: string[];
11
+ SpecificDate: string;
12
+ }
13
+ export declare function bili_history_fast_forward(
14
+ /**
15
+ * 请求api时使用的日期(UTC+8, yyyy-MM-dd)
16
+ */
17
+ query_history_date: string): (that: UniPool) => BiliHistoryDanmakuFastForwardResult;
18
+ export {};
@@ -0,0 +1,2 @@
1
+ export * as bili_dedupe from './dedupe';
2
+ export { bili_history_fast_forward } from './history-danmaku-fast-forward';
@@ -1,2 +1,2 @@
1
- export * as bili_dedupe from './bili-dedupe';
1
+ export * as bili from './bili';
2
2
  export * as stats from './stats';
@@ -15107,11 +15107,11 @@ and limitations under the License.
15107
15107
  },
15108
15108
  num_dec: {
15109
15109
  regex: /&#([0-9]{1,7});/g,
15110
- val: (_, str)=>String.fromCodePoint(Number.parseInt(str, 10))
15110
+ val: (_, str)=>fromCodePoint(str, 10, "&#")
15111
15111
  },
15112
15112
  num_hex: {
15113
15113
  regex: /&#x([0-9a-fA-F]{1,6});/g,
15114
- val: (_, str)=>String.fromCodePoint(Number.parseInt(str, 16))
15114
+ val: (_, str)=>fromCodePoint(str, 16, "&#x")
15115
15115
  }
15116
15116
  };
15117
15117
  this.addExternalEntities = addExternalEntities;
@@ -15487,6 +15487,11 @@ and limitations under the License.
15487
15487
  if (isExist(val)) return val;
15488
15488
  return '';
15489
15489
  }
15490
+ function fromCodePoint(str, base, prefix) {
15491
+ const codePoint = Number.parseInt(str, base);
15492
+ if (codePoint >= 0 && codePoint <= 0x10FFFF) return String.fromCodePoint(codePoint);
15493
+ return prefix + str + ";";
15494
+ }
15490
15495
  const node2json_METADATA_SYMBOL = XmlNode.getMetaDataSymbol();
15491
15496
  function prettify(node, options) {
15492
15497
  return node2json_compress(node, options);
@@ -21043,7 +21048,7 @@ and limitations under the License.
21043
21048
  function timestamp_timestampMs(timestamp) {
21044
21049
  return 1000 * Number(timestamp.seconds) + Math.round(timestamp.nanos / 1000000);
21045
21050
  }
21046
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.2.2","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21051
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.2.5","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21047
21052
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
21048
21053
  const decimalToHex = (n)=>color_pad(n.toString(16));
21049
21054
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -24492,10 +24497,7 @@ and limitations under the License.
24492
24497
  if (false !== options.dedupe) options.dedupe = true;
24493
24498
  if (this.options.dedupe) this.dedupe();
24494
24499
  }
24495
- async pipe(fn) {
24496
- return fn(this);
24497
- }
24498
- pipeSync(fn) {
24500
+ pipe(fn) {
24499
24501
  return fn(this);
24500
24502
  }
24501
24503
  get shared() {