@dan-uni/dan-any 1.2.5 → 1.3.0
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/buf.gen.yaml +4 -2
- package/buf.yaml +12 -0
- package/dist/browser/17.min.js +44 -25
- package/dist/browser/index.min.js +1 -1
- package/dist/browser/src/index.d.ts +15 -3
- package/dist/browser/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
- package/dist/{umd/src/proto/gen/danuni_pb.d.ts → browser/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
- package/dist/node/17.js +44 -25
- package/dist/node/index.js +1 -1
- package/dist/node/src/index.d.ts +15 -3
- package/dist/{umd/src/proto/gen/bili → node/src/proto/gen/bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
- package/dist/{browser/src/proto/gen/danuni_pb.d.ts → node/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
- package/dist/umd/index.umd.min.js +124 -52
- package/dist/umd/plugins/bili.umd.min.js +109 -52
- package/dist/umd/plugins/index.umd.min.js +109 -52
- package/dist/umd/src/index.d.ts +15 -3
- package/dist/{node/src/proto/gen/bili → umd/src/proto/gen/bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
- package/dist/{node/src/proto/gen/danuni_pb.d.ts → umd/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
- package/package.json +3 -3
- package/src/index.test.ts +1 -1
- package/src/index.ts +45 -34
- package/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.ts +104 -104
- package/src/proto/gen/danuni/danmaku/v1/danmaku_pb.ts +223 -0
- package/src/proto/src/danuni/danmaku/v1/danmaku.proto +52 -0
- package/src/utils/dm-gen.ts +2 -2
- package/src/proto/gen/danuni_pb.ts +0 -219
- package/src/proto/src/danuni.proto +0 -50
- /package/src/proto/src/{bili → bilibili/community/service/dm/v1}/dm.proto +0 -0
|
@@ -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
|
|
7
|
+
export declare const file_danuni_danmaku_v1_danmaku: GenFile;
|
|
8
8
|
/**
|
|
9
|
-
* @generated from message danuni.danmaku.v1.
|
|
9
|
+
* @generated from message danuni.danmaku.v1.ListDanRequest
|
|
10
10
|
*/
|
|
11
|
-
export type
|
|
11
|
+
export type ListDanRequest = Message<"danuni.danmaku.v1.ListDanRequest"> & {
|
|
12
12
|
/**
|
|
13
|
-
* @generated from field: string
|
|
13
|
+
* @generated from field: string id = 1;
|
|
14
14
|
*/
|
|
15
|
-
|
|
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.
|
|
23
|
-
* Use `create(
|
|
22
|
+
* Describes the message danuni.danmaku.v1.ListDanRequest.
|
|
23
|
+
* Use `create(ListDanRequestSchema)` to create a new message.
|
|
24
24
|
*/
|
|
25
|
-
export declare const
|
|
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
|
|
31
|
+
* @generated from field: string soid = 1 [json_name = "SOID"];
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
soid: string;
|
|
34
34
|
/**
|
|
35
|
-
* @generated from field: string
|
|
35
|
+
* @generated from field: string dmid = 2 [json_name = "DMID"];
|
|
36
36
|
*/
|
|
37
|
-
|
|
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
|
|
55
|
+
* @generated from field: string sender_id = 7 [json_name = "senderID"];
|
|
56
56
|
*/
|
|
57
|
-
|
|
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.
|
|
93
|
+
* @generated from message danuni.danmaku.v1.ListDanResponse
|
|
94
94
|
*/
|
|
95
|
-
export type
|
|
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.
|
|
103
|
-
* Use `create(
|
|
102
|
+
* Describes the message danuni.danmaku.v1.ListDanResponse.
|
|
103
|
+
* Use `create(ListDanResponseSchema)` to create a new message.
|
|
104
104
|
*/
|
|
105
|
-
export declare const
|
|
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:
|
|
113
|
+
* @generated from enum value: MODE_NORMAL_UNSPECIFIED = 0;
|
|
112
114
|
*/
|
|
113
|
-
|
|
115
|
+
NORMAL_UNSPECIFIED = 0,
|
|
114
116
|
/**
|
|
115
|
-
* @generated from enum value:
|
|
117
|
+
* @generated from enum value: MODE_BOTTOM = 1;
|
|
116
118
|
*/
|
|
117
|
-
|
|
119
|
+
BOTTOM = 1,
|
|
118
120
|
/**
|
|
119
|
-
* @generated from enum value:
|
|
121
|
+
* @generated from enum value: MODE_TOP = 2;
|
|
120
122
|
*/
|
|
121
|
-
|
|
123
|
+
TOP = 2,
|
|
122
124
|
/**
|
|
123
|
-
* @generated from enum value:
|
|
125
|
+
* @generated from enum value: MODE_REVERSE = 3;
|
|
124
126
|
*/
|
|
125
|
-
|
|
127
|
+
REVERSE = 3,
|
|
126
128
|
/**
|
|
127
|
-
* @generated from enum value:
|
|
129
|
+
* @generated from enum value: MODE_EXT = 4;
|
|
128
130
|
*/
|
|
129
|
-
|
|
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:
|
|
144
|
+
* @generated from enum value: POOL_DEF_UNSPECIFIED = 0;
|
|
141
145
|
*/
|
|
142
|
-
|
|
146
|
+
DEF_UNSPECIFIED = 0,
|
|
143
147
|
/**
|
|
144
|
-
* @generated from enum value:
|
|
148
|
+
* @generated from enum value: POOL_SUB = 1;
|
|
145
149
|
*/
|
|
146
|
-
|
|
150
|
+
SUB = 1,
|
|
147
151
|
/**
|
|
148
|
-
* @generated from enum value:
|
|
152
|
+
* @generated from enum value: POOL_ADV = 2;
|
|
149
153
|
*/
|
|
150
|
-
|
|
154
|
+
ADV = 2,
|
|
151
155
|
/**
|
|
152
|
-
* @generated from enum value:
|
|
156
|
+
* @generated from enum value: POOL_IX = 3;
|
|
153
157
|
*/
|
|
154
|
-
|
|
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.
|
|
169
|
+
* @generated from rpc danuni.danmaku.v1.DanmakuService.ListDan
|
|
166
170
|
*/
|
|
167
171
|
listDan: {
|
|
168
172
|
methodKind: "unary";
|
|
169
|
-
input: typeof
|
|
170
|
-
output: typeof
|
|
173
|
+
input: typeof ListDanRequestSchema;
|
|
174
|
+
output: typeof ListDanResponseSchema;
|
|
171
175
|
};
|
|
172
176
|
}>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dan-uni/dan-any",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"description": "A danmaku transformer lib, supporting danmaku from different platforms.",
|
|
6
6
|
"author": "rinne",
|
|
7
7
|
"license": "LGPL-3.0-or-later",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"base16384": "^1.0.0",
|
|
37
37
|
"class-transformer": "^0.5.1",
|
|
38
38
|
"class-validator": "^0.14.3",
|
|
39
|
-
"fast-xml-parser": "^5.3.
|
|
39
|
+
"fast-xml-parser": "^5.3.6",
|
|
40
40
|
"fs-extra": "^11.3.3",
|
|
41
41
|
"hh-mm-ss": "^1.2.0",
|
|
42
42
|
"json-bigint": "^1.0.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"reflect-metadata": "^0.2.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@bufbuild/buf": "^1.
|
|
48
|
+
"@bufbuild/buf": "^1.65.0",
|
|
49
49
|
"@bufbuild/protoc-gen-es": "^2.11.0",
|
|
50
50
|
"@types/fs-extra": "^11.0.4",
|
|
51
51
|
"@types/hh-mm-ss": "^1.2.3",
|
package/src/index.test.ts
CHANGED
|
@@ -73,7 +73,7 @@ describe('转化自', () => {
|
|
|
73
73
|
const pb = pool.toPb()
|
|
74
74
|
console.info(UniPool.fromPb(pb))
|
|
75
75
|
const imp = UniPool.import(pb)
|
|
76
|
-
expect(imp.fmt).toBe('danuni.
|
|
76
|
+
expect(imp.fmt).toBe('danuni.binpb')
|
|
77
77
|
expect(imp.pool).toEqual(pool)
|
|
78
78
|
})
|
|
79
79
|
it('DDplay[双向]', () => {
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { isJSON, isObject, isString } from 'class-validator'
|
|
|
4
4
|
import { XMLBuilder, XMLParser } from 'fast-xml-parser'
|
|
5
5
|
import JSONbig from 'json-bigint'
|
|
6
6
|
import type { Options as AssGenOptions, CanvasCtx } from './ass-gen'
|
|
7
|
-
import type { CommandDm as DM_JSON_BiliCommandGrpc } from './proto/gen/
|
|
7
|
+
import type { CommandDm as DM_JSON_BiliCommandGrpc } from './proto/gen/bilibili/community/service/dm/v1/dm_pb'
|
|
8
|
+
import type { Danmaku } from './proto/gen/danuni/danmaku/v1/danmaku_pb'
|
|
8
9
|
|
|
9
10
|
import { create, fromBinary, toBinary } from '@bufbuild/protobuf'
|
|
10
11
|
import {
|
|
@@ -19,8 +20,8 @@ import {
|
|
|
19
20
|
// DanmakuElem as DM_JSON_BiliGrpc,
|
|
20
21
|
DmSegMobileReplySchema,
|
|
21
22
|
DmWebViewReplySchema,
|
|
22
|
-
} from './proto/gen/
|
|
23
|
-
import {
|
|
23
|
+
} from './proto/gen/bilibili/community/service/dm/v1/dm_pb'
|
|
24
|
+
import { ListDanResponseSchema } from './proto/gen/danuni/danmaku/v1/danmaku_pb'
|
|
24
25
|
// import type * as UniIDType from './utils/id-gen'
|
|
25
26
|
|
|
26
27
|
import { UniDM } from './utils/dm-gen'
|
|
@@ -151,17 +152,19 @@ export interface DM_JSON_DDPlay {
|
|
|
151
152
|
}[]
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
export
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
export enum DM_format {
|
|
156
|
+
DanuniJson = 'danuni.json',
|
|
157
|
+
DanuniMinJson = 'danuni.min.json',
|
|
158
|
+
DanuniPbBin = 'danuni.binpb',
|
|
159
|
+
BiliXml = 'bili.xml',
|
|
160
|
+
BiliPbBin = 'bili.binpb',
|
|
161
|
+
BiliCmdPbBin = 'bili.cmd.binpb',
|
|
162
|
+
BiliUpJson = 'bili.up.json',
|
|
163
|
+
DplayerJson = 'dplayer.json',
|
|
164
|
+
ArtplayerJson = 'artplayer.json',
|
|
165
|
+
DdplayJson = 'ddplay.json',
|
|
166
|
+
CommonAss = 'common.ass',
|
|
167
|
+
}
|
|
165
168
|
|
|
166
169
|
type shareItems = Partial<
|
|
167
170
|
Pick<
|
|
@@ -460,7 +463,7 @@ export class UniPool {
|
|
|
460
463
|
): { pool: UniPool; fmt: DM_format } | undefined => {
|
|
461
464
|
try {
|
|
462
465
|
if (Array.isArray(json) && json.every((d) => d.SOID)) {
|
|
463
|
-
return { pool: new UniPool(json, options), fmt:
|
|
466
|
+
return { pool: new UniPool(json, options), fmt: DM_format.DanuniJson }
|
|
464
467
|
} else if (json.danmuku && json.danmuku.every((d) => d.text)) {
|
|
465
468
|
return {
|
|
466
469
|
pool: this.fromArtplayer(
|
|
@@ -469,7 +472,7 @@ export class UniPool {
|
|
|
469
472
|
undefined,
|
|
470
473
|
options,
|
|
471
474
|
),
|
|
472
|
-
fmt:
|
|
475
|
+
fmt: DM_format.ArtplayerJson,
|
|
473
476
|
}
|
|
474
477
|
} else if (
|
|
475
478
|
json.count &&
|
|
@@ -479,7 +482,7 @@ export class UniPool {
|
|
|
479
482
|
) {
|
|
480
483
|
return {
|
|
481
484
|
pool: this.fromDDPlay(json, json.danuni?.data ?? '', options),
|
|
482
|
-
fmt:
|
|
485
|
+
fmt: DM_format.DdplayJson,
|
|
483
486
|
}
|
|
484
487
|
} else if (
|
|
485
488
|
json.code == 0 &&
|
|
@@ -494,7 +497,7 @@ export class UniPool {
|
|
|
494
497
|
undefined,
|
|
495
498
|
options,
|
|
496
499
|
),
|
|
497
|
-
fmt:
|
|
500
|
+
fmt: DM_format.DplayerJson,
|
|
498
501
|
}
|
|
499
502
|
} else if (
|
|
500
503
|
json.code == 0 &&
|
|
@@ -507,7 +510,7 @@ export class UniPool {
|
|
|
507
510
|
) {
|
|
508
511
|
return {
|
|
509
512
|
pool: this.fromBiliUp(json, options),
|
|
510
|
-
fmt:
|
|
513
|
+
fmt: DM_format.BiliUpJson,
|
|
511
514
|
}
|
|
512
515
|
}
|
|
513
516
|
} catch {}
|
|
@@ -529,10 +532,13 @@ export class UniPool {
|
|
|
529
532
|
const xmlParser = new XMLParser({ ignoreAttributes: false })
|
|
530
533
|
const xml = xmlParser.parse(file)
|
|
531
534
|
if (xml?.i?.d)
|
|
532
|
-
return {
|
|
535
|
+
return {
|
|
536
|
+
pool: this.fromBiliXML(file, options),
|
|
537
|
+
fmt: DM_format.BiliXml,
|
|
538
|
+
}
|
|
533
539
|
} catch {}
|
|
534
540
|
try {
|
|
535
|
-
return { pool: this.fromASS(file, options), fmt:
|
|
541
|
+
return { pool: this.fromASS(file, options), fmt: DM_format.CommonAss }
|
|
536
542
|
} catch {}
|
|
537
543
|
}
|
|
538
544
|
}
|
|
@@ -542,15 +548,15 @@ export class UniPool {
|
|
|
542
548
|
// pure-bin (pb)
|
|
543
549
|
if (mod.includes('bin')) {
|
|
544
550
|
try {
|
|
545
|
-
return { pool: this.fromPb(file), fmt:
|
|
551
|
+
return { pool: this.fromPb(file), fmt: DM_format.DanuniPbBin }
|
|
546
552
|
} catch {}
|
|
547
553
|
try {
|
|
548
|
-
return { pool: this.fromBiliGrpc(file), fmt:
|
|
554
|
+
return { pool: this.fromBiliGrpc(file), fmt: DM_format.BiliPbBin }
|
|
549
555
|
} catch {}
|
|
550
556
|
try {
|
|
551
557
|
return {
|
|
552
558
|
pool: this.fromBiliCommandGrpc(file),
|
|
553
|
-
fmt:
|
|
559
|
+
fmt: DM_format.BiliCmdPbBin,
|
|
554
560
|
}
|
|
555
561
|
} catch {}
|
|
556
562
|
}
|
|
@@ -583,13 +589,15 @@ export class UniPool {
|
|
|
583
589
|
switch (format) {
|
|
584
590
|
case 'danuni.json':
|
|
585
591
|
return this.dans
|
|
586
|
-
case 'danuni.
|
|
592
|
+
case 'danuni.min.json':
|
|
593
|
+
return this.minify()
|
|
594
|
+
case 'danuni.binpb':
|
|
587
595
|
return this.toPb()
|
|
588
596
|
case 'bili.xml':
|
|
589
597
|
return this.toBiliXML()
|
|
590
|
-
// case 'bili.
|
|
598
|
+
// case 'bili.binpb':
|
|
591
599
|
// return this.toBiliBin()
|
|
592
|
-
// case 'bili.cmd.
|
|
600
|
+
// case 'bili.cmd.binpb':
|
|
593
601
|
// return this.toBiliCmdBin()
|
|
594
602
|
case 'dplayer.json':
|
|
595
603
|
return this.toDplayer()
|
|
@@ -607,14 +615,17 @@ export class UniPool {
|
|
|
607
615
|
}
|
|
608
616
|
}
|
|
609
617
|
static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options) {
|
|
610
|
-
const data = fromBinary(
|
|
618
|
+
const data = fromBinary(ListDanResponseSchema, new Uint8Array(bin))
|
|
611
619
|
return new UniPool(
|
|
612
620
|
data.danmakus.map((d) =>
|
|
613
621
|
UniDM.create(
|
|
614
622
|
{
|
|
615
623
|
...d,
|
|
624
|
+
SOID: d.soid,
|
|
625
|
+
DMID: d.dmid,
|
|
616
626
|
progress: d.progress / 1000,
|
|
617
627
|
mode: d.mode as number,
|
|
628
|
+
senderID: d.senderId,
|
|
618
629
|
ctime: timestampDate(d.ctime || timestampNow()),
|
|
619
630
|
pool: d.pool as number,
|
|
620
631
|
attr: d.attr as UniDMTools.DMAttr[],
|
|
@@ -632,17 +643,17 @@ export class UniPool {
|
|
|
632
643
|
*/
|
|
633
644
|
toPb() {
|
|
634
645
|
return toBinary(
|
|
635
|
-
|
|
636
|
-
create(
|
|
646
|
+
ListDanResponseSchema,
|
|
647
|
+
create(ListDanResponseSchema, {
|
|
637
648
|
danmakus: this.dans.map((d) => {
|
|
638
649
|
return {
|
|
639
|
-
|
|
640
|
-
|
|
650
|
+
soid: d.SOID,
|
|
651
|
+
dmid: d.DMID ?? '',
|
|
641
652
|
progress: Math.round(d.progress * 1000),
|
|
642
653
|
mode: d.mode as number,
|
|
643
654
|
fontsize: d.fontsize,
|
|
644
655
|
color: d.color,
|
|
645
|
-
|
|
656
|
+
senderId: d.senderID,
|
|
646
657
|
content: d.content,
|
|
647
658
|
ctime: timestampFromDate(d.ctime),
|
|
648
659
|
weight: d.weight,
|
|
@@ -650,7 +661,7 @@ export class UniPool {
|
|
|
650
661
|
attr: d.attr,
|
|
651
662
|
platform: d.platform,
|
|
652
663
|
extra: d.extraStr,
|
|
653
|
-
}
|
|
664
|
+
} satisfies Omit<Danmaku, '$typeName'>
|
|
654
665
|
}),
|
|
655
666
|
}),
|
|
656
667
|
)
|