@dan-uni/dan-any 1.2.7 → 1.3.3

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 (46) hide show
  1. package/README.md +1 -0
  2. package/buf.gen.yaml +4 -2
  3. package/buf.yaml +12 -0
  4. package/dist/browser/index.min.js +13384 -1
  5. package/dist/browser/plugins/bili.min.js +77 -1
  6. package/dist/browser/plugins/index.min.js +2 -2
  7. package/dist/browser/plugins/stats.min.js +10 -1
  8. package/dist/browser/rslib-runtime.min.js +5 -5
  9. package/dist/browser/src/index.d.ts +10 -7
  10. package/dist/browser/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
  11. package/dist/browser/src/proto/gen/{danuni_pb.d.ts → danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
  12. package/dist/browser/src/utils/fileParser.d.ts +3 -0
  13. package/dist/node/index.js +1959 -1
  14. package/dist/node/plugins/bili.js +77 -1
  15. package/dist/node/plugins/index.js +2 -2
  16. package/dist/node/plugins/stats.js +10 -1
  17. package/dist/node/rslib-runtime.js +5 -5
  18. package/dist/node/src/index.d.ts +10 -7
  19. package/dist/node/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
  20. package/dist/{umd/src/proto/gen/danuni_pb.d.ts → node/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
  21. package/dist/node/src/utils/fileParser.d.ts +3 -0
  22. package/dist/umd/index.umd.min.js +1146 -336
  23. package/dist/umd/plugins/bili.umd.min.js +1143 -334
  24. package/dist/umd/plugins/index.umd.min.js +1143 -334
  25. package/dist/umd/src/index.d.ts +10 -7
  26. package/dist/umd/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
  27. package/dist/{node/src/proto/gen/danuni_pb.d.ts → umd/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
  28. package/dist/umd/src/utils/fileParser.d.ts +3 -0
  29. package/package.json +5 -7
  30. package/src/index.test.ts +23 -1
  31. package/src/index.ts +153 -59
  32. package/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.ts +104 -104
  33. package/src/proto/gen/danuni/danmaku/v1/danmaku_pb.ts +223 -0
  34. package/src/proto/src/danuni/danmaku/v1/danmaku.proto +52 -0
  35. package/src/utils/dm-gen.ts +1 -1
  36. package/src/utils/fileParser.ts +37 -0
  37. package/dist/browser/17.min.js +0 -13299
  38. package/dist/browser/705.min.js +0 -77
  39. package/dist/browser/898.min.js +0 -10
  40. package/dist/node/17.js +0 -1874
  41. package/dist/node/705.js +0 -77
  42. package/dist/node/898.js +0 -10
  43. package/src/proto/gen/danuni_pb.ts +0 -219
  44. package/src/proto/src/danuni.proto +0 -50
  45. /package/dist/browser/{17.min.js.LICENSE.txt → index.min.js.LICENSE.txt} +0 -0
  46. /package/src/proto/src/{bili → bilibili/community/service/dm/v1}/dm.proto +0 -0
@@ -1 +1,77 @@
1
- export { bili_dedupe, bili_history_fast_forward } from "../705.min.js";
1
+ import { __webpack_require__ } from "../rslib-runtime.min.js";
2
+ import { DateTime } from "luxon";
3
+ import { UniPool, platform_PlatformVideoSource } from "../index.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 };
@@ -1,2 +1,2 @@
1
- export { bili } from "../705.min.js";
2
- export { stats } from "../898.min.js";
1
+ export { bili } from "./bili.min.js";
2
+ export { stats } from "./stats.min.js";
@@ -1 +1,10 @@
1
- export { getLatestDan } from "../898.min.js";
1
+ import { __webpack_require__ } from "../rslib-runtime.min.js";
2
+ var stats_namespaceObject = {};
3
+ __webpack_require__.r(stats_namespaceObject);
4
+ __webpack_require__.d(stats_namespaceObject, {
5
+ getLatestDan: ()=>getLatestDan
6
+ });
7
+ function getLatestDan(that) {
8
+ return 0 === that.dans.length ? null : that.dans.reduce((latest, current)=>current.ctime > latest.ctime ? current : latest);
9
+ }
10
+ export { getLatestDan, stats_namespaceObject as stats };
@@ -10,11 +10,6 @@ function __webpack_require__(moduleId) {
10
10
  return module.exports;
11
11
  }
12
12
  __webpack_require__.m = __webpack_modules__;
13
- (()=>{
14
- __webpack_require__.add = function(modules) {
15
- Object.assign(__webpack_require__.m, modules);
16
- };
17
- })();
18
13
  (()=>{
19
14
  __webpack_require__.d = (exports, definition)=>{
20
15
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
@@ -23,6 +18,11 @@ __webpack_require__.m = __webpack_modules__;
23
18
  });
24
19
  };
25
20
  })();
21
+ (()=>{
22
+ __webpack_require__.add = function(modules) {
23
+ Object.assign(__webpack_require__.m, modules);
24
+ };
25
+ })();
26
26
  (()=>{
27
27
  __webpack_require__.g = (()=>{
28
28
  if ('object' == typeof globalThis) return globalThis;
@@ -1,6 +1,6 @@
1
1
  import 'reflect-metadata/lite';
2
2
  import type { Options as AssGenOptions, CanvasCtx } from './ass-gen';
3
- import type { CommandDm as DM_JSON_BiliCommandGrpc } from './proto/gen/bili/dm_pb';
3
+ import type { CommandDm as DM_JSON_BiliCommandGrpc } from './proto/gen/bilibili/community/service/dm/v1/dm_pb';
4
4
  import { UniDM } from './utils/dm-gen';
5
5
  import * as UniDMTools from './utils/dm-gen';
6
6
  import * as UniIDTools from './utils/id-gen';
@@ -10,6 +10,7 @@ interface DanUniConvertTip {
10
10
  version: string;
11
11
  data?: string;
12
12
  }
13
+ export type DM_JSON_DanuniMin = Partial<UniDMTools.UniDMObj>[];
13
14
  export interface DM_XML_Bili {
14
15
  i: {
15
16
  chatserver: string;
@@ -118,10 +119,11 @@ export interface DM_JSON_DDPlay {
118
119
  }
119
120
  export declare enum DM_format {
120
121
  DanuniJson = "danuni.json",
121
- DanuniPbBin = "danuni.pb.bin",
122
+ DanuniMinJson = "danuni.min.json",
123
+ DanuniPbBin = "danuni.binpb",
122
124
  BiliXml = "bili.xml",
123
- BiliPbBin = "bili.pb.bin",
124
- BiliCmdPbBin = "bili.cmd.pb.bin",
125
+ BiliPbBin = "bili.binpb",
126
+ BiliCmdPbBin = "bili.cmd.binpb",
125
127
  BiliUpJson = "bili.up.json",
126
128
  DplayerJson = "dplayer.json",
127
129
  ArtplayerJson = "artplayer.json",
@@ -199,19 +201,20 @@ export declare class UniPool {
199
201
  minify(): (Partial<UniDMTools.UniDMObj> & Pick<UniDMTools.UniDMObj, "SOID">)[];
200
202
  static import(file: unknown, options?: Options,
201
203
  /**
202
- * 加载指定解析模块,为空则全选
204
+ * 加载指定解析模块,为空则全选,为字符串则视为文件名解析加载模块
203
205
  */
204
- mod?: ('json' | 'str' | 'bin')[]): {
206
+ mod?: string | ('json' | 'str' | 'bin')[]): {
205
207
  pool: UniPool;
206
208
  fmt: DM_format;
207
209
  };
208
- convert2(format: DM_format, continue_on_error?: boolean): string | Uint8Array<ArrayBuffer> | UniDM[] | (DM_JSON_Dplayer & {
210
+ convert2(format: DM_format, continue_on_error?: boolean): string | Uint8Array<ArrayBuffer> | UniDM[] | (Partial<UniDMTools.UniDMObj> & Pick<UniDMTools.UniDMObj, "SOID">)[] | (DM_JSON_Dplayer & {
209
211
  danuni?: DanUniConvertTip;
210
212
  }) | (DM_JSON_Artplayer & {
211
213
  danuni?: DanUniConvertTip;
212
214
  }) | (DM_JSON_DDPlay & {
213
215
  danuni?: DanUniConvertTip;
214
216
  });
217
+ static fromMin(json: DM_JSON_DanuniMin, options?: Options): UniPool;
215
218
  static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
216
219
  /**
217
220
  * 转为 protobuf 二进制
@@ -1,9 +1,9 @@
1
1
  import type { GenEnum, GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
2
2
  import type { Message } from "@bufbuild/protobuf";
3
3
  /**
4
- * Describes the file bili/dm.proto.
4
+ * Describes the file bilibili/community/service/dm/v1/dm.proto.
5
5
  */
6
- export declare const file_bili_dm: GenFile;
6
+ export declare const file_bilibili_community_service_dm_v1_dm: GenFile;
7
7
  /**
8
8
  * @generated from message bilibili.community.service.dm.v1.Avatar
9
9
  */
@@ -2,39 +2,39 @@ import type { GenEnum, GenFile, GenMessage, GenService } from "@bufbuild/protobu
2
2
  import type { Timestamp } from "@bufbuild/protobuf/wkt";
3
3
  import type { Message } from "@bufbuild/protobuf";
4
4
  /**
5
- * Describes the file danuni.proto.
5
+ * Describes the file danuni/danmaku/v1/danmaku.proto.
6
6
  */
7
- export declare const file_danuni: GenFile;
7
+ export declare const file_danuni_danmaku_v1_danmaku: GenFile;
8
8
  /**
9
- * @generated from message danuni.danmaku.v1.listDanReq
9
+ * @generated from message danuni.danmaku.v1.ListDanRequest
10
10
  */
11
- export type listDanReq = Message<"danuni.danmaku.v1.listDanReq"> & {
11
+ export type ListDanRequest = Message<"danuni.danmaku.v1.ListDanRequest"> & {
12
12
  /**
13
- * @generated from field: string ID = 1;
13
+ * @generated from field: string id = 1;
14
14
  */
15
- ID: string;
15
+ id: string;
16
16
  /**
17
17
  * @generated from field: optional int32 seg = 2;
18
18
  */
19
19
  seg?: number;
20
20
  };
21
21
  /**
22
- * Describes the message danuni.danmaku.v1.listDanReq.
23
- * Use `create(listDanReqSchema)` to create a new message.
22
+ * Describes the message danuni.danmaku.v1.ListDanRequest.
23
+ * Use `create(ListDanRequestSchema)` to create a new message.
24
24
  */
25
- export declare const listDanReqSchema: GenMessage<listDanReq>;
25
+ export declare const ListDanRequestSchema: GenMessage<ListDanRequest>;
26
26
  /**
27
27
  * @generated from message danuni.danmaku.v1.Danmaku
28
28
  */
29
29
  export type Danmaku = Message<"danuni.danmaku.v1.Danmaku"> & {
30
30
  /**
31
- * @generated from field: string SOID = 1;
31
+ * @generated from field: string soid = 1 [json_name = "SOID"];
32
32
  */
33
- SOID: string;
33
+ soid: string;
34
34
  /**
35
- * @generated from field: string DMID = 2;
35
+ * @generated from field: string dmid = 2 [json_name = "DMID"];
36
36
  */
37
- DMID: string;
37
+ dmid: string;
38
38
  /**
39
39
  * @generated from field: int32 progress = 3;
40
40
  */
@@ -52,9 +52,9 @@ export type Danmaku = Message<"danuni.danmaku.v1.Danmaku"> & {
52
52
  */
53
53
  color: number;
54
54
  /**
55
- * @generated from field: string senderID = 7;
55
+ * @generated from field: string sender_id = 7 [json_name = "senderID"];
56
56
  */
57
- senderID: string;
57
+ senderId: string;
58
58
  /**
59
59
  * @generated from field: string content = 8;
60
60
  */
@@ -90,68 +90,72 @@ export type Danmaku = Message<"danuni.danmaku.v1.Danmaku"> & {
90
90
  */
91
91
  export declare const DanmakuSchema: GenMessage<Danmaku>;
92
92
  /**
93
- * @generated from message danuni.danmaku.v1.DanmakuReply
93
+ * @generated from message danuni.danmaku.v1.ListDanResponse
94
94
  */
95
- export type DanmakuReply = Message<"danuni.danmaku.v1.DanmakuReply"> & {
95
+ export type ListDanResponse = Message<"danuni.danmaku.v1.ListDanResponse"> & {
96
96
  /**
97
97
  * @generated from field: repeated danuni.danmaku.v1.Danmaku danmakus = 1;
98
98
  */
99
99
  danmakus: Danmaku[];
100
100
  };
101
101
  /**
102
- * Describes the message danuni.danmaku.v1.DanmakuReply.
103
- * Use `create(DanmakuReplySchema)` to create a new message.
102
+ * Describes the message danuni.danmaku.v1.ListDanResponse.
103
+ * Use `create(ListDanResponseSchema)` to create a new message.
104
104
  */
105
- export declare const DanmakuReplySchema: GenMessage<DanmakuReply>;
105
+ export declare const ListDanResponseSchema: GenMessage<ListDanResponse>;
106
106
  /**
107
+ * 此处作为数字应与danuni库相应类型一一对应
108
+ *
107
109
  * @generated from enum danuni.danmaku.v1.Mode
108
110
  */
109
111
  export declare enum Mode {
110
112
  /**
111
- * @generated from enum value: Normal = 0;
113
+ * @generated from enum value: MODE_NORMAL_UNSPECIFIED = 0;
112
114
  */
113
- Normal = 0,
115
+ NORMAL_UNSPECIFIED = 0,
114
116
  /**
115
- * @generated from enum value: Bottom = 1;
117
+ * @generated from enum value: MODE_BOTTOM = 1;
116
118
  */
117
- Bottom = 1,
119
+ BOTTOM = 1,
118
120
  /**
119
- * @generated from enum value: Top = 2;
121
+ * @generated from enum value: MODE_TOP = 2;
120
122
  */
121
- Top = 2,
123
+ TOP = 2,
122
124
  /**
123
- * @generated from enum value: Reverse = 3;
125
+ * @generated from enum value: MODE_REVERSE = 3;
124
126
  */
125
- Reverse = 3,
127
+ REVERSE = 3,
126
128
  /**
127
- * @generated from enum value: Ext = 4;
129
+ * @generated from enum value: MODE_EXT = 4;
128
130
  */
129
- Ext = 4
131
+ EXT = 4
130
132
  }
131
133
  /**
132
134
  * Describes the enum danuni.danmaku.v1.Mode.
133
135
  */
134
136
  export declare const ModeSchema: GenEnum<Mode>;
135
137
  /**
138
+ * 此处作为数字应与danuni库相应类型一一对应
139
+ *
136
140
  * @generated from enum danuni.danmaku.v1.Pool
137
141
  */
138
142
  export declare enum Pool {
139
143
  /**
140
- * @generated from enum value: Def = 0;
144
+ * @generated from enum value: POOL_DEF_UNSPECIFIED = 0;
141
145
  */
142
- Def = 0,
146
+ DEF_UNSPECIFIED = 0,
143
147
  /**
144
- * @generated from enum value: Sub = 1;
148
+ * @generated from enum value: POOL_SUB = 1;
145
149
  */
146
- Sub = 1,
150
+ SUB = 1,
147
151
  /**
148
- * @generated from enum value: Adv = 2;
152
+ * @generated from enum value: POOL_ADV = 2;
149
153
  */
150
- Adv = 2,
154
+ ADV = 2,
151
155
  /**
152
- * @generated from enum value: Ix = 3;
156
+ * @generated from enum value: POOL_IX = 3;
153
157
  */
154
- Ix = 3
158
+ IX = 3
155
159
  }
156
160
  /**
157
161
  * Describes the enum danuni.danmaku.v1.Pool.
@@ -162,11 +166,11 @@ export declare const PoolSchema: GenEnum<Pool>;
162
166
  */
163
167
  export declare const DanmakuService: GenService<{
164
168
  /**
165
- * @generated from rpc danuni.danmaku.v1.DanmakuService.listDan
169
+ * @generated from rpc danuni.danmaku.v1.DanmakuService.ListDan
166
170
  */
167
171
  listDan: {
168
172
  methodKind: "unary";
169
- input: typeof listDanReqSchema;
170
- output: typeof DanmakuReplySchema;
173
+ input: typeof ListDanRequestSchema;
174
+ output: typeof ListDanResponseSchema;
171
175
  };
172
176
  }>;
@@ -0,0 +1,3 @@
1
+ export declare function fileParser(file: unknown, mod: 'bin'): ArrayBuffer | Uint8Array;
2
+ export declare function fileParser(file: unknown, mod: 'string'): string;
3
+ export declare function fileParser<T extends object>(file: unknown, mod: 'json'): T;