agdi 3.3.6 → 3.3.8
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 +13 -0
- package/dist/APEv2Parser-EU45AV6X.js +14 -0
- package/dist/AiffParser-FOX7GQ42.js +189 -0
- package/dist/AsfParser-HD5CSGIO.js +610 -0
- package/dist/DsdiffParser-OJREDMBI.js +188 -0
- package/dist/DsfParser-2YL4ARJ7.js +110 -0
- package/dist/FlacParser-IVV4RYF6.js +15 -0
- package/dist/MP4Parser-NLX4A2YN.js +1140 -0
- package/dist/MatroskaParser-4OEK43GF.js +654 -0
- package/dist/MpegParser-PXKEUF2B.js +642 -0
- package/dist/MusepackParser-54QGYRLY.js +322 -0
- package/dist/OggParser-KRV5QCGZ.js +435 -0
- package/dist/WavPackParser-XPZSQFVS.js +203 -0
- package/dist/WaveParser-27IS2RAI.js +294 -0
- package/dist/chunk-2B4QMSZW.js +311 -0
- package/dist/chunk-3JKZUGPJ.js +70 -0
- package/dist/chunk-4VNS5WPM.js +42 -0
- package/dist/chunk-65JVFJ3X.js +729 -0
- package/dist/chunk-6OKLAJRQ.js +0 -0
- package/dist/chunk-AGSFUVRG.js +439 -0
- package/dist/chunk-GD35BJSH.js +177 -0
- package/dist/chunk-HNLU36CC.js +702 -0
- package/dist/{chunk-M2FF7ETI.js → chunk-J6OLLWVT.js} +1 -1
- package/dist/chunk-LREP5CZP.js +146 -0
- package/dist/chunk-M54HVABG.js +34 -0
- package/dist/{chunk-S45VXJEO.js → chunk-OPFFFAQC.js} +19 -1
- package/dist/chunk-VGOIHW7D.js +1529 -0
- package/dist/chunk-YIHDW7JC.js +314 -0
- package/dist/config-D3QBUN2Y.js +13 -0
- package/dist/{config-ZFU7TSU2.js → config-K2XM6D4Z.js} +3 -2
- package/dist/{event-bus-Q3WCETQQ.js → event-bus-MO5SFUME.js} +1 -0
- package/dist/index.js +3966 -1203
- package/dist/lib-2XISBYT3.js +144950 -0
- package/dist/lib-HCGLI2GJ.js +4161 -0
- package/dist/{telemetry-service-OHU5NKON.js → telemetry-service-76YPOPDM.js} +8 -4
- package/package.json +5 -2
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TargetType,
|
|
3
|
+
TrackType
|
|
4
|
+
} from "./chunk-M54HVABG.js";
|
|
5
|
+
import {
|
|
6
|
+
EndOfStreamError
|
|
7
|
+
} from "./chunk-HNLU36CC.js";
|
|
8
|
+
import {
|
|
9
|
+
BasicParser,
|
|
10
|
+
Float32_BE,
|
|
11
|
+
Float64_BE,
|
|
12
|
+
StringType,
|
|
13
|
+
UINT64_BE,
|
|
14
|
+
UINT8,
|
|
15
|
+
makeUnexpectedFileContentError,
|
|
16
|
+
require_src
|
|
17
|
+
} from "./chunk-VGOIHW7D.js";
|
|
18
|
+
import {
|
|
19
|
+
__toESM
|
|
20
|
+
} from "./chunk-4VNS5WPM.js";
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/.pnpm/music-metadata@11.12.0/node_modules/music-metadata/lib/matroska/MatroskaParser.js
|
|
23
|
+
var import_debug2 = __toESM(require_src(), 1);
|
|
24
|
+
|
|
25
|
+
// ../../node_modules/.pnpm/music-metadata@11.12.0/node_modules/music-metadata/lib/ebml/types.js
|
|
26
|
+
var DataType = {
|
|
27
|
+
string: 0,
|
|
28
|
+
uint: 1,
|
|
29
|
+
uid: 2,
|
|
30
|
+
bool: 3,
|
|
31
|
+
binary: 4,
|
|
32
|
+
float: 5
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// ../../node_modules/.pnpm/music-metadata@11.12.0/node_modules/music-metadata/lib/matroska/MatroskaDtd.js
|
|
36
|
+
var matroskaDtd = {
|
|
37
|
+
name: "dtd",
|
|
38
|
+
container: {
|
|
39
|
+
440786851: {
|
|
40
|
+
name: "ebml",
|
|
41
|
+
container: {
|
|
42
|
+
17030: { name: "ebmlVersion", value: DataType.uint },
|
|
43
|
+
// 5.1.1
|
|
44
|
+
17143: { name: "ebmlReadVersion", value: DataType.uint },
|
|
45
|
+
// 5.1.2
|
|
46
|
+
17138: { name: "ebmlMaxIDWidth", value: DataType.uint },
|
|
47
|
+
// 5.1.3
|
|
48
|
+
17139: { name: "ebmlMaxSizeWidth", value: DataType.uint },
|
|
49
|
+
// 5.1.4
|
|
50
|
+
17026: { name: "docType", value: DataType.string },
|
|
51
|
+
// 5.1.5
|
|
52
|
+
17031: { name: "docTypeVersion", value: DataType.uint },
|
|
53
|
+
// 5.1.6
|
|
54
|
+
17029: { name: "docTypeReadVersion", value: DataType.uint }
|
|
55
|
+
// 5.1.7
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
// Matroska segments
|
|
59
|
+
408125543: {
|
|
60
|
+
name: "segment",
|
|
61
|
+
container: {
|
|
62
|
+
// Meta Seek Information (also known as MetaSeek)
|
|
63
|
+
290298740: {
|
|
64
|
+
name: "seekHead",
|
|
65
|
+
container: {
|
|
66
|
+
19899: {
|
|
67
|
+
name: "seek",
|
|
68
|
+
multiple: true,
|
|
69
|
+
container: {
|
|
70
|
+
21419: { name: "id", value: DataType.binary },
|
|
71
|
+
21420: { name: "position", value: DataType.uint }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
// Segment Information
|
|
77
|
+
357149030: {
|
|
78
|
+
name: "info",
|
|
79
|
+
container: {
|
|
80
|
+
29604: { name: "uid", value: DataType.uid },
|
|
81
|
+
29572: { name: "filename", value: DataType.string },
|
|
82
|
+
3979555: { name: "prevUID", value: DataType.uid },
|
|
83
|
+
3965867: { name: "prevFilename", value: DataType.string },
|
|
84
|
+
4110627: { name: "nextUID", value: DataType.uid },
|
|
85
|
+
4096955: { name: "nextFilename", value: DataType.string },
|
|
86
|
+
2807729: { name: "timecodeScale", value: DataType.uint },
|
|
87
|
+
17545: { name: "duration", value: DataType.float },
|
|
88
|
+
17505: { name: "dateUTC", value: DataType.uint },
|
|
89
|
+
31657: { name: "title", value: DataType.string },
|
|
90
|
+
19840: { name: "muxingApp", value: DataType.string },
|
|
91
|
+
22337: { name: "writingApp", value: DataType.string }
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
// Cluster
|
|
95
|
+
524531317: {
|
|
96
|
+
name: "cluster",
|
|
97
|
+
multiple: true,
|
|
98
|
+
container: {
|
|
99
|
+
231: { name: "timecode", value: DataType.uid },
|
|
100
|
+
22743: { name: "silentTracks ", multiple: true },
|
|
101
|
+
167: { name: "position", value: DataType.uid },
|
|
102
|
+
171: { name: "prevSize", value: DataType.uid },
|
|
103
|
+
160: { name: "blockGroup" },
|
|
104
|
+
163: { name: "simpleBlock" }
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
// Track
|
|
108
|
+
374648427: {
|
|
109
|
+
name: "tracks",
|
|
110
|
+
container: {
|
|
111
|
+
174: {
|
|
112
|
+
name: "entries",
|
|
113
|
+
multiple: true,
|
|
114
|
+
container: {
|
|
115
|
+
215: { name: "trackNumber", value: DataType.uint },
|
|
116
|
+
29637: { name: "uid", value: DataType.uid },
|
|
117
|
+
131: { name: "trackType", value: DataType.uint },
|
|
118
|
+
185: { name: "flagEnabled", value: DataType.bool },
|
|
119
|
+
136: { name: "flagDefault", value: DataType.bool },
|
|
120
|
+
21930: { name: "flagForced", value: DataType.bool },
|
|
121
|
+
// extended
|
|
122
|
+
156: { name: "flagLacing", value: DataType.bool },
|
|
123
|
+
28135: { name: "minCache", value: DataType.uint },
|
|
124
|
+
28136: { name: "maxCache", value: DataType.uint },
|
|
125
|
+
2352003: { name: "defaultDuration", value: DataType.uint },
|
|
126
|
+
2306383: { name: "timecodeScale", value: DataType.float },
|
|
127
|
+
21358: { name: "name", value: DataType.string },
|
|
128
|
+
2274716: { name: "language", value: DataType.string },
|
|
129
|
+
134: { name: "codecID", value: DataType.string },
|
|
130
|
+
25506: { name: "codecPrivate", value: DataType.binary },
|
|
131
|
+
2459272: { name: "codecName", value: DataType.string },
|
|
132
|
+
3839639: { name: "codecSettings", value: DataType.string },
|
|
133
|
+
3883072: { name: "codecInfoUrl", value: DataType.string },
|
|
134
|
+
2536e3: { name: "codecDownloadUrl", value: DataType.string },
|
|
135
|
+
170: { name: "codecDecodeAll", value: DataType.bool },
|
|
136
|
+
28587: { name: "trackOverlay", value: DataType.uint },
|
|
137
|
+
// Video
|
|
138
|
+
224: {
|
|
139
|
+
name: "video",
|
|
140
|
+
container: {
|
|
141
|
+
154: { name: "flagInterlaced", value: DataType.bool },
|
|
142
|
+
21432: { name: "stereoMode", value: DataType.uint },
|
|
143
|
+
176: { name: "pixelWidth", value: DataType.uint },
|
|
144
|
+
186: { name: "pixelHeight", value: DataType.uint },
|
|
145
|
+
21680: { name: "displayWidth", value: DataType.uint },
|
|
146
|
+
21690: { name: "displayHeight", value: DataType.uint },
|
|
147
|
+
21683: { name: "aspectRatioType", value: DataType.uint },
|
|
148
|
+
3061028: { name: "colourSpace", value: DataType.uint },
|
|
149
|
+
3126563: { name: "gammaValue", value: DataType.float }
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
// Audio
|
|
153
|
+
225: {
|
|
154
|
+
name: "audio",
|
|
155
|
+
container: {
|
|
156
|
+
181: { name: "samplingFrequency", value: DataType.float },
|
|
157
|
+
30901: { name: "outputSamplingFrequency", value: DataType.float },
|
|
158
|
+
159: { name: "channels", value: DataType.uint },
|
|
159
|
+
// https://www.matroska.org/technical/specs/index.html
|
|
160
|
+
148: { name: "channels", value: DataType.uint },
|
|
161
|
+
32123: { name: "channelPositions", value: DataType.binary },
|
|
162
|
+
25188: { name: "bitDepth", value: DataType.uint }
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
// Content Encoding
|
|
166
|
+
28032: {
|
|
167
|
+
name: "contentEncodings",
|
|
168
|
+
container: {
|
|
169
|
+
25152: {
|
|
170
|
+
name: "contentEncoding",
|
|
171
|
+
container: {
|
|
172
|
+
20529: { name: "order", value: DataType.uint },
|
|
173
|
+
20530: { name: "scope", value: DataType.bool },
|
|
174
|
+
20531: { name: "type", value: DataType.uint },
|
|
175
|
+
20532: {
|
|
176
|
+
name: "contentEncoding",
|
|
177
|
+
container: {
|
|
178
|
+
16980: { name: "contentCompAlgo", value: DataType.uint },
|
|
179
|
+
16981: { name: "contentCompSettings", value: DataType.binary }
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
20533: {
|
|
183
|
+
name: "contentEncoding",
|
|
184
|
+
container: {
|
|
185
|
+
18401: { name: "contentEncAlgo", value: DataType.uint },
|
|
186
|
+
18402: { name: "contentEncKeyID", value: DataType.binary },
|
|
187
|
+
18403: { name: "contentSignature ", value: DataType.binary },
|
|
188
|
+
18404: { name: "ContentSigKeyID ", value: DataType.binary },
|
|
189
|
+
18405: { name: "contentSigAlgo ", value: DataType.uint },
|
|
190
|
+
18406: { name: "contentSigHashAlgo ", value: DataType.uint }
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
25188: { name: "bitDepth", value: DataType.uint }
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
// Cueing Data
|
|
203
|
+
475249515: {
|
|
204
|
+
name: "cues",
|
|
205
|
+
container: {
|
|
206
|
+
187: {
|
|
207
|
+
name: "cuePoint",
|
|
208
|
+
container: {
|
|
209
|
+
179: { name: "cueTime", value: DataType.uid },
|
|
210
|
+
183: {
|
|
211
|
+
name: "positions",
|
|
212
|
+
container: {
|
|
213
|
+
247: { name: "track", value: DataType.uint },
|
|
214
|
+
241: { name: "clusterPosition", value: DataType.uint },
|
|
215
|
+
21368: { name: "blockNumber", value: DataType.uint },
|
|
216
|
+
234: { name: "codecState", value: DataType.uint },
|
|
217
|
+
219: {
|
|
218
|
+
name: "reference",
|
|
219
|
+
container: {
|
|
220
|
+
150: { name: "time", value: DataType.uint },
|
|
221
|
+
151: { name: "cluster", value: DataType.uint },
|
|
222
|
+
21343: { name: "number", value: DataType.uint },
|
|
223
|
+
235: { name: "codecState", value: DataType.uint }
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
240: { name: "relativePosition", value: DataType.uint }
|
|
227
|
+
// extended
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
// Attachment
|
|
235
|
+
423732329: {
|
|
236
|
+
name: "attachments",
|
|
237
|
+
container: {
|
|
238
|
+
24999: {
|
|
239
|
+
name: "attachedFiles",
|
|
240
|
+
multiple: true,
|
|
241
|
+
container: {
|
|
242
|
+
18046: { name: "description", value: DataType.string },
|
|
243
|
+
18030: { name: "name", value: DataType.string },
|
|
244
|
+
18016: { name: "mimeType", value: DataType.string },
|
|
245
|
+
18012: { name: "data", value: DataType.binary },
|
|
246
|
+
18094: { name: "uid", value: DataType.uid }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
// Chapters
|
|
252
|
+
272869232: {
|
|
253
|
+
name: "chapters",
|
|
254
|
+
container: {
|
|
255
|
+
17849: {
|
|
256
|
+
name: "editionEntry",
|
|
257
|
+
container: {
|
|
258
|
+
182: {
|
|
259
|
+
name: "chapterAtom",
|
|
260
|
+
container: {
|
|
261
|
+
29636: { name: "uid", value: DataType.uid },
|
|
262
|
+
145: { name: "timeStart", value: DataType.uint },
|
|
263
|
+
146: { name: "timeEnd", value: DataType.uid },
|
|
264
|
+
152: { name: "hidden", value: DataType.bool },
|
|
265
|
+
17816: { name: "enabled", value: DataType.uid },
|
|
266
|
+
143: {
|
|
267
|
+
name: "track",
|
|
268
|
+
container: {
|
|
269
|
+
137: { name: "trackNumber", value: DataType.uid },
|
|
270
|
+
128: {
|
|
271
|
+
name: "display",
|
|
272
|
+
container: {
|
|
273
|
+
133: { name: "string", value: DataType.string },
|
|
274
|
+
17276: { name: "language ", value: DataType.string },
|
|
275
|
+
17278: { name: "country ", value: DataType.string }
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
// Tagging
|
|
287
|
+
307544935: {
|
|
288
|
+
name: "tags",
|
|
289
|
+
container: {
|
|
290
|
+
29555: {
|
|
291
|
+
name: "tag",
|
|
292
|
+
multiple: true,
|
|
293
|
+
container: {
|
|
294
|
+
25536: {
|
|
295
|
+
name: "target",
|
|
296
|
+
container: {
|
|
297
|
+
25541: { name: "tagTrackUID", value: DataType.uid },
|
|
298
|
+
25540: { name: "tagChapterUID", value: DataType.uint },
|
|
299
|
+
25542: { name: "tagAttachmentUID", value: DataType.uid },
|
|
300
|
+
25546: { name: "targetType", value: DataType.string },
|
|
301
|
+
// extended
|
|
302
|
+
26826: { name: "targetTypeValue", value: DataType.uint },
|
|
303
|
+
// extended
|
|
304
|
+
25545: { name: "tagEditionUID", value: DataType.uid }
|
|
305
|
+
// extended
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
26568: {
|
|
309
|
+
name: "simpleTags",
|
|
310
|
+
multiple: true,
|
|
311
|
+
container: {
|
|
312
|
+
17827: { name: "name", value: DataType.string },
|
|
313
|
+
17543: { name: "string", value: DataType.string },
|
|
314
|
+
17541: { name: "binary", value: DataType.binary },
|
|
315
|
+
17530: { name: "language", value: DataType.string },
|
|
316
|
+
// extended
|
|
317
|
+
17531: { name: "languageIETF", value: DataType.string },
|
|
318
|
+
// extended
|
|
319
|
+
17540: { name: "default", value: DataType.bool }
|
|
320
|
+
// extended
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// ../../node_modules/.pnpm/music-metadata@11.12.0/node_modules/music-metadata/lib/ebml/EbmlIterator.js
|
|
333
|
+
var import_debug = __toESM(require_src(), 1);
|
|
334
|
+
var debug = (0, import_debug.default)("music-metadata:parser:ebml");
|
|
335
|
+
var EbmlContentError = class extends makeUnexpectedFileContentError("EBML") {
|
|
336
|
+
};
|
|
337
|
+
var ParseAction = {
|
|
338
|
+
ReadNext: 0,
|
|
339
|
+
// Continue reading the next elements
|
|
340
|
+
IgnoreElement: 2,
|
|
341
|
+
// Ignore (do not read) this element
|
|
342
|
+
SkipSiblings: 3,
|
|
343
|
+
// Skip all remaining elements at the same level
|
|
344
|
+
TerminateParsing: 4,
|
|
345
|
+
// Terminate the parsing process
|
|
346
|
+
SkipElement: 5
|
|
347
|
+
// Consider the element has read, assume position is at the next element
|
|
348
|
+
};
|
|
349
|
+
var EbmlIterator = class {
|
|
350
|
+
/**
|
|
351
|
+
* @param {ITokenizer} tokenizer Input
|
|
352
|
+
* @param tokenizer
|
|
353
|
+
*/
|
|
354
|
+
constructor(tokenizer) {
|
|
355
|
+
this.parserMap = /* @__PURE__ */ new Map();
|
|
356
|
+
this.ebmlMaxIDLength = 4;
|
|
357
|
+
this.ebmlMaxSizeLength = 8;
|
|
358
|
+
this.tokenizer = tokenizer;
|
|
359
|
+
this.parserMap.set(DataType.uint, (e) => this.readUint(e));
|
|
360
|
+
this.parserMap.set(DataType.string, (e) => this.readString(e));
|
|
361
|
+
this.parserMap.set(DataType.binary, (e) => this.readBuffer(e));
|
|
362
|
+
this.parserMap.set(DataType.uid, async (e) => this.readBuffer(e));
|
|
363
|
+
this.parserMap.set(DataType.bool, (e) => this.readFlag(e));
|
|
364
|
+
this.parserMap.set(DataType.float, (e) => this.readFloat(e));
|
|
365
|
+
}
|
|
366
|
+
async iterate(dtdElement, posDone, listener) {
|
|
367
|
+
return this.parseContainer(linkParents(dtdElement), posDone, listener);
|
|
368
|
+
}
|
|
369
|
+
async parseContainer(dtdElement, posDone, listener) {
|
|
370
|
+
const tree = {};
|
|
371
|
+
while (this.tokenizer.position < posDone) {
|
|
372
|
+
let element;
|
|
373
|
+
const elementPosition = this.tokenizer.position;
|
|
374
|
+
try {
|
|
375
|
+
element = await this.readElement();
|
|
376
|
+
} catch (error) {
|
|
377
|
+
if (error instanceof EndOfStreamError) {
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
const child = dtdElement.container[element.id];
|
|
383
|
+
if (child) {
|
|
384
|
+
const action = listener.startNext(child);
|
|
385
|
+
switch (action) {
|
|
386
|
+
case ParseAction.ReadNext:
|
|
387
|
+
{
|
|
388
|
+
if (element.id === 524531317) {
|
|
389
|
+
}
|
|
390
|
+
debug(`Read element: name=${getElementPath(child)}{id=0x${element.id.toString(16)}, container=${!!child.container}} at position=${elementPosition}`);
|
|
391
|
+
if (child.container) {
|
|
392
|
+
const res = await this.parseContainer(child, element.len >= 0 ? this.tokenizer.position + element.len : -1, listener);
|
|
393
|
+
if (child.multiple) {
|
|
394
|
+
if (!tree[child.name]) {
|
|
395
|
+
tree[child.name] = [];
|
|
396
|
+
}
|
|
397
|
+
tree[child.name].push(res);
|
|
398
|
+
} else {
|
|
399
|
+
tree[child.name] = res;
|
|
400
|
+
}
|
|
401
|
+
await listener.elementValue(child, res, elementPosition);
|
|
402
|
+
} else {
|
|
403
|
+
const parser = this.parserMap.get(child.value);
|
|
404
|
+
if (typeof parser === "function") {
|
|
405
|
+
const value = await parser(element);
|
|
406
|
+
tree[child.name] = value;
|
|
407
|
+
await listener.elementValue(child, value, elementPosition);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
break;
|
|
412
|
+
case ParseAction.SkipElement:
|
|
413
|
+
debug(`Go to next element: name=${getElementPath(child)}, element.id=0x${element.id}, container=${!!child.container} at position=${elementPosition}`);
|
|
414
|
+
break;
|
|
415
|
+
case ParseAction.IgnoreElement:
|
|
416
|
+
debug(`Ignore element: name=${getElementPath(child)}, element.id=0x${element.id}, container=${!!child.container} at position=${elementPosition}`);
|
|
417
|
+
await this.tokenizer.ignore(element.len);
|
|
418
|
+
break;
|
|
419
|
+
case ParseAction.SkipSiblings:
|
|
420
|
+
debug(`Ignore remaining container, at: name=${getElementPath(child)}, element.id=0x${element.id}, container=${!!child.container} at position=${elementPosition}`);
|
|
421
|
+
await this.tokenizer.ignore(posDone - this.tokenizer.position);
|
|
422
|
+
break;
|
|
423
|
+
case ParseAction.TerminateParsing:
|
|
424
|
+
debug(`Terminate parsing at element: name=${getElementPath(child)}, element.id=0x${element.id}, container=${!!child.container} at position=${elementPosition}`);
|
|
425
|
+
return tree;
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
switch (element.id) {
|
|
429
|
+
case 236:
|
|
430
|
+
await this.tokenizer.ignore(element.len);
|
|
431
|
+
break;
|
|
432
|
+
default:
|
|
433
|
+
debug(`parseEbml: parent=${getElementPath(dtdElement)}, unknown child: id=${element.id.toString(16)} at position=${elementPosition}`);
|
|
434
|
+
await this.tokenizer.ignore(element.len);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return tree;
|
|
439
|
+
}
|
|
440
|
+
async readVintData(maxLength) {
|
|
441
|
+
const msb = await this.tokenizer.peekNumber(UINT8);
|
|
442
|
+
let mask = 128;
|
|
443
|
+
let oc = 1;
|
|
444
|
+
while ((msb & mask) === 0) {
|
|
445
|
+
if (oc > maxLength) {
|
|
446
|
+
throw new EbmlContentError("VINT value exceeding maximum size");
|
|
447
|
+
}
|
|
448
|
+
++oc;
|
|
449
|
+
mask >>= 1;
|
|
450
|
+
}
|
|
451
|
+
const id = new Uint8Array(oc);
|
|
452
|
+
await this.tokenizer.readBuffer(id);
|
|
453
|
+
return id;
|
|
454
|
+
}
|
|
455
|
+
async readElement() {
|
|
456
|
+
const id = await this.readVintData(this.ebmlMaxIDLength);
|
|
457
|
+
const lenField = await this.readVintData(this.ebmlMaxSizeLength);
|
|
458
|
+
lenField[0] ^= 128 >> lenField.length - 1;
|
|
459
|
+
return {
|
|
460
|
+
id: readUIntBE(id, id.length),
|
|
461
|
+
len: readUIntBE(lenField, lenField.length)
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
async readFloat(e) {
|
|
465
|
+
switch (e.len) {
|
|
466
|
+
case 0:
|
|
467
|
+
return 0;
|
|
468
|
+
case 4:
|
|
469
|
+
return this.tokenizer.readNumber(Float32_BE);
|
|
470
|
+
case 8:
|
|
471
|
+
return this.tokenizer.readNumber(Float64_BE);
|
|
472
|
+
case 10:
|
|
473
|
+
return this.tokenizer.readNumber(Float64_BE);
|
|
474
|
+
default:
|
|
475
|
+
throw new EbmlContentError(`Invalid IEEE-754 float length: ${e.len}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
async readFlag(e) {
|
|
479
|
+
return await this.readUint(e) === 1;
|
|
480
|
+
}
|
|
481
|
+
async readUint(e) {
|
|
482
|
+
const buf = await this.readBuffer(e);
|
|
483
|
+
return readUIntBE(buf, e.len);
|
|
484
|
+
}
|
|
485
|
+
async readString(e) {
|
|
486
|
+
const rawString = await this.tokenizer.readToken(new StringType(e.len, "utf-8"));
|
|
487
|
+
return rawString.replace(/\x00.*$/g, "");
|
|
488
|
+
}
|
|
489
|
+
async readBuffer(e) {
|
|
490
|
+
const buf = new Uint8Array(e.len);
|
|
491
|
+
await this.tokenizer.readBuffer(buf);
|
|
492
|
+
return buf;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
function readUIntBE(buf, len) {
|
|
496
|
+
return Number(readUIntBeAsBigInt(buf, len));
|
|
497
|
+
}
|
|
498
|
+
function readUIntBeAsBigInt(buf, len) {
|
|
499
|
+
const normalizedNumber = new Uint8Array(8);
|
|
500
|
+
const cleanNumber = buf.subarray(0, len);
|
|
501
|
+
try {
|
|
502
|
+
normalizedNumber.set(cleanNumber, 8 - len);
|
|
503
|
+
return UINT64_BE.get(normalizedNumber, 0);
|
|
504
|
+
} catch (_error) {
|
|
505
|
+
return BigInt(-1);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function linkParents(element) {
|
|
509
|
+
if (element.container) {
|
|
510
|
+
Object.keys(element.container).map((id) => {
|
|
511
|
+
const child = element.container[id];
|
|
512
|
+
child.id = Number.parseInt(id, 10);
|
|
513
|
+
return child;
|
|
514
|
+
}).forEach((child) => {
|
|
515
|
+
child.parent = element;
|
|
516
|
+
linkParents(child);
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
return element;
|
|
520
|
+
}
|
|
521
|
+
function getElementPath(element) {
|
|
522
|
+
let path = "";
|
|
523
|
+
if (element.parent && element.parent.name !== "dtd") {
|
|
524
|
+
path += `${getElementPath(element.parent)}/`;
|
|
525
|
+
}
|
|
526
|
+
return path + element.name;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// ../../node_modules/.pnpm/music-metadata@11.12.0/node_modules/music-metadata/lib/matroska/MatroskaParser.js
|
|
530
|
+
var debug2 = (0, import_debug2.default)("music-metadata:parser:matroska");
|
|
531
|
+
var MatroskaParser = class extends BasicParser {
|
|
532
|
+
constructor() {
|
|
533
|
+
super(...arguments);
|
|
534
|
+
this.seekHeadOffset = 0;
|
|
535
|
+
this.flagUseIndexToSkipClusters = this.options.mkvUseIndex ?? false;
|
|
536
|
+
}
|
|
537
|
+
async parse() {
|
|
538
|
+
const containerSize = this.tokenizer.fileInfo.size ?? Number.MAX_SAFE_INTEGER;
|
|
539
|
+
const matroskaIterator = new EbmlIterator(this.tokenizer);
|
|
540
|
+
debug2("Initializing DTD end MatroskaIterator");
|
|
541
|
+
await matroskaIterator.iterate(matroskaDtd, containerSize, {
|
|
542
|
+
startNext: (element) => {
|
|
543
|
+
switch (element.id) {
|
|
544
|
+
// case 0x1f43b675: // cluster
|
|
545
|
+
case 475249515:
|
|
546
|
+
debug2(`Skip element: name=${element.name}, id=0x${element.id.toString(16)}`);
|
|
547
|
+
return ParseAction.IgnoreElement;
|
|
548
|
+
case 524531317:
|
|
549
|
+
if (this.flagUseIndexToSkipClusters && this.seekHead) {
|
|
550
|
+
const index = this.seekHead.seek.find((index2) => index2.position + this.seekHeadOffset > this.tokenizer.position);
|
|
551
|
+
if (index) {
|
|
552
|
+
const ignoreSize = index.position + this.seekHeadOffset - this.tokenizer.position;
|
|
553
|
+
debug2(`Use index to go to next position, ignoring ${ignoreSize} bytes`);
|
|
554
|
+
this.tokenizer.ignore(ignoreSize);
|
|
555
|
+
return ParseAction.SkipElement;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return ParseAction.IgnoreElement;
|
|
559
|
+
default:
|
|
560
|
+
return ParseAction.ReadNext;
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
elementValue: async (element, value, offset) => {
|
|
564
|
+
debug2(`Received: name=${element.name}, value=${value}`);
|
|
565
|
+
switch (element.id) {
|
|
566
|
+
case 17026:
|
|
567
|
+
this.metadata.setFormat("container", `EBML/${value}`);
|
|
568
|
+
break;
|
|
569
|
+
case 290298740:
|
|
570
|
+
this.seekHead = value;
|
|
571
|
+
this.seekHeadOffset = offset;
|
|
572
|
+
break;
|
|
573
|
+
case 357149030:
|
|
574
|
+
{
|
|
575
|
+
const info = value;
|
|
576
|
+
const timecodeScale = info.timecodeScale ? info.timecodeScale : 1e6;
|
|
577
|
+
if (typeof info.duration === "number") {
|
|
578
|
+
const duration = info.duration * timecodeScale / 1e9;
|
|
579
|
+
await this.addTag("segment:title", info.title);
|
|
580
|
+
this.metadata.setFormat("duration", Number(duration));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
break;
|
|
584
|
+
case 374648427:
|
|
585
|
+
{
|
|
586
|
+
const audioTracks = value;
|
|
587
|
+
if (audioTracks?.entries) {
|
|
588
|
+
audioTracks.entries.forEach((entry) => {
|
|
589
|
+
const stream = {
|
|
590
|
+
codecName: entry.codecID.replace("A_", "").replace("V_", ""),
|
|
591
|
+
codecSettings: entry.codecSettings,
|
|
592
|
+
flagDefault: entry.flagDefault,
|
|
593
|
+
flagLacing: entry.flagLacing,
|
|
594
|
+
flagEnabled: entry.flagEnabled,
|
|
595
|
+
language: entry.language,
|
|
596
|
+
name: entry.name,
|
|
597
|
+
type: entry.trackType,
|
|
598
|
+
audio: entry.audio,
|
|
599
|
+
video: entry.video
|
|
600
|
+
};
|
|
601
|
+
this.metadata.addStreamInfo(stream);
|
|
602
|
+
});
|
|
603
|
+
const audioTrack = audioTracks.entries.filter((entry) => entry.trackType === TrackType.audio).reduce((acc, cur) => {
|
|
604
|
+
if (!acc)
|
|
605
|
+
return cur;
|
|
606
|
+
if (cur.flagDefault && !acc.flagDefault)
|
|
607
|
+
return cur;
|
|
608
|
+
if (cur.trackNumber < acc.trackNumber)
|
|
609
|
+
return cur;
|
|
610
|
+
return acc;
|
|
611
|
+
}, null);
|
|
612
|
+
if (audioTrack) {
|
|
613
|
+
this.metadata.setFormat("codec", audioTrack.codecID.replace("A_", ""));
|
|
614
|
+
this.metadata.setFormat("sampleRate", audioTrack.audio.samplingFrequency);
|
|
615
|
+
this.metadata.setFormat("numberOfChannels", audioTrack.audio.channels);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
break;
|
|
620
|
+
case 307544935:
|
|
621
|
+
{
|
|
622
|
+
const tags = value;
|
|
623
|
+
await Promise.all(tags.tag.map(async (tag) => {
|
|
624
|
+
const target = tag.target;
|
|
625
|
+
const targetType = target?.targetTypeValue ? TargetType[target.targetTypeValue] : target?.targetType ? target.targetType : "track";
|
|
626
|
+
await Promise.all(tag.simpleTags.map(async (simpleTag) => {
|
|
627
|
+
const value2 = simpleTag.string ? simpleTag.string : simpleTag.binary;
|
|
628
|
+
await this.addTag(`${targetType}:${simpleTag.name}`, value2);
|
|
629
|
+
}));
|
|
630
|
+
}));
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
case 423732329:
|
|
634
|
+
{
|
|
635
|
+
const attachments = value;
|
|
636
|
+
await Promise.all(attachments.attachedFiles.filter((file) => file.mimeType.startsWith("image/")).map((file) => this.addTag("picture", {
|
|
637
|
+
data: file.data,
|
|
638
|
+
format: file.mimeType,
|
|
639
|
+
description: file.description,
|
|
640
|
+
name: file.name
|
|
641
|
+
})));
|
|
642
|
+
}
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
async addTag(tagId, value) {
|
|
649
|
+
await this.metadata.addTag("matroska", tagId, value);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
export {
|
|
653
|
+
MatroskaParser
|
|
654
|
+
};
|