@dan-uni/dan-any 0.6.9 → 0.7.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.
- package/dist/index.js +70 -60
- package/dist/index.umd.min.js +70 -60
- package/dist/src/index.d.ts +9 -8
- package/dist/src/utils/dm-gen.d.ts +13 -8
- package/dist/src/utils/id-gen.d.ts +2 -1
- package/package.json +2 -2
- package/src/ass-gen/__tests__/898651903.xml.ass +1 -1
- package/src/ass-gen/ass/raw.ts +2 -2
- package/src/index.test.ts +22 -0
- package/src/index.ts +42 -16
- package/src/utils/dm-gen.ts +136 -84
- package/src/utils/id-gen.ts +10 -2
- package/tsconfig.json +1 -1
- package/types/tsconfig.tsbuildinfo +1 -1
package/dist/index.umd.min.js
CHANGED
|
@@ -23095,7 +23095,7 @@ and limitations under the License.
|
|
|
23095
23095
|
return this.fromNull(domain);
|
|
23096
23096
|
}
|
|
23097
23097
|
}
|
|
23098
|
-
function createDMID(content = '', senderID, ctime, extraStr, slice = 8) {
|
|
23098
|
+
function createDMID(content = '', senderID = id_gen_UniID.fromNull().toString(), ctime = new Date().toISOString(), extraStr, slice = 8) {
|
|
23099
23099
|
return new ht('SHA3-256', 'TEXT').update(`${content}|${senderID}|${UniDM.transCtime(ctime).toISOString()}|${extraStr}`).getHash('HEX').slice(0, slice);
|
|
23100
23100
|
}
|
|
23101
23101
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -23137,7 +23137,7 @@ and limitations under the License.
|
|
|
23137
23137
|
bits.unshift(!!(1 & number));
|
|
23138
23138
|
number >>= 1;
|
|
23139
23139
|
}while (number);
|
|
23140
|
-
return bits.
|
|
23140
|
+
return bits.toReversed();
|
|
23141
23141
|
};
|
|
23142
23142
|
var dm_gen_DMAttr = /*#__PURE__*/ function(DMAttr) {
|
|
23143
23143
|
DMAttr["Protect"] = "Protect";
|
|
@@ -23220,8 +23220,10 @@ and limitations under the License.
|
|
|
23220
23220
|
return Pools;
|
|
23221
23221
|
}({});
|
|
23222
23222
|
class UniDM {
|
|
23223
|
-
init() {
|
|
23223
|
+
init(options) {
|
|
23224
|
+
this.options = options || this.options;
|
|
23224
23225
|
const def = new UniDM();
|
|
23226
|
+
if (void 0 === this.options.dmid || true === this.options.dmid) this.options.dmid = createDMID;
|
|
23225
23227
|
if (!this.SOID) this.SOID = def.SOID;
|
|
23226
23228
|
if (!this.progress) this.progress = def.progress;
|
|
23227
23229
|
if (!this.mode) this.mode = def.mode;
|
|
@@ -23233,7 +23235,7 @@ and limitations under the License.
|
|
|
23233
23235
|
if (!this.weight) this.weight = def.weight;
|
|
23234
23236
|
if (!this.pool) this.pool = def.pool;
|
|
23235
23237
|
if (!this.attr) this.attr = def.attr;
|
|
23236
|
-
if (!this.DMID) this.DMID = this.toDMID();
|
|
23238
|
+
if (!this.DMID && false !== this.options.dmid) this.DMID = this.toDMID();
|
|
23237
23239
|
this.progress = Number.parseFloat(this.progress.toFixed(3));
|
|
23238
23240
|
if (this.extraStr) this.extraStr = dm_gen_JSON.stringify(cleanEmptyObjects(dm_gen_JSON.parse(this.extraStr)));
|
|
23239
23241
|
if ('{}' === this.extraStr) this.extraStr = void 0;
|
|
@@ -23251,13 +23253,13 @@ and limitations under the License.
|
|
|
23251
23253
|
async validate() {
|
|
23252
23254
|
return validateOrReject(this);
|
|
23253
23255
|
}
|
|
23254
|
-
static create(pjson) {
|
|
23256
|
+
static create(pjson, options) {
|
|
23255
23257
|
return pjson ? plainToInstance(UniDM, pjson.extra ? {
|
|
23256
23258
|
...pjson,
|
|
23257
23259
|
extraStr: pjson.extra ? dm_gen_JSON.stringify(pjson.extra) : pjson.extraStr
|
|
23258
23260
|
} : pjson, {
|
|
23259
23261
|
excludeExtraneousValues: true
|
|
23260
|
-
}).init() : new UniDM();
|
|
23262
|
+
}).init(options) : new UniDM();
|
|
23261
23263
|
}
|
|
23262
23264
|
get extra() {
|
|
23263
23265
|
const extra = dm_gen_JSON.parse(this.extraStr || '{}');
|
|
@@ -23268,7 +23270,10 @@ and limitations under the License.
|
|
|
23268
23270
|
return false;
|
|
23269
23271
|
}
|
|
23270
23272
|
toDMID() {
|
|
23271
|
-
|
|
23273
|
+
if (false === this.options.dmid) return;
|
|
23274
|
+
if (true === this.options.dmid) return createDMID(this.content, this.senderID, this.ctime, this.extraStr);
|
|
23275
|
+
if ('number' == typeof this.options.dmid) return createDMID(this.content, this.senderID, this.ctime, this.extraStr, this.options.dmid);
|
|
23276
|
+
return this.options.dmid(this.content, this.senderID, this.ctime, this.extraStr);
|
|
23272
23277
|
}
|
|
23273
23278
|
isSameAs(dan, options) {
|
|
23274
23279
|
if (4 === this.mode || 4 === dan.mode) return false;
|
|
@@ -23386,7 +23391,7 @@ and limitations under the License.
|
|
|
23386
23391
|
}
|
|
23387
23392
|
return mode;
|
|
23388
23393
|
}
|
|
23389
|
-
static fromBili(args, cid) {
|
|
23394
|
+
static fromBili(args, cid, options) {
|
|
23390
23395
|
if (args.oid && !cid) cid = args.oid;
|
|
23391
23396
|
const SOID = `def_${platform_PlatformVideoSource.Bilibili}+${id_gen_UniID.fromBili({
|
|
23392
23397
|
cid
|
|
@@ -23429,7 +23434,7 @@ and limitations under the License.
|
|
|
23429
23434
|
}
|
|
23430
23435
|
return this.create({
|
|
23431
23436
|
...args,
|
|
23432
|
-
SOID
|
|
23437
|
+
SOID,
|
|
23433
23438
|
mode,
|
|
23434
23439
|
senderID: senderID.toString(),
|
|
23435
23440
|
ctime: this.transCtime(args.ctime, 's'),
|
|
@@ -23438,7 +23443,7 @@ and limitations under the License.
|
|
|
23438
23443
|
attr: DMAttrUtils.fromBin(args.attr, platform_PlatformVideoSource.Bilibili),
|
|
23439
23444
|
platform: platform_PlatformVideoSource.Bilibili,
|
|
23440
23445
|
extra
|
|
23441
|
-
});
|
|
23446
|
+
}, options);
|
|
23442
23447
|
}
|
|
23443
23448
|
toBiliXML(options) {
|
|
23444
23449
|
if (options?.skipBiliCommand && this.extra.bili?.command) return null;
|
|
@@ -23493,16 +23498,16 @@ and limitations under the License.
|
|
|
23493
23498
|
].join(',')
|
|
23494
23499
|
};
|
|
23495
23500
|
}
|
|
23496
|
-
static fromBiliCommand(args, cid) {
|
|
23501
|
+
static fromBiliCommand(args, cid, options) {
|
|
23497
23502
|
if (args.oid && !cid) cid = args.oid;
|
|
23498
|
-
const SOID = id_gen_UniID.fromBili({
|
|
23503
|
+
const SOID = `def_${platform_PlatformVideoSource.Bilibili}+${id_gen_UniID.fromBili({
|
|
23499
23504
|
cid
|
|
23500
|
-
})
|
|
23505
|
+
})}`, senderID = id_gen_UniID.fromBili({
|
|
23501
23506
|
mid: args.mid
|
|
23502
23507
|
});
|
|
23503
23508
|
return this.create({
|
|
23504
23509
|
...args,
|
|
23505
|
-
SOID
|
|
23510
|
+
SOID,
|
|
23506
23511
|
mode: 4,
|
|
23507
23512
|
senderID: senderID.toString(),
|
|
23508
23513
|
ctime: new Date(`${args.ctime} GMT+0800`),
|
|
@@ -23517,9 +23522,9 @@ and limitations under the License.
|
|
|
23517
23522
|
command: args
|
|
23518
23523
|
}
|
|
23519
23524
|
}
|
|
23520
|
-
});
|
|
23525
|
+
}, options);
|
|
23521
23526
|
}
|
|
23522
|
-
static fromDplayer(args, playerID, domain) {
|
|
23527
|
+
static fromDplayer(args, playerID, domain, options) {
|
|
23523
23528
|
const SOID = id_gen_UniID.fromUnknown(playerID, domain), senderID = id_gen_UniID.fromUnknown(args.midHash, domain);
|
|
23524
23529
|
return this.create({
|
|
23525
23530
|
...args,
|
|
@@ -23527,7 +23532,7 @@ and limitations under the License.
|
|
|
23527
23532
|
mode: this.transMode(args.mode, 'dplayer'),
|
|
23528
23533
|
senderID: senderID.toString(),
|
|
23529
23534
|
platform: domain
|
|
23530
|
-
});
|
|
23535
|
+
}, options);
|
|
23531
23536
|
}
|
|
23532
23537
|
toDplayer() {
|
|
23533
23538
|
let mode = 0;
|
|
@@ -23541,7 +23546,7 @@ and limitations under the License.
|
|
|
23541
23546
|
content: this.content
|
|
23542
23547
|
};
|
|
23543
23548
|
}
|
|
23544
|
-
static fromArtplayer(args, playerID, domain) {
|
|
23549
|
+
static fromArtplayer(args, playerID, domain, options) {
|
|
23545
23550
|
const SOID = id_gen_UniID.fromUnknown(playerID, domain), senderID = id_gen_UniID.fromUnknown('', domain);
|
|
23546
23551
|
let extra = args.border ? {
|
|
23547
23552
|
artplayer: {
|
|
@@ -23567,7 +23572,7 @@ and limitations under the License.
|
|
|
23567
23572
|
senderID: senderID.toString(),
|
|
23568
23573
|
platform: domain,
|
|
23569
23574
|
extra
|
|
23570
|
-
});
|
|
23575
|
+
}, options);
|
|
23571
23576
|
}
|
|
23572
23577
|
toArtplayer() {
|
|
23573
23578
|
let mode = 0;
|
|
@@ -23581,7 +23586,7 @@ and limitations under the License.
|
|
|
23581
23586
|
style: this.extra.artplayer?.style
|
|
23582
23587
|
};
|
|
23583
23588
|
}
|
|
23584
|
-
static fromDDplay(args, episodeId, domain = platform_PlatformDanmakuOnlySource.DanDanPlay) {
|
|
23589
|
+
static fromDDplay(args, episodeId, domain = platform_PlatformDanmakuOnlySource.DanDanPlay, options) {
|
|
23585
23590
|
const SOID = id_gen_UniID.fromUnknown(`def_${platform_PlatformDanmakuOnlySource.DanDanPlay}+${episodeId}`, domain);
|
|
23586
23591
|
return this.create({
|
|
23587
23592
|
...args,
|
|
@@ -23591,7 +23596,7 @@ and limitations under the License.
|
|
|
23591
23596
|
content: args.m,
|
|
23592
23597
|
platform: domain,
|
|
23593
23598
|
DMID: args.cid.toString()
|
|
23594
|
-
});
|
|
23599
|
+
}, options);
|
|
23595
23600
|
}
|
|
23596
23601
|
toDDplay() {
|
|
23597
23602
|
let mode = 1;
|
|
@@ -23618,6 +23623,9 @@ and limitations under the License.
|
|
|
23618
23623
|
this.weight = 0;
|
|
23619
23624
|
this.pool = 0;
|
|
23620
23625
|
this.attr = [];
|
|
23626
|
+
this.options = {
|
|
23627
|
+
dmid: createDMID
|
|
23628
|
+
};
|
|
23621
23629
|
}
|
|
23622
23630
|
}
|
|
23623
23631
|
_ts_decorate([
|
|
@@ -23720,7 +23728,9 @@ and limitations under the License.
|
|
|
23720
23728
|
_ts_decorate([
|
|
23721
23729
|
Expose(),
|
|
23722
23730
|
_ts_metadata("design:type", Function),
|
|
23723
|
-
_ts_metadata("design:paramtypes", [
|
|
23731
|
+
_ts_metadata("design:paramtypes", [
|
|
23732
|
+
"undefined" == typeof Options ? Object : Options
|
|
23733
|
+
]),
|
|
23724
23734
|
_ts_metadata("design:returntype", void 0)
|
|
23725
23735
|
], UniDM.prototype, "init", null);
|
|
23726
23736
|
_ts_decorate([
|
|
@@ -23944,8 +23954,8 @@ and limitations under the License.
|
|
|
23944
23954
|
platform: s.platform.sort((a, b)=>b.count - a.count)[0].val
|
|
23945
23955
|
};
|
|
23946
23956
|
}
|
|
23947
|
-
static create() {
|
|
23948
|
-
return new UniPool([]);
|
|
23957
|
+
static create(options) {
|
|
23958
|
+
return new UniPool([], options);
|
|
23949
23959
|
}
|
|
23950
23960
|
assign(dans) {
|
|
23951
23961
|
if (dans instanceof UniPool) return new UniPool([
|
|
@@ -24107,7 +24117,7 @@ and limitations under the License.
|
|
|
24107
24117
|
}
|
|
24108
24118
|
}
|
|
24109
24119
|
}
|
|
24110
|
-
static fromPb(bin) {
|
|
24120
|
+
static fromPb(bin, options) {
|
|
24111
24121
|
const data = fromBinary(DanmakuReplySchema, new Uint8Array(bin));
|
|
24112
24122
|
return new UniPool(data.danmakus.map((d)=>UniDM.create({
|
|
24113
24123
|
...d,
|
|
@@ -24115,7 +24125,7 @@ and limitations under the License.
|
|
|
24115
24125
|
ctime: timestampDate(d.ctime || timestampNow()),
|
|
24116
24126
|
pool: d.pool,
|
|
24117
24127
|
attr: d.attr
|
|
24118
|
-
})));
|
|
24128
|
+
}, options)), options);
|
|
24119
24129
|
}
|
|
24120
24130
|
toPb() {
|
|
24121
24131
|
return toBinary(DanmakuReplySchema, create(DanmakuReplySchema, {
|
|
@@ -24137,7 +24147,7 @@ and limitations under the License.
|
|
|
24137
24147
|
}))
|
|
24138
24148
|
}));
|
|
24139
24149
|
}
|
|
24140
|
-
static fromBiliXML(xml) {
|
|
24150
|
+
static fromBiliXML(xml, options) {
|
|
24141
24151
|
const parser = new XMLParser({
|
|
24142
24152
|
ignoreAttributes: false
|
|
24143
24153
|
}), oriData = parser.parse(xml), dans = oriData.i.d;
|
|
@@ -24154,8 +24164,8 @@ and limitations under the License.
|
|
|
24154
24164
|
midHash: p_arr[6],
|
|
24155
24165
|
id: BigInt(p_arr[7]),
|
|
24156
24166
|
weight: Number.parseInt(p_arr[8])
|
|
24157
|
-
}, BigInt(oriData.i.chatid));
|
|
24158
|
-
}).filter((d)=>null !== d));
|
|
24167
|
+
}, BigInt(oriData.i.chatid), options);
|
|
24168
|
+
}).filter((d)=>null !== d), options);
|
|
24159
24169
|
}
|
|
24160
24170
|
toBiliXML() {
|
|
24161
24171
|
const genCID = (id)=>{
|
|
@@ -24186,25 +24196,25 @@ and limitations under the License.
|
|
|
24186
24196
|
}
|
|
24187
24197
|
});
|
|
24188
24198
|
}
|
|
24189
|
-
static fromBiliGrpc(bin) {
|
|
24199
|
+
static fromBiliGrpc(bin, options) {
|
|
24190
24200
|
const data = fromBinary(DmSegMobileReplySchema, new Uint8Array(bin)), json = data.elems;
|
|
24191
24201
|
return new UniPool(json.map((d)=>UniDM.fromBili({
|
|
24192
24202
|
...d,
|
|
24193
24203
|
progress: d.progress / 1000
|
|
24194
|
-
})));
|
|
24204
|
+
}, d.oid, options)), options);
|
|
24195
24205
|
}
|
|
24196
|
-
static fromBiliCommandGrpc(bin) {
|
|
24206
|
+
static fromBiliCommandGrpc(bin, options) {
|
|
24197
24207
|
const data = fromBinary(DmWebViewReplySchema, new Uint8Array(bin)), json = data.commandDms;
|
|
24198
|
-
return new UniPool(json.map((d)=>UniDM.fromBiliCommand(d)));
|
|
24208
|
+
return new UniPool(json.map((d)=>UniDM.fromBiliCommand(d, d.oid, options)), options);
|
|
24199
24209
|
}
|
|
24200
|
-
static fromDplayer(json, playerID, domain = 'other') {
|
|
24210
|
+
static fromDplayer(json, playerID, domain = 'other', options) {
|
|
24201
24211
|
return new UniPool(json.data.map((d)=>UniDM.fromDplayer({
|
|
24202
24212
|
content: d[4],
|
|
24203
24213
|
progress: d[0],
|
|
24204
24214
|
mode: d[1],
|
|
24205
24215
|
color: d[2],
|
|
24206
24216
|
midHash: d[3]
|
|
24207
|
-
}, playerID, domain)));
|
|
24217
|
+
}, playerID, domain, options)), options);
|
|
24208
24218
|
}
|
|
24209
24219
|
toDplayer() {
|
|
24210
24220
|
return {
|
|
@@ -24221,14 +24231,14 @@ and limitations under the License.
|
|
|
24221
24231
|
})
|
|
24222
24232
|
};
|
|
24223
24233
|
}
|
|
24224
|
-
static fromArtplayer(json, playerID, domain = 'other') {
|
|
24234
|
+
static fromArtplayer(json, playerID, domain = 'other', options) {
|
|
24225
24235
|
return new UniPool(json.map((d)=>UniDM.fromArtplayer({
|
|
24226
24236
|
content: d.text,
|
|
24227
24237
|
progress: d.time || 0,
|
|
24228
24238
|
mode: d.mode || 0,
|
|
24229
24239
|
color: Number((d.color || 'FFFFFF').replace('#', '0x')),
|
|
24230
24240
|
style: d.style
|
|
24231
|
-
}, playerID, domain)));
|
|
24241
|
+
}, playerID, domain, options)), options);
|
|
24232
24242
|
}
|
|
24233
24243
|
toArtplayer() {
|
|
24234
24244
|
return this.dans.map((dan)=>{
|
|
@@ -24243,7 +24253,7 @@ and limitations under the License.
|
|
|
24243
24253
|
};
|
|
24244
24254
|
});
|
|
24245
24255
|
}
|
|
24246
|
-
static fromDDPlay(json, episodeId) {
|
|
24256
|
+
static fromDDPlay(json, episodeId, options) {
|
|
24247
24257
|
return new UniPool(json.comments.map((d)=>{
|
|
24248
24258
|
const p_arr = d.p.split(',');
|
|
24249
24259
|
return UniDM.fromDDplay({
|
|
@@ -24253,8 +24263,8 @@ and limitations under the License.
|
|
|
24253
24263
|
mode: Number.parseInt(p_arr[1]),
|
|
24254
24264
|
progress: Number.parseFloat(p_arr[0]),
|
|
24255
24265
|
uid: p_arr[3]
|
|
24256
|
-
}, episodeId);
|
|
24257
|
-
}));
|
|
24266
|
+
}, episodeId, void 0, options);
|
|
24267
|
+
}), options);
|
|
24258
24268
|
}
|
|
24259
24269
|
toDDplay() {
|
|
24260
24270
|
return {
|
|
@@ -24600,7 +24610,7 @@ and limitations under the License.
|
|
|
24600
24610
|
config,
|
|
24601
24611
|
context
|
|
24602
24612
|
}, rawText = JSON.stringify(raw1);
|
|
24603
|
-
let compress
|
|
24613
|
+
let compress;
|
|
24604
24614
|
compress = 'brotli' === compressType ? (0, lib.brotliCompressSync)(rawText) : (0, lib.gzipSync)(rawText);
|
|
24605
24615
|
return `;RawCompressType: ${compressType}\n;RawBaseType: ${baseType}\n;Raw: ${'base64' === baseType ? compress.toString('base64') : fromUint16Array(base16384_lib.encode(compress))}`;
|
|
24606
24616
|
}
|
|
@@ -24612,7 +24622,7 @@ and limitations under the License.
|
|
|
24612
24622
|
if (!compressTypes.includes(compressType)) compressType = 'gzip';
|
|
24613
24623
|
if (!baseTypes.includes(baseType)) baseType = 'base64';
|
|
24614
24624
|
const text = lineRaw.replace(';Raw: ', '').trim(), buffer = 'base64' === baseType ? raw_Buffer.from(text, 'base64') : raw_Buffer.from(base16384_lib.decode(raw_Buffer.from(text, 'utf-8').toString('utf-8')));
|
|
24615
|
-
let decompress
|
|
24625
|
+
let decompress;
|
|
24616
24626
|
decompress = 'brotli' === compressType ? (0, lib.brotliDecompressSync)(buffer) : (0, lib.gunzipSync)(buffer);
|
|
24617
24627
|
try {
|
|
24618
24628
|
return JSON.parse(decompress.toString('utf-8'));
|
|
@@ -24875,8 +24885,8 @@ and limitations under the License.
|
|
|
24875
24885
|
platform: s.platform.sort((a, b)=>b.count - a.count)[0].val
|
|
24876
24886
|
};
|
|
24877
24887
|
}
|
|
24878
|
-
static create() {
|
|
24879
|
-
return new src_UniPool([]);
|
|
24888
|
+
static create(options) {
|
|
24889
|
+
return new src_UniPool([], options);
|
|
24880
24890
|
}
|
|
24881
24891
|
assign(dans) {
|
|
24882
24892
|
if (dans instanceof src_UniPool) return new src_UniPool([
|
|
@@ -25038,7 +25048,7 @@ and limitations under the License.
|
|
|
25038
25048
|
}
|
|
25039
25049
|
}
|
|
25040
25050
|
}
|
|
25041
|
-
static fromPb(bin) {
|
|
25051
|
+
static fromPb(bin, options) {
|
|
25042
25052
|
const data = fromBinary(DanmakuReplySchema, new Uint8Array(bin));
|
|
25043
25053
|
return new src_UniPool(data.danmakus.map((d)=>UniDM.create({
|
|
25044
25054
|
...d,
|
|
@@ -25046,7 +25056,7 @@ and limitations under the License.
|
|
|
25046
25056
|
ctime: timestampDate(d.ctime || timestampNow()),
|
|
25047
25057
|
pool: d.pool,
|
|
25048
25058
|
attr: d.attr
|
|
25049
|
-
})));
|
|
25059
|
+
}, options)), options);
|
|
25050
25060
|
}
|
|
25051
25061
|
toPb() {
|
|
25052
25062
|
return toBinary(DanmakuReplySchema, create(DanmakuReplySchema, {
|
|
@@ -25068,7 +25078,7 @@ and limitations under the License.
|
|
|
25068
25078
|
}))
|
|
25069
25079
|
}));
|
|
25070
25080
|
}
|
|
25071
|
-
static fromBiliXML(xml) {
|
|
25081
|
+
static fromBiliXML(xml, options) {
|
|
25072
25082
|
const parser = new XMLParser({
|
|
25073
25083
|
ignoreAttributes: false
|
|
25074
25084
|
}), oriData = parser.parse(xml), dans = oriData.i.d;
|
|
@@ -25085,8 +25095,8 @@ and limitations under the License.
|
|
|
25085
25095
|
midHash: p_arr[6],
|
|
25086
25096
|
id: BigInt(p_arr[7]),
|
|
25087
25097
|
weight: Number.parseInt(p_arr[8])
|
|
25088
|
-
}, BigInt(oriData.i.chatid));
|
|
25089
|
-
}).filter((d)=>null !== d));
|
|
25098
|
+
}, BigInt(oriData.i.chatid), options);
|
|
25099
|
+
}).filter((d)=>null !== d), options);
|
|
25090
25100
|
}
|
|
25091
25101
|
toBiliXML() {
|
|
25092
25102
|
const genCID = (id)=>{
|
|
@@ -25117,25 +25127,25 @@ and limitations under the License.
|
|
|
25117
25127
|
}
|
|
25118
25128
|
});
|
|
25119
25129
|
}
|
|
25120
|
-
static fromBiliGrpc(bin) {
|
|
25130
|
+
static fromBiliGrpc(bin, options) {
|
|
25121
25131
|
const data = fromBinary(DmSegMobileReplySchema, new Uint8Array(bin)), json = data.elems;
|
|
25122
25132
|
return new src_UniPool(json.map((d)=>UniDM.fromBili({
|
|
25123
25133
|
...d,
|
|
25124
25134
|
progress: d.progress / 1000
|
|
25125
|
-
})));
|
|
25135
|
+
}, d.oid, options)), options);
|
|
25126
25136
|
}
|
|
25127
|
-
static fromBiliCommandGrpc(bin) {
|
|
25137
|
+
static fromBiliCommandGrpc(bin, options) {
|
|
25128
25138
|
const data = fromBinary(DmWebViewReplySchema, new Uint8Array(bin)), json = data.commandDms;
|
|
25129
|
-
return new src_UniPool(json.map((d)=>UniDM.fromBiliCommand(d)));
|
|
25139
|
+
return new src_UniPool(json.map((d)=>UniDM.fromBiliCommand(d, d.oid, options)), options);
|
|
25130
25140
|
}
|
|
25131
|
-
static fromDplayer(json, playerID, domain = 'other') {
|
|
25141
|
+
static fromDplayer(json, playerID, domain = 'other', options) {
|
|
25132
25142
|
return new src_UniPool(json.data.map((d)=>UniDM.fromDplayer({
|
|
25133
25143
|
content: d[4],
|
|
25134
25144
|
progress: d[0],
|
|
25135
25145
|
mode: d[1],
|
|
25136
25146
|
color: d[2],
|
|
25137
25147
|
midHash: d[3]
|
|
25138
|
-
}, playerID, domain)));
|
|
25148
|
+
}, playerID, domain, options)), options);
|
|
25139
25149
|
}
|
|
25140
25150
|
toDplayer() {
|
|
25141
25151
|
return {
|
|
@@ -25152,14 +25162,14 @@ and limitations under the License.
|
|
|
25152
25162
|
})
|
|
25153
25163
|
};
|
|
25154
25164
|
}
|
|
25155
|
-
static fromArtplayer(json, playerID, domain = 'other') {
|
|
25165
|
+
static fromArtplayer(json, playerID, domain = 'other', options) {
|
|
25156
25166
|
return new src_UniPool(json.map((d)=>UniDM.fromArtplayer({
|
|
25157
25167
|
content: d.text,
|
|
25158
25168
|
progress: d.time || 0,
|
|
25159
25169
|
mode: d.mode || 0,
|
|
25160
25170
|
color: Number((d.color || 'FFFFFF').replace('#', '0x')),
|
|
25161
25171
|
style: d.style
|
|
25162
|
-
}, playerID, domain)));
|
|
25172
|
+
}, playerID, domain, options)), options);
|
|
25163
25173
|
}
|
|
25164
25174
|
toArtplayer() {
|
|
25165
25175
|
return this.dans.map((dan)=>{
|
|
@@ -25174,7 +25184,7 @@ and limitations under the License.
|
|
|
25174
25184
|
};
|
|
25175
25185
|
});
|
|
25176
25186
|
}
|
|
25177
|
-
static fromDDPlay(json, episodeId) {
|
|
25187
|
+
static fromDDPlay(json, episodeId, options) {
|
|
25178
25188
|
return new src_UniPool(json.comments.map((d)=>{
|
|
25179
25189
|
const p_arr = d.p.split(',');
|
|
25180
25190
|
return UniDM.fromDDplay({
|
|
@@ -25184,8 +25194,8 @@ and limitations under the License.
|
|
|
25184
25194
|
mode: Number.parseInt(p_arr[1]),
|
|
25185
25195
|
progress: Number.parseFloat(p_arr[0]),
|
|
25186
25196
|
uid: p_arr[3]
|
|
25187
|
-
}, episodeId);
|
|
25188
|
-
}));
|
|
25197
|
+
}, episodeId, void 0, options);
|
|
25198
|
+
}), options);
|
|
25189
25199
|
}
|
|
25190
25200
|
toDDplay() {
|
|
25191
25201
|
return {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ type UniPoolPipe = (that: UniPool) => Promise<UniPool>;
|
|
|
49
49
|
type UniPoolPipeSync = (that: UniPool) => UniPool;
|
|
50
50
|
interface Options {
|
|
51
51
|
dedupe?: boolean;
|
|
52
|
+
dmid?: boolean | number | UniIDTools.DMIDGenerator;
|
|
52
53
|
}
|
|
53
54
|
export declare class UniPool {
|
|
54
55
|
dans: UniDM[];
|
|
@@ -105,7 +106,7 @@ export declare class UniPool {
|
|
|
105
106
|
pool: UniDMTools.Pools;
|
|
106
107
|
platform: string | undefined;
|
|
107
108
|
};
|
|
108
|
-
static create(): UniPool;
|
|
109
|
+
static create(options?: Options): UniPool;
|
|
109
110
|
/**
|
|
110
111
|
* 合并弹幕/弹幕库
|
|
111
112
|
*/
|
|
@@ -125,23 +126,23 @@ export declare class UniPool {
|
|
|
125
126
|
merge(lifetime?: number): UniPool;
|
|
126
127
|
minify(): (Partial<UniDMTools.UniDMObj> & Pick<UniDMTools.UniDMObj, "SOID">)[];
|
|
127
128
|
convert2(format: DM_format, continue_on_error?: boolean): string | Uint8Array<ArrayBufferLike> | UniDM[] | DM_JSON_Dplayer | DM_JSON_DDPlay | DM_JSON_Artplayer[];
|
|
128
|
-
static fromPb(bin: Uint8Array | ArrayBuffer): UniPool;
|
|
129
|
+
static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
|
|
129
130
|
/**
|
|
130
131
|
* 转为 protobuf 二进制
|
|
131
132
|
*/
|
|
132
133
|
toPb(): Uint8Array<ArrayBufferLike>;
|
|
133
|
-
static fromBiliXML(xml: string): UniPool;
|
|
134
|
+
static fromBiliXML(xml: string, options?: Options): UniPool;
|
|
134
135
|
toBiliXML(): string;
|
|
135
|
-
static fromBiliGrpc(bin: Uint8Array | ArrayBuffer): UniPool;
|
|
136
|
+
static fromBiliGrpc(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
|
|
136
137
|
/**
|
|
137
138
|
* @param bin 符合`DmWebViewReplySchema`(bili视频meta)的protobuf二进制
|
|
138
139
|
*/
|
|
139
|
-
static fromBiliCommandGrpc(bin: Uint8Array | ArrayBuffer): UniPool;
|
|
140
|
-
static fromDplayer(json: DM_JSON_Dplayer, playerID: string, domain?: string): UniPool;
|
|
140
|
+
static fromBiliCommandGrpc(bin: Uint8Array | ArrayBuffer, options?: Options): UniPool;
|
|
141
|
+
static fromDplayer(json: DM_JSON_Dplayer, playerID: string, domain?: string, options?: Options): UniPool;
|
|
141
142
|
toDplayer(): DM_JSON_Dplayer;
|
|
142
|
-
static fromArtplayer(json: DM_JSON_Artplayer[], playerID: string, domain?: string): UniPool;
|
|
143
|
+
static fromArtplayer(json: DM_JSON_Artplayer[], playerID: string, domain?: string, options?: Options): UniPool;
|
|
143
144
|
toArtplayer(): DM_JSON_Artplayer[];
|
|
144
|
-
static fromDDPlay(json: DM_JSON_DDPlay, episodeId: string): UniPool;
|
|
145
|
+
static fromDDPlay(json: DM_JSON_DDPlay, episodeId: string, options?: Options): UniPool;
|
|
145
146
|
toDDplay(): DM_JSON_DDPlay;
|
|
146
147
|
static fromASS(ass: string): UniPool;
|
|
147
148
|
toASS(options?: AssGenOptions): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DM_JSON_BiliCommandGrpc } from '..';
|
|
2
2
|
import type { PlatformDanmakuSource } from './platform';
|
|
3
|
+
import { DMIDGenerator } from './id-gen';
|
|
3
4
|
import { PlatformDanmakuOnlySource } from './platform';
|
|
4
5
|
export declare enum DMAttr {
|
|
5
6
|
Protect = "Protect",
|
|
@@ -165,6 +166,9 @@ export interface UniDMObj {
|
|
|
165
166
|
extraStr: string;
|
|
166
167
|
DMID: string;
|
|
167
168
|
}
|
|
169
|
+
interface Options {
|
|
170
|
+
dmid?: boolean | number | DMIDGenerator;
|
|
171
|
+
}
|
|
168
172
|
export declare class UniDM {
|
|
169
173
|
/**
|
|
170
174
|
* 资源ID
|
|
@@ -238,9 +242,10 @@ export declare class UniDM {
|
|
|
238
242
|
*/
|
|
239
243
|
extraStr?: string;
|
|
240
244
|
DMID?: string;
|
|
241
|
-
|
|
245
|
+
private options;
|
|
246
|
+
init(options?: Options): this;
|
|
242
247
|
validate(): Promise<void>;
|
|
243
|
-
static create(pjson?: Partial<UniDMObj
|
|
248
|
+
static create(pjson?: Partial<UniDMObj>, options?: Options): UniDM;
|
|
244
249
|
get extra(): Extra;
|
|
245
250
|
get isFrom3rdPlatform(): boolean;
|
|
246
251
|
/**
|
|
@@ -248,7 +253,7 @@ export declare class UniDM {
|
|
|
248
253
|
* @description sha3-256(content+senderID+ctime)截取前8位
|
|
249
254
|
* @description 同一SOID下唯一
|
|
250
255
|
*/
|
|
251
|
-
toDMID(): string;
|
|
256
|
+
toDMID(): string | undefined;
|
|
252
257
|
isSameAs(dan: UniDM, options?: {
|
|
253
258
|
skipDanuniMerge?: boolean;
|
|
254
259
|
}): boolean;
|
|
@@ -267,19 +272,19 @@ export declare class UniDM {
|
|
|
267
272
|
*/
|
|
268
273
|
static transCtime(oriCtime: ctime, tsUnit?: 'ms' | 's'): Date;
|
|
269
274
|
static transMode(oriMode: number, fmt: 'bili' | 'dplayer' | 'artplayer' | 'ddplay'): Modes;
|
|
270
|
-
static fromBili(args: DMBili, cid?: bigint): UniDM;
|
|
275
|
+
static fromBili(args: DMBili, cid?: bigint, options?: Options): UniDM;
|
|
271
276
|
toBiliXML(options?: {
|
|
272
277
|
skipBiliCommand: boolean;
|
|
273
278
|
}): {
|
|
274
279
|
'#text': string;
|
|
275
280
|
'@_p': string;
|
|
276
281
|
} | null;
|
|
277
|
-
static fromBiliCommand(args: DMBiliCommand, cid?: bigint): UniDM;
|
|
278
|
-
static fromDplayer(args: DMDplayer, playerID: string, domain: string): UniDM;
|
|
282
|
+
static fromBiliCommand(args: DMBiliCommand, cid?: bigint, options?: Options): UniDM;
|
|
283
|
+
static fromDplayer(args: DMDplayer, playerID: string, domain: string, options?: Options): UniDM;
|
|
279
284
|
toDplayer(): DMDplayer;
|
|
280
|
-
static fromArtplayer(args: DMArtplayer, playerID: string, domain: string): UniDM;
|
|
285
|
+
static fromArtplayer(args: DMArtplayer, playerID: string, domain: string, options?: Options): UniDM;
|
|
281
286
|
toArtplayer(): DMArtplayer;
|
|
282
|
-
static fromDDplay(args: DMDDplay, episodeId: string, domain?: PlatformDanmakuOnlySource): UniDM;
|
|
287
|
+
static fromDDplay(args: DMDDplay, episodeId: string, domain?: PlatformDanmakuOnlySource, options?: Options): UniDM;
|
|
283
288
|
toDDplay(): DMDDplay;
|
|
284
289
|
}
|
|
285
290
|
export {};
|
|
@@ -46,4 +46,5 @@ export declare class UniID {
|
|
|
46
46
|
*/
|
|
47
47
|
domain: PlatformSource | string): UniID;
|
|
48
48
|
}
|
|
49
|
-
export
|
|
49
|
+
export type DMIDGenerator = (content?: string, senderID?: string, ctime?: ctime, extraStr?: string, slice?: number) => string;
|
|
50
|
+
export declare function createDMID(content?: string, senderID?: string, ctime?: ctime, extraStr?: string, slice?: number): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dan-uni/dan-any",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "A danmaku transformer lib, supporting danmaku from different platforms.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bangumi",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"reflect-metadata": "^0.2.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@bufbuild/buf": "^1.
|
|
47
|
+
"@bufbuild/buf": "^1.56.0",
|
|
48
48
|
"@bufbuild/protoc-gen-es": "^2.6.2",
|
|
49
49
|
"@types/fs-extra": "^11.0.4",
|
|
50
50
|
"@types/hh-mm-ss": "^1.2.3",
|