@agentdocumentformat/cli 0.7.2

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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -0
  3. package/dist/adf.mjs +162 -0
  4. package/dist/chunks/APEv2Parser-2CNNHMXV.mjs +22 -0
  5. package/dist/chunks/AiffParser-7BR4RL6G.mjs +162 -0
  6. package/dist/chunks/App-L5L37JI5.mjs +16747 -0
  7. package/dist/chunks/AsfParser-VVRSLFOM.mjs +538 -0
  8. package/dist/chunks/DsdiffParser-CMD4AX7A.mjs +156 -0
  9. package/dist/chunks/DsfParser-UOGZDS2M.mjs +94 -0
  10. package/dist/chunks/FlacParser-HB3T3CD4.mjs +23 -0
  11. package/dist/chunks/MP4Parser-66HBRUSX.mjs +973 -0
  12. package/dist/chunks/MatroskaParser-J3HUIMEW.mjs +579 -0
  13. package/dist/chunks/MpegParser-YW6LIUEW.mjs +442 -0
  14. package/dist/chunks/MusepackParser-PAUSXP7D.mjs +252 -0
  15. package/dist/chunks/OggParser-NUBV3GWC.mjs +359 -0
  16. package/dist/chunks/WavPackParser-WQAGT7TC.mjs +171 -0
  17. package/dist/chunks/WaveParser-EWLQVDX4.mjs +238 -0
  18. package/dist/chunks/adf-schema-JRU2BTOG.mjs +62 -0
  19. package/dist/chunks/build-QF5W473T.mjs +60 -0
  20. package/dist/chunks/chatgpt-subscription-BQGWYZXE.mjs +23 -0
  21. package/dist/chunks/chunk-2DIECGFL.mjs +6 -0
  22. package/dist/chunks/chunk-2NAP2ZF7.mjs +60 -0
  23. package/dist/chunks/chunk-3AT7IIP7.mjs +25696 -0
  24. package/dist/chunks/chunk-3GNIDM53.mjs +35 -0
  25. package/dist/chunks/chunk-3M4ZPOA3.mjs +1477 -0
  26. package/dist/chunks/chunk-4MQPTCXY.mjs +510 -0
  27. package/dist/chunks/chunk-5PO5PKRV.mjs +366 -0
  28. package/dist/chunks/chunk-5QU5VY7N.mjs +52 -0
  29. package/dist/chunks/chunk-5W7KES6P.mjs +436 -0
  30. package/dist/chunks/chunk-62NE4LG4.mjs +61 -0
  31. package/dist/chunks/chunk-64OKE4X3.mjs +45 -0
  32. package/dist/chunks/chunk-6GJ4QHRI.mjs +1278 -0
  33. package/dist/chunks/chunk-6VQEXLE2.mjs +144 -0
  34. package/dist/chunks/chunk-6XUV6EK6.mjs +41 -0
  35. package/dist/chunks/chunk-776TSXEP.mjs +43 -0
  36. package/dist/chunks/chunk-7CV2SA3H.mjs +285 -0
  37. package/dist/chunks/chunk-7MTRVW2U.mjs +3103 -0
  38. package/dist/chunks/chunk-7N2R2VCG.mjs +1434 -0
  39. package/dist/chunks/chunk-7T2YMTWL.mjs +374 -0
  40. package/dist/chunks/chunk-7XYNI52E.mjs +149 -0
  41. package/dist/chunks/chunk-APHX6HSV.mjs +7731 -0
  42. package/dist/chunks/chunk-APRU6PHC.mjs +40 -0
  43. package/dist/chunks/chunk-AUYKRQPJ.mjs +499 -0
  44. package/dist/chunks/chunk-DXWDD5XJ.mjs +136 -0
  45. package/dist/chunks/chunk-EWL5FG4I.mjs +39 -0
  46. package/dist/chunks/chunk-EYX2YLJW.mjs +117 -0
  47. package/dist/chunks/chunk-F5ELW46V.mjs +27 -0
  48. package/dist/chunks/chunk-G426FACA.mjs +49 -0
  49. package/dist/chunks/chunk-GEKSJHIV.mjs +2472 -0
  50. package/dist/chunks/chunk-HBUENVQL.mjs +570 -0
  51. package/dist/chunks/chunk-HPVFJYXR.mjs +112 -0
  52. package/dist/chunks/chunk-HWLWPXQ7.mjs +721 -0
  53. package/dist/chunks/chunk-I2HJYHFT.mjs +665 -0
  54. package/dist/chunks/chunk-I3UYSITV.mjs +68 -0
  55. package/dist/chunks/chunk-IC4JDZCI.mjs +3864 -0
  56. package/dist/chunks/chunk-IHDDCZBS.mjs +112 -0
  57. package/dist/chunks/chunk-IIGMZHQQ.mjs +10416 -0
  58. package/dist/chunks/chunk-KWFOS5WC.mjs +41 -0
  59. package/dist/chunks/chunk-LAZIXV2F.mjs +5290 -0
  60. package/dist/chunks/chunk-LFMB4PAA.mjs +10814 -0
  61. package/dist/chunks/chunk-M2RX3S2T.mjs +49 -0
  62. package/dist/chunks/chunk-M3WPIJYM.mjs +65 -0
  63. package/dist/chunks/chunk-NBTUWMGP.mjs +263 -0
  64. package/dist/chunks/chunk-NGK6PVSF.mjs +2676 -0
  65. package/dist/chunks/chunk-NZ7JTHEO.mjs +85 -0
  66. package/dist/chunks/chunk-OQN33RGQ.mjs +52 -0
  67. package/dist/chunks/chunk-RIX34QHC.mjs +2935 -0
  68. package/dist/chunks/chunk-SGUTYISF.mjs +16 -0
  69. package/dist/chunks/chunk-SLJ5L7PY.mjs +1473 -0
  70. package/dist/chunks/chunk-SLUKGXKH.mjs +68 -0
  71. package/dist/chunks/chunk-TMT32MXT.mjs +419 -0
  72. package/dist/chunks/chunk-UYY5M2PB.mjs +151 -0
  73. package/dist/chunks/chunk-VAUOM3IN.mjs +298 -0
  74. package/dist/chunks/chunk-VMHTYDH4.mjs +172 -0
  75. package/dist/chunks/chunk-VZS54AA5.mjs +200 -0
  76. package/dist/chunks/chunk-WFQUVXML.mjs +295 -0
  77. package/dist/chunks/chunk-X34PDRUH.mjs +809 -0
  78. package/dist/chunks/chunk-XNPZBLYL.mjs +33 -0
  79. package/dist/chunks/chunk-XX7OSWTO.mjs +157 -0
  80. package/dist/chunks/chunk-XYTWGHFS.mjs +600 -0
  81. package/dist/chunks/chunk-XYV3VCIX.mjs +336 -0
  82. package/dist/chunks/chunk-Y5ZLKFLE.mjs +1469 -0
  83. package/dist/chunks/chunk-ZJKXHM4Q.mjs +230 -0
  84. package/dist/chunks/cli-TCMBNZF6.mjs +1030 -0
  85. package/dist/chunks/commands-DTEKM4ZL.mjs +20 -0
  86. package/dist/chunks/daemon-ZC3FZ2P4.mjs +112449 -0
  87. package/dist/chunks/daemon-control-WDX7PMTC.mjs +300 -0
  88. package/dist/chunks/daemon-token-WRSULP7G.mjs +23 -0
  89. package/dist/chunks/devtools-H7CI2ZVG.mjs +85 -0
  90. package/dist/chunks/discord-IWDQJA7A.mjs +70588 -0
  91. package/dist/chunks/dist-C57KYFS2.mjs +4952 -0
  92. package/dist/chunks/dist-I3XBAGDL.mjs +11 -0
  93. package/dist/chunks/email-V4Q4VJON.mjs +58679 -0
  94. package/dist/chunks/environment-NX277MQG.mjs +15 -0
  95. package/dist/chunks/grok-subscription-4PYX7TBF.mjs +19 -0
  96. package/dist/chunks/layout-EPJQNFAI.mjs +22 -0
  97. package/dist/chunks/lib-N7FCZWKH.mjs +4038 -0
  98. package/dist/chunks/open-OTQDGDH5.mjs +36 -0
  99. package/dist/chunks/parser-JVY2PWSM.mjs +19 -0
  100. package/dist/chunks/pipeline-executor-BHBSJX2K.mjs +19 -0
  101. package/dist/chunks/react-IUIDQ5LX.mjs +11 -0
  102. package/dist/chunks/screen-54BUTYCW.mjs +27 -0
  103. package/dist/chunks/slack-3L5QTDZX.mjs +8113 -0
  104. package/dist/chunks/store-WR7TZJZS.mjs +32 -0
  105. package/dist/chunks/telegram-5ISVFBV3.mjs +14918 -0
  106. package/dist/chunks/terminal-O5WO7C5U.mjs +48 -0
  107. package/dist/chunks/theme-NORU4J74.mjs +20 -0
  108. package/dist/chunks/themes-F2FKU7CP.mjs +23 -0
  109. package/dist/chunks/token-6G3HCMNX.mjs +54 -0
  110. package/dist/chunks/token-util-UXYSDQIW.mjs +12 -0
  111. package/dist/chunks/tui-ODVYUIMT.mjs +197 -0
  112. package/dist/chunks/welcome-XHXFV7SH.mjs +32 -0
  113. package/dist/chunks/whatsapp-XSAMNGPJ.mjs +85412 -0
  114. package/dist/chunks/xterm-headless-YF53XWXE.mjs +3353 -0
  115. package/package.json +53 -0
  116. package/resources/wasm/coreutils.LICENSE +18 -0
  117. package/resources/wasm/coreutils.wasm +0 -0
@@ -0,0 +1,252 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ AbstractID3Parser
9
+ } from "./chunk-62NE4LG4.mjs";
10
+ import "./chunk-XYTWGHFS.mjs";
11
+ import "./chunk-VAUOM3IN.mjs";
12
+ import "./chunk-DXWDD5XJ.mjs";
13
+ import {
14
+ FourCcToken,
15
+ tryParseApeHeader
16
+ } from "./chunk-NBTUWMGP.mjs";
17
+ import {
18
+ getBitAllignedNumber,
19
+ isBitSet
20
+ } from "./chunk-XX7OSWTO.mjs";
21
+ import "./chunk-HBUENVQL.mjs";
22
+ import {
23
+ BasicParser,
24
+ StringType,
25
+ UINT16_LE,
26
+ UINT32_LE,
27
+ UINT8,
28
+ makeUnexpectedFileContentError,
29
+ textDecode
30
+ } from "./chunk-I2HJYHFT.mjs";
31
+ import {
32
+ require_src
33
+ } from "./chunk-AUYKRQPJ.mjs";
34
+ import "./chunk-NZ7JTHEO.mjs";
35
+ import {
36
+ __toESM
37
+ } from "./chunk-M2RX3S2T.mjs";
38
+
39
+ // node_modules/music-metadata/lib/musepack/MusepackParser.js
40
+ var import_debug4 = __toESM(require_src(), 1);
41
+
42
+ // node_modules/music-metadata/lib/musepack/sv8/MpcSv8Parser.js
43
+ var import_debug2 = __toESM(require_src(), 1);
44
+
45
+ // node_modules/music-metadata/lib/musepack/sv8/StreamVersion8.js
46
+ var import_debug = __toESM(require_src(), 1);
47
+ var debug = (0, import_debug.default)("music-metadata:parser:musepack:sv8"), PacketKey = new StringType(2, "latin1"), SH_part1 = {
48
+ len: 5,
49
+ get: (buf, off) => ({
50
+ crc: UINT32_LE.get(buf, off),
51
+ streamVersion: UINT8.get(buf, off + 4)
52
+ })
53
+ }, SH_part3 = {
54
+ len: 2,
55
+ get: (buf, off) => ({
56
+ sampleFrequency: [44100, 48e3, 37800, 32e3][getBitAllignedNumber(buf, off, 0, 3)],
57
+ maxUsedBands: getBitAllignedNumber(buf, off, 3, 5),
58
+ channelCount: getBitAllignedNumber(buf, off + 1, 0, 4) + 1,
59
+ msUsed: isBitSet(buf, off + 1, 4),
60
+ audioBlockFrames: getBitAllignedNumber(buf, off + 1, 5, 3)
61
+ })
62
+ }, StreamReader = class {
63
+ get tokenizer() {
64
+ return this._tokenizer;
65
+ }
66
+ set tokenizer(value) {
67
+ this._tokenizer = value;
68
+ }
69
+ constructor(_tokenizer) {
70
+ this._tokenizer = _tokenizer;
71
+ }
72
+ async readPacketHeader() {
73
+ let key = await this.tokenizer.readToken(PacketKey), size = await this.readVariableSizeField();
74
+ return {
75
+ key,
76
+ payloadLength: size.value - 2 - size.len
77
+ };
78
+ }
79
+ async readStreamHeader(size) {
80
+ let streamHeader = {};
81
+ debug(`Reading SH at offset=${this.tokenizer.position}`);
82
+ let part1 = await this.tokenizer.readToken(SH_part1);
83
+ size -= SH_part1.len, Object.assign(streamHeader, part1), debug(`SH.streamVersion = ${part1.streamVersion}`);
84
+ let sampleCount = await this.readVariableSizeField();
85
+ size -= sampleCount.len, streamHeader.sampleCount = sampleCount.value;
86
+ let bs = await this.readVariableSizeField();
87
+ size -= bs.len, streamHeader.beginningOfSilence = bs.value;
88
+ let part3 = await this.tokenizer.readToken(SH_part3);
89
+ return size -= SH_part3.len, Object.assign(streamHeader, part3), await this.tokenizer.ignore(size), streamHeader;
90
+ }
91
+ async readVariableSizeField(len = 1, hb = 0) {
92
+ let n = await this.tokenizer.readNumber(UINT8);
93
+ return (n & 128) === 0 ? { len, value: hb + n } : (n &= 127, n += hb, this.readVariableSizeField(len + 1, n << 7));
94
+ }
95
+ };
96
+
97
+ // node_modules/music-metadata/lib/musepack/MusepackConentError.js
98
+ var MusepackContentError = class extends makeUnexpectedFileContentError("Musepack") {
99
+ };
100
+
101
+ // node_modules/music-metadata/lib/musepack/sv8/MpcSv8Parser.js
102
+ var debug2 = (0, import_debug2.default)("music-metadata:parser:musepack"), MpcSv8Parser = class extends BasicParser {
103
+ constructor() {
104
+ super(...arguments), this.audioLength = 0;
105
+ }
106
+ async parse() {
107
+ if (await this.tokenizer.readToken(FourCcToken) !== "MPCK")
108
+ throw new MusepackContentError("Invalid Magic number");
109
+ return this.metadata.setFormat("container", "Musepack, SV8"), this.parsePacket();
110
+ }
111
+ async parsePacket() {
112
+ let sv8reader = new StreamReader(this.tokenizer);
113
+ do {
114
+ let header = await sv8reader.readPacketHeader();
115
+ switch (debug2(`packet-header key=${header.key}, payloadLength=${header.payloadLength}`), header.key) {
116
+ case "SH": {
117
+ let sh = await sv8reader.readStreamHeader(header.payloadLength);
118
+ this.metadata.setFormat("numberOfSamples", sh.sampleCount), this.metadata.setFormat("sampleRate", sh.sampleFrequency), this.metadata.setFormat("duration", sh.sampleCount / sh.sampleFrequency), this.metadata.setFormat("numberOfChannels", sh.channelCount);
119
+ break;
120
+ }
121
+ case "AP":
122
+ this.audioLength += header.payloadLength, await this.tokenizer.ignore(header.payloadLength);
123
+ break;
124
+ case "RG":
125
+ // Replaygain
126
+ case "EI":
127
+ // Encoder Info
128
+ case "SO":
129
+ // Seek Table Offset
130
+ case "ST":
131
+ // Seek Table
132
+ case "CT":
133
+ await this.tokenizer.ignore(header.payloadLength);
134
+ break;
135
+ case "SE":
136
+ return this.metadata.format.duration && this.metadata.setFormat("bitrate", this.audioLength * 8 / this.metadata.format.duration), tryParseApeHeader(this.metadata, this.tokenizer, this.options);
137
+ default:
138
+ throw new MusepackContentError(`Unexpected header: ${header.key}`);
139
+ }
140
+ } while (!0);
141
+ }
142
+ };
143
+
144
+ // node_modules/music-metadata/lib/musepack/sv7/MpcSv7Parser.js
145
+ var import_debug3 = __toESM(require_src(), 1);
146
+
147
+ // node_modules/music-metadata/lib/musepack/sv7/BitReader.js
148
+ var BitReader = class {
149
+ constructor(tokenizer) {
150
+ this.pos = 0, this.dword = null, this.tokenizer = tokenizer;
151
+ }
152
+ /**
153
+ *
154
+ * @param bits 1..30 bits
155
+ */
156
+ async read(bits) {
157
+ for (; this.dword === null; )
158
+ this.dword = await this.tokenizer.readToken(UINT32_LE);
159
+ let out = this.dword;
160
+ return this.pos += bits, this.pos < 32 ? (out >>>= 32 - this.pos, out & (1 << bits) - 1) : (this.pos -= 32, this.pos === 0 ? (this.dword = null, out & (1 << bits) - 1) : (this.dword = await this.tokenizer.readToken(UINT32_LE), this.pos && (out <<= this.pos, out |= this.dword >>> 32 - this.pos), out & (1 << bits) - 1));
161
+ }
162
+ async ignore(bits) {
163
+ if (this.pos > 0) {
164
+ let remaining = 32 - this.pos;
165
+ this.dword = null, bits -= remaining, this.pos = 0;
166
+ }
167
+ let remainder = bits % 32, numOfWords = (bits - remainder) / 32;
168
+ return await this.tokenizer.ignore(numOfWords * 4), this.read(remainder);
169
+ }
170
+ };
171
+
172
+ // node_modules/music-metadata/lib/musepack/sv7/StreamVersion7.js
173
+ var Header = {
174
+ len: 24,
175
+ get: (buf, off) => {
176
+ let header = {
177
+ // word 0
178
+ signature: textDecode(buf.subarray(off, off + 3), "latin1"),
179
+ // versionIndex number * 1000 (3.81 = 3810) (remember that 4-byte alignment causes this to take 4-bytes)
180
+ streamMinorVersion: getBitAllignedNumber(buf, off + 3, 0, 4),
181
+ streamMajorVersion: getBitAllignedNumber(buf, off + 3, 4, 4),
182
+ // word 1
183
+ frameCount: UINT32_LE.get(buf, off + 4),
184
+ // word 2
185
+ maxLevel: UINT16_LE.get(buf, off + 8),
186
+ sampleFrequency: [44100, 48e3, 37800, 32e3][getBitAllignedNumber(buf, off + 10, 0, 2)],
187
+ link: getBitAllignedNumber(buf, off + 10, 2, 2),
188
+ profile: getBitAllignedNumber(buf, off + 10, 4, 4),
189
+ maxBand: getBitAllignedNumber(buf, off + 11, 0, 6),
190
+ intensityStereo: isBitSet(buf, off + 11, 6),
191
+ midSideStereo: isBitSet(buf, off + 11, 7),
192
+ // word 3
193
+ titlePeak: UINT16_LE.get(buf, off + 12),
194
+ titleGain: UINT16_LE.get(buf, off + 14),
195
+ // word 4
196
+ albumPeak: UINT16_LE.get(buf, off + 16),
197
+ albumGain: UINT16_LE.get(buf, off + 18),
198
+ // word
199
+ lastFrameLength: UINT32_LE.get(buf, off + 20) >>> 20 & 2047,
200
+ trueGapless: isBitSet(buf, off + 23, 0)
201
+ };
202
+ return header.lastFrameLength = header.trueGapless ? UINT32_LE.get(buf, 20) >>> 20 & 2047 : 0, header;
203
+ }
204
+ };
205
+
206
+ // node_modules/music-metadata/lib/musepack/sv7/MpcSv7Parser.js
207
+ var debug3 = (0, import_debug3.default)("music-metadata:parser:musepack"), MpcSv7Parser = class extends BasicParser {
208
+ constructor() {
209
+ super(...arguments), this.bitreader = null, this.audioLength = 0, this.duration = null;
210
+ }
211
+ async parse() {
212
+ let header = await this.tokenizer.readToken(Header);
213
+ if (header.signature !== "MP+")
214
+ throw new MusepackContentError("Unexpected magic number");
215
+ debug3(`stream-version=${header.streamMajorVersion}.${header.streamMinorVersion}`), this.metadata.setFormat("container", "Musepack, SV7"), this.metadata.setFormat("sampleRate", header.sampleFrequency);
216
+ let numberOfSamples = 1152 * (header.frameCount - 1) + header.lastFrameLength;
217
+ this.metadata.setFormat("numberOfSamples", numberOfSamples), this.duration = numberOfSamples / header.sampleFrequency, this.metadata.setFormat("duration", this.duration), this.bitreader = new BitReader(this.tokenizer), this.metadata.setFormat("numberOfChannels", header.midSideStereo || header.intensityStereo ? 2 : 1);
218
+ let version = await this.bitreader.read(8);
219
+ return this.metadata.setFormat("codec", (version / 100).toFixed(2)), await this.skipAudioData(header.frameCount), debug3(`End of audio stream, switching to APEv2, offset=${this.tokenizer.position}`), tryParseApeHeader(this.metadata, this.tokenizer, this.options);
220
+ }
221
+ async skipAudioData(frameCount) {
222
+ for (; frameCount-- > 0; ) {
223
+ let frameLength = await this.bitreader.read(20);
224
+ this.audioLength += 20 + frameLength, await this.bitreader.ignore(frameLength);
225
+ }
226
+ let lastFrameLength = await this.bitreader.read(11);
227
+ this.audioLength += lastFrameLength, this.duration !== null && this.metadata.setFormat("bitrate", this.audioLength / this.duration);
228
+ }
229
+ };
230
+
231
+ // node_modules/music-metadata/lib/musepack/MusepackParser.js
232
+ var debug4 = (0, import_debug4.default)("music-metadata:parser:musepack"), MusepackParser = class extends AbstractID3Parser {
233
+ async postId3v2Parse() {
234
+ let signature = await this.tokenizer.peekToken(new StringType(3, "latin1")), mpcParser;
235
+ switch (signature) {
236
+ case "MP+": {
237
+ debug4("Stream-version 7"), mpcParser = new MpcSv7Parser(this.metadata, this.tokenizer, this.options);
238
+ break;
239
+ }
240
+ case "MPC": {
241
+ debug4("Stream-version 8"), mpcParser = new MpcSv8Parser(this.metadata, this.tokenizer, this.options);
242
+ break;
243
+ }
244
+ default:
245
+ throw new MusepackContentError("Invalid signature prefix");
246
+ }
247
+ return this.metadata.setAudioOnly(), mpcParser.parse();
248
+ }
249
+ };
250
+ export {
251
+ MusepackParser
252
+ };
@@ -0,0 +1,359 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ BlockHeader,
9
+ BlockStreamInfo,
10
+ BlockType,
11
+ FlacParser,
12
+ VorbisPictureToken,
13
+ VorbisStream
14
+ } from "./chunk-7T2YMTWL.mjs";
15
+ import "./chunk-62NE4LG4.mjs";
16
+ import "./chunk-XYTWGHFS.mjs";
17
+ import "./chunk-VAUOM3IN.mjs";
18
+ import "./chunk-DXWDD5XJ.mjs";
19
+ import {
20
+ FourCcToken
21
+ } from "./chunk-NBTUWMGP.mjs";
22
+ import {
23
+ getBit,
24
+ trimRightNull
25
+ } from "./chunk-XX7OSWTO.mjs";
26
+ import {
27
+ EndOfStreamError
28
+ } from "./chunk-HBUENVQL.mjs";
29
+ import {
30
+ BasicParser,
31
+ INT32_LE,
32
+ StringType,
33
+ UINT16_BE,
34
+ UINT16_LE,
35
+ UINT24_BE,
36
+ UINT32_LE,
37
+ UINT64_LE,
38
+ UINT8,
39
+ Uint8ArrayType,
40
+ makeUnexpectedFileContentError
41
+ } from "./chunk-I2HJYHFT.mjs";
42
+ import {
43
+ require_src
44
+ } from "./chunk-AUYKRQPJ.mjs";
45
+ import "./chunk-NZ7JTHEO.mjs";
46
+ import {
47
+ __toESM
48
+ } from "./chunk-M2RX3S2T.mjs";
49
+
50
+ // node_modules/music-metadata/lib/ogg/OggParser.js
51
+ var import_debug4 = __toESM(require_src(), 1);
52
+
53
+ // node_modules/music-metadata/lib/ogg/opus/Opus.js
54
+ var OpusContentError = class extends makeUnexpectedFileContentError("Opus") {
55
+ }, IdHeader = class {
56
+ constructor(len) {
57
+ if (len < 19)
58
+ throw new OpusContentError("ID-header-page 0 should be at least 19 bytes long");
59
+ this.len = len;
60
+ }
61
+ get(buf, off) {
62
+ return {
63
+ magicSignature: new StringType(8, "ascii").get(buf, off + 0),
64
+ version: UINT8.get(buf, off + 8),
65
+ channelCount: UINT8.get(buf, off + 9),
66
+ preSkip: UINT16_LE.get(buf, off + 10),
67
+ inputSampleRate: UINT32_LE.get(buf, off + 12),
68
+ outputGain: UINT16_LE.get(buf, off + 16),
69
+ channelMapping: UINT8.get(buf, off + 18)
70
+ };
71
+ }
72
+ };
73
+
74
+ // node_modules/music-metadata/lib/ogg/opus/OpusStream.js
75
+ var OpusStream = class extends VorbisStream {
76
+ constructor(metadata, options, tokenizer) {
77
+ super(metadata, options), this.idHeader = null, this.lastPos = -1, this.tokenizer = tokenizer, this.durationOnLastPage = !0;
78
+ }
79
+ /**
80
+ * Parse first Opus Ogg page
81
+ * @param {IPageHeader} header
82
+ * @param {Uint8Array} pageData
83
+ */
84
+ parseFirstPage(_header, pageData) {
85
+ if (this.metadata.setFormat("codec", "Opus"), this.idHeader = new IdHeader(pageData.length).get(pageData, 0), this.idHeader.magicSignature !== "OpusHead")
86
+ throw new OpusContentError("Illegal ogg/Opus magic-signature");
87
+ this.metadata.setFormat("sampleRate", this.idHeader.inputSampleRate), this.metadata.setFormat("numberOfChannels", this.idHeader.channelCount), this.metadata.setAudioOnly();
88
+ }
89
+ async parseFullPage(pageData) {
90
+ new StringType(8, "ascii").get(pageData, 0) === "OpusTags" && (await this.parseUserCommentList(pageData, 8), this.lastPos = this.tokenizer.position - pageData.length);
91
+ }
92
+ calculateDuration(enfOfStream) {
93
+ if (this.lastPageHeader && (enfOfStream || this.lastPageHeader.headerType.lastPage) && this.metadata.format.sampleRate && this.lastPageHeader.absoluteGranulePosition >= 0) {
94
+ let pos_48bit = this.lastPageHeader.absoluteGranulePosition - this.idHeader.preSkip;
95
+ if (this.metadata.setFormat("numberOfSamples", pos_48bit), this.metadata.setFormat("duration", pos_48bit / 48e3), this.lastPos !== -1 && this.tokenizer.fileInfo.size && this.metadata.format.duration) {
96
+ let dataSize = this.tokenizer.fileInfo.size - this.lastPos;
97
+ this.metadata.setFormat("bitrate", 8 * dataSize / this.metadata.format.duration);
98
+ }
99
+ }
100
+ }
101
+ };
102
+
103
+ // node_modules/music-metadata/lib/ogg/speex/SpeexStream.js
104
+ var import_debug = __toESM(require_src(), 1);
105
+
106
+ // node_modules/music-metadata/lib/ogg/speex/Speex.js
107
+ var Header = {
108
+ len: 80,
109
+ get: (buf, off) => ({
110
+ speex: new StringType(8, "ascii").get(buf, off + 0),
111
+ version: trimRightNull(new StringType(20, "ascii").get(buf, off + 8)),
112
+ version_id: INT32_LE.get(buf, off + 28),
113
+ header_size: INT32_LE.get(buf, off + 32),
114
+ rate: INT32_LE.get(buf, off + 36),
115
+ mode: INT32_LE.get(buf, off + 40),
116
+ mode_bitstream_version: INT32_LE.get(buf, off + 44),
117
+ nb_channels: INT32_LE.get(buf, off + 48),
118
+ bitrate: INT32_LE.get(buf, off + 52),
119
+ frame_size: INT32_LE.get(buf, off + 56),
120
+ vbr: INT32_LE.get(buf, off + 60),
121
+ frames_per_packet: INT32_LE.get(buf, off + 64),
122
+ extra_headers: INT32_LE.get(buf, off + 68),
123
+ reserved1: INT32_LE.get(buf, off + 72),
124
+ reserved2: INT32_LE.get(buf, off + 76)
125
+ })
126
+ };
127
+
128
+ // node_modules/music-metadata/lib/ogg/speex/SpeexStream.js
129
+ var debug = (0, import_debug.default)("music-metadata:parser:ogg:speex"), SpeexStream = class extends VorbisStream {
130
+ constructor(metadata, options, _tokenizer) {
131
+ super(metadata, options);
132
+ }
133
+ /**
134
+ * Parse first Speex Ogg page
135
+ * @param {IPageHeader} header
136
+ * @param {Uint8Array} pageData
137
+ */
138
+ parseFirstPage(_header, pageData) {
139
+ debug("First Ogg/Speex page");
140
+ let speexHeader = Header.get(pageData, 0);
141
+ this.metadata.setFormat("codec", `Speex ${speexHeader.version}`), this.metadata.setFormat("numberOfChannels", speexHeader.nb_channels), this.metadata.setFormat("sampleRate", speexHeader.rate), speexHeader.bitrate !== -1 && this.metadata.setFormat("bitrate", speexHeader.bitrate), this.metadata.setAudioOnly();
142
+ }
143
+ };
144
+
145
+ // node_modules/music-metadata/lib/ogg/theora/TheoraStream.js
146
+ var import_debug2 = __toESM(require_src(), 1);
147
+
148
+ // node_modules/music-metadata/lib/ogg/theora/Theora.js
149
+ var IdentificationHeader = {
150
+ len: 42,
151
+ get: (buf, off) => ({
152
+ id: new StringType(7, "ascii").get(buf, off),
153
+ vmaj: UINT8.get(buf, off + 7),
154
+ vmin: UINT8.get(buf, off + 8),
155
+ vrev: UINT8.get(buf, off + 9),
156
+ vmbw: UINT16_BE.get(buf, off + 10),
157
+ vmbh: UINT16_BE.get(buf, off + 17),
158
+ nombr: UINT24_BE.get(buf, off + 37),
159
+ nqual: UINT8.get(buf, off + 40)
160
+ })
161
+ };
162
+
163
+ // node_modules/music-metadata/lib/ogg/theora/TheoraStream.js
164
+ var debug2 = (0, import_debug2.default)("music-metadata:parser:ogg:theora"), TheoraStream = class {
165
+ constructor(metadata, _options, _tokenizer) {
166
+ this.durationOnLastPage = !1, this.metadata = metadata;
167
+ }
168
+ /**
169
+ * Vorbis 1 parser
170
+ * @param header Ogg Page Header
171
+ * @param pageData Page data
172
+ */
173
+ async parsePage(header, pageData) {
174
+ header.headerType.firstPage && await this.parseFirstPage(header, pageData);
175
+ }
176
+ calculateDuration() {
177
+ debug2("duration calculation not implemented");
178
+ }
179
+ /**
180
+ * Parse first Theora Ogg page. the initial identification header packet
181
+ */
182
+ async parseFirstPage(_header, pageData) {
183
+ debug2("First Ogg/Theora page"), this.metadata.setFormat("codec", "Theora");
184
+ let idHeader = IdentificationHeader.get(pageData, 0);
185
+ this.metadata.setFormat("bitrate", idHeader.nombr), this.metadata.setFormat("hasVideo", !0);
186
+ }
187
+ flush() {
188
+ return Promise.resolve();
189
+ }
190
+ };
191
+
192
+ // node_modules/music-metadata/lib/ogg/OggToken.js
193
+ var PageHeader = {
194
+ len: 27,
195
+ get: (buf, off) => ({
196
+ capturePattern: new StringType(4, "latin1").get(buf, off),
197
+ version: UINT8.get(buf, off + 4),
198
+ headerType: {
199
+ continued: getBit(buf, off + 5, 0),
200
+ firstPage: getBit(buf, off + 5, 1),
201
+ lastPage: getBit(buf, off + 5, 2)
202
+ },
203
+ // packet_flag: Token.UINT8.get(buf, off + 5),
204
+ absoluteGranulePosition: Number(UINT64_LE.get(buf, off + 6)),
205
+ streamSerialNumber: UINT32_LE.get(buf, off + 14),
206
+ pageSequenceNo: UINT32_LE.get(buf, off + 18),
207
+ pageChecksum: UINT32_LE.get(buf, off + 22),
208
+ page_segments: UINT8.get(buf, off + 26)
209
+ })
210
+ }, SegmentTable = class _SegmentTable {
211
+ static sum(buf, off, len) {
212
+ let dv = new DataView(buf.buffer, 0), s = 0;
213
+ for (let i = off; i < off + len; ++i)
214
+ s += dv.getUint8(i);
215
+ return s;
216
+ }
217
+ constructor(header) {
218
+ this.len = header.page_segments;
219
+ }
220
+ get(buf, off) {
221
+ return {
222
+ totalPageSize: _SegmentTable.sum(buf, off, this.len)
223
+ };
224
+ }
225
+ };
226
+
227
+ // node_modules/music-metadata/lib/ogg/flac/FlacStream.js
228
+ var import_debug3 = __toESM(require_src(), 1);
229
+ var debug3 = (0, import_debug3.default)("music-metadata:parser:ogg:theora"), FlacStream = class {
230
+ constructor(metadata, options, tokenizer) {
231
+ this.durationOnLastPage = !1, this.metadata = metadata, this.options = options, this.tokenizer = tokenizer, this.flacParser = new FlacParser(this.metadata, this.tokenizer, options);
232
+ }
233
+ /**
234
+ * Vorbis 1 parser
235
+ * @param header Ogg Page Header
236
+ * @param pageData Page data
237
+ */
238
+ async parsePage(header, pageData) {
239
+ header.headerType.firstPage && await this.parseFirstPage(header, pageData);
240
+ }
241
+ calculateDuration() {
242
+ debug3("duration calculation not implemented");
243
+ }
244
+ /**
245
+ * Parse first Theora Ogg page. the initial identification header packet
246
+ */
247
+ async parseFirstPage(_header, pageData) {
248
+ if (debug3("First Ogg/FLAC page"), (await FourCcToken.get(pageData, 9)).toString() !== "fLaC")
249
+ throw new Error("Invalid FLAC preamble");
250
+ let blockHeader = await BlockHeader.get(pageData, 13);
251
+ await this.parseDataBlock(blockHeader, pageData.subarray(13 + BlockHeader.len));
252
+ }
253
+ async parseDataBlock(blockHeader, pageData) {
254
+ switch (debug3(`blockHeader type=${blockHeader.type}, length=${blockHeader.length}`), blockHeader.type) {
255
+ case BlockType.STREAMINFO: {
256
+ let streamInfo = BlockStreamInfo.get(pageData, 0);
257
+ return this.flacParser.processsStreamInfo(streamInfo);
258
+ }
259
+ case BlockType.PADDING:
260
+ break;
261
+ case BlockType.APPLICATION:
262
+ break;
263
+ case BlockType.SEEKTABLE:
264
+ break;
265
+ case BlockType.VORBIS_COMMENT:
266
+ return this.flacParser.parseComment(pageData);
267
+ case BlockType.PICTURE:
268
+ if (!this.options.skipCovers) {
269
+ let picture = new VorbisPictureToken(pageData.length).get(pageData, 0);
270
+ return this.flacParser.addPictureTag(picture);
271
+ }
272
+ break;
273
+ default:
274
+ this.metadata.addWarning(`Unknown block type: ${blockHeader.type}`);
275
+ }
276
+ return this.tokenizer.ignore(blockHeader.length).then();
277
+ }
278
+ flush() {
279
+ return Promise.resolve();
280
+ }
281
+ };
282
+
283
+ // node_modules/music-metadata/lib/ogg/OggParser.js
284
+ var OggContentError = class extends makeUnexpectedFileContentError("Ogg") {
285
+ }, debug4 = (0, import_debug4.default)("music-metadata:parser:ogg"), OggStream = class {
286
+ constructor(metadata, streamSerial, options) {
287
+ this.pageNumber = 0, this.closed = !1, this.metadata = metadata, this.streamSerial = streamSerial, this.options = options;
288
+ }
289
+ async parsePage(tokenizer, header) {
290
+ this.pageNumber = header.pageSequenceNo, debug4("serial=%s page#=%s, Ogg.id=%s", header.streamSerialNumber, header.pageSequenceNo, header.capturePattern);
291
+ let segmentTable = await tokenizer.readToken(new SegmentTable(header));
292
+ debug4("totalPageSize=%s", segmentTable.totalPageSize);
293
+ let pageData = await tokenizer.readToken(new Uint8ArrayType(segmentTable.totalPageSize));
294
+ if (debug4("firstPage=%s, lastPage=%s, continued=%s", header.headerType.firstPage, header.headerType.lastPage, header.headerType.continued), header.headerType.firstPage) {
295
+ this.metadata.setFormat("container", "Ogg");
296
+ let idData = pageData.subarray(0, 7), asciiId = Array.from(idData).filter((b) => b >= 32 && b <= 126).map((b) => String.fromCharCode(b)).join("");
297
+ switch (asciiId) {
298
+ case "vorbis":
299
+ debug4(`Set Ogg stream serial ${header.streamSerialNumber}, codec=Vorbis`), this.pageConsumer = new VorbisStream(this.metadata, this.options);
300
+ break;
301
+ case "OpusHea":
302
+ debug4("Set page consumer to Ogg/Opus"), this.pageConsumer = new OpusStream(this.metadata, this.options, tokenizer);
303
+ break;
304
+ case "Speex ":
305
+ debug4("Set page consumer to Ogg/Speex"), this.pageConsumer = new SpeexStream(this.metadata, this.options, tokenizer);
306
+ break;
307
+ case "fishead":
308
+ case "theora":
309
+ debug4("Set page consumer to Ogg/Theora"), this.pageConsumer = new TheoraStream(this.metadata, this.options, tokenizer);
310
+ break;
311
+ case "FLAC":
312
+ debug4("Set page consumer to Vorbis"), this.pageConsumer = new FlacStream(this.metadata, this.options, tokenizer);
313
+ break;
314
+ default:
315
+ throw new OggContentError(`Ogg codec not recognized (id=${asciiId}`);
316
+ }
317
+ }
318
+ if (header.headerType.lastPage && (this.closed = !0), this.pageConsumer)
319
+ await this.pageConsumer.parsePage(header, pageData);
320
+ else
321
+ throw new Error("pageConsumer should be initialized");
322
+ }
323
+ }, OggParser = class extends BasicParser {
324
+ constructor() {
325
+ super(...arguments), this.streams = /* @__PURE__ */ new Map();
326
+ }
327
+ /**
328
+ * Parse page
329
+ * @returns {Promise<void>}
330
+ */
331
+ async parse() {
332
+ this.streams = /* @__PURE__ */ new Map();
333
+ let enfOfStream = !1, header;
334
+ try {
335
+ do {
336
+ if (header = await this.tokenizer.readToken(PageHeader), header.capturePattern !== "OggS")
337
+ throw new OggContentError("Invalid Ogg capture pattern");
338
+ let stream = this.streams.get(header.streamSerialNumber);
339
+ if (stream || (stream = new OggStream(this.metadata, header.streamSerialNumber, this.options), this.streams.set(header.streamSerialNumber, stream)), await stream.parsePage(this.tokenizer, header), stream.pageNumber > 12 && !(this.options.duration && [...this.streams.values()].find((stream2) => stream2.pageConsumer?.durationOnLastPage))) {
340
+ debug4("Stop processing Ogg stream");
341
+ break;
342
+ }
343
+ } while (![...this.streams.values()].every((item) => item.closed));
344
+ } catch (err) {
345
+ if (err instanceof EndOfStreamError)
346
+ debug4("Reached end-of-stream"), enfOfStream = !0;
347
+ else if (err instanceof OggContentError)
348
+ this.metadata.addWarning(`Corrupt Ogg content at ${this.tokenizer.position}`);
349
+ else
350
+ throw err;
351
+ }
352
+ for (let stream of this.streams.values())
353
+ stream.closed || (this.metadata.addWarning(`End-of-stream reached before reaching last page in Ogg stream serial=${stream.streamSerial}`), await stream.pageConsumer?.flush()), stream.pageConsumer?.calculateDuration(enfOfStream);
354
+ }
355
+ };
356
+ export {
357
+ OggContentError,
358
+ OggParser
359
+ };