@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.
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/adf.mjs +162 -0
- package/dist/chunks/APEv2Parser-2CNNHMXV.mjs +22 -0
- package/dist/chunks/AiffParser-7BR4RL6G.mjs +162 -0
- package/dist/chunks/App-L5L37JI5.mjs +16747 -0
- package/dist/chunks/AsfParser-VVRSLFOM.mjs +538 -0
- package/dist/chunks/DsdiffParser-CMD4AX7A.mjs +156 -0
- package/dist/chunks/DsfParser-UOGZDS2M.mjs +94 -0
- package/dist/chunks/FlacParser-HB3T3CD4.mjs +23 -0
- package/dist/chunks/MP4Parser-66HBRUSX.mjs +973 -0
- package/dist/chunks/MatroskaParser-J3HUIMEW.mjs +579 -0
- package/dist/chunks/MpegParser-YW6LIUEW.mjs +442 -0
- package/dist/chunks/MusepackParser-PAUSXP7D.mjs +252 -0
- package/dist/chunks/OggParser-NUBV3GWC.mjs +359 -0
- package/dist/chunks/WavPackParser-WQAGT7TC.mjs +171 -0
- package/dist/chunks/WaveParser-EWLQVDX4.mjs +238 -0
- package/dist/chunks/adf-schema-JRU2BTOG.mjs +62 -0
- package/dist/chunks/build-QF5W473T.mjs +60 -0
- package/dist/chunks/chatgpt-subscription-BQGWYZXE.mjs +23 -0
- package/dist/chunks/chunk-2DIECGFL.mjs +6 -0
- package/dist/chunks/chunk-2NAP2ZF7.mjs +60 -0
- package/dist/chunks/chunk-3AT7IIP7.mjs +25696 -0
- package/dist/chunks/chunk-3GNIDM53.mjs +35 -0
- package/dist/chunks/chunk-3M4ZPOA3.mjs +1477 -0
- package/dist/chunks/chunk-4MQPTCXY.mjs +510 -0
- package/dist/chunks/chunk-5PO5PKRV.mjs +366 -0
- package/dist/chunks/chunk-5QU5VY7N.mjs +52 -0
- package/dist/chunks/chunk-5W7KES6P.mjs +436 -0
- package/dist/chunks/chunk-62NE4LG4.mjs +61 -0
- package/dist/chunks/chunk-64OKE4X3.mjs +45 -0
- package/dist/chunks/chunk-6GJ4QHRI.mjs +1278 -0
- package/dist/chunks/chunk-6VQEXLE2.mjs +144 -0
- package/dist/chunks/chunk-6XUV6EK6.mjs +41 -0
- package/dist/chunks/chunk-776TSXEP.mjs +43 -0
- package/dist/chunks/chunk-7CV2SA3H.mjs +285 -0
- package/dist/chunks/chunk-7MTRVW2U.mjs +3103 -0
- package/dist/chunks/chunk-7N2R2VCG.mjs +1434 -0
- package/dist/chunks/chunk-7T2YMTWL.mjs +374 -0
- package/dist/chunks/chunk-7XYNI52E.mjs +149 -0
- package/dist/chunks/chunk-APHX6HSV.mjs +7731 -0
- package/dist/chunks/chunk-APRU6PHC.mjs +40 -0
- package/dist/chunks/chunk-AUYKRQPJ.mjs +499 -0
- package/dist/chunks/chunk-DXWDD5XJ.mjs +136 -0
- package/dist/chunks/chunk-EWL5FG4I.mjs +39 -0
- package/dist/chunks/chunk-EYX2YLJW.mjs +117 -0
- package/dist/chunks/chunk-F5ELW46V.mjs +27 -0
- package/dist/chunks/chunk-G426FACA.mjs +49 -0
- package/dist/chunks/chunk-GEKSJHIV.mjs +2472 -0
- package/dist/chunks/chunk-HBUENVQL.mjs +570 -0
- package/dist/chunks/chunk-HPVFJYXR.mjs +112 -0
- package/dist/chunks/chunk-HWLWPXQ7.mjs +721 -0
- package/dist/chunks/chunk-I2HJYHFT.mjs +665 -0
- package/dist/chunks/chunk-I3UYSITV.mjs +68 -0
- package/dist/chunks/chunk-IC4JDZCI.mjs +3864 -0
- package/dist/chunks/chunk-IHDDCZBS.mjs +112 -0
- package/dist/chunks/chunk-IIGMZHQQ.mjs +10416 -0
- package/dist/chunks/chunk-KWFOS5WC.mjs +41 -0
- package/dist/chunks/chunk-LAZIXV2F.mjs +5290 -0
- package/dist/chunks/chunk-LFMB4PAA.mjs +10814 -0
- package/dist/chunks/chunk-M2RX3S2T.mjs +49 -0
- package/dist/chunks/chunk-M3WPIJYM.mjs +65 -0
- package/dist/chunks/chunk-NBTUWMGP.mjs +263 -0
- package/dist/chunks/chunk-NGK6PVSF.mjs +2676 -0
- package/dist/chunks/chunk-NZ7JTHEO.mjs +85 -0
- package/dist/chunks/chunk-OQN33RGQ.mjs +52 -0
- package/dist/chunks/chunk-RIX34QHC.mjs +2935 -0
- package/dist/chunks/chunk-SGUTYISF.mjs +16 -0
- package/dist/chunks/chunk-SLJ5L7PY.mjs +1473 -0
- package/dist/chunks/chunk-SLUKGXKH.mjs +68 -0
- package/dist/chunks/chunk-TMT32MXT.mjs +419 -0
- package/dist/chunks/chunk-UYY5M2PB.mjs +151 -0
- package/dist/chunks/chunk-VAUOM3IN.mjs +298 -0
- package/dist/chunks/chunk-VMHTYDH4.mjs +172 -0
- package/dist/chunks/chunk-VZS54AA5.mjs +200 -0
- package/dist/chunks/chunk-WFQUVXML.mjs +295 -0
- package/dist/chunks/chunk-X34PDRUH.mjs +809 -0
- package/dist/chunks/chunk-XNPZBLYL.mjs +33 -0
- package/dist/chunks/chunk-XX7OSWTO.mjs +157 -0
- package/dist/chunks/chunk-XYTWGHFS.mjs +600 -0
- package/dist/chunks/chunk-XYV3VCIX.mjs +336 -0
- package/dist/chunks/chunk-Y5ZLKFLE.mjs +1469 -0
- package/dist/chunks/chunk-ZJKXHM4Q.mjs +230 -0
- package/dist/chunks/cli-TCMBNZF6.mjs +1030 -0
- package/dist/chunks/commands-DTEKM4ZL.mjs +20 -0
- package/dist/chunks/daemon-ZC3FZ2P4.mjs +112449 -0
- package/dist/chunks/daemon-control-WDX7PMTC.mjs +300 -0
- package/dist/chunks/daemon-token-WRSULP7G.mjs +23 -0
- package/dist/chunks/devtools-H7CI2ZVG.mjs +85 -0
- package/dist/chunks/discord-IWDQJA7A.mjs +70588 -0
- package/dist/chunks/dist-C57KYFS2.mjs +4952 -0
- package/dist/chunks/dist-I3XBAGDL.mjs +11 -0
- package/dist/chunks/email-V4Q4VJON.mjs +58679 -0
- package/dist/chunks/environment-NX277MQG.mjs +15 -0
- package/dist/chunks/grok-subscription-4PYX7TBF.mjs +19 -0
- package/dist/chunks/layout-EPJQNFAI.mjs +22 -0
- package/dist/chunks/lib-N7FCZWKH.mjs +4038 -0
- package/dist/chunks/open-OTQDGDH5.mjs +36 -0
- package/dist/chunks/parser-JVY2PWSM.mjs +19 -0
- package/dist/chunks/pipeline-executor-BHBSJX2K.mjs +19 -0
- package/dist/chunks/react-IUIDQ5LX.mjs +11 -0
- package/dist/chunks/screen-54BUTYCW.mjs +27 -0
- package/dist/chunks/slack-3L5QTDZX.mjs +8113 -0
- package/dist/chunks/store-WR7TZJZS.mjs +32 -0
- package/dist/chunks/telegram-5ISVFBV3.mjs +14918 -0
- package/dist/chunks/terminal-O5WO7C5U.mjs +48 -0
- package/dist/chunks/theme-NORU4J74.mjs +20 -0
- package/dist/chunks/themes-F2FKU7CP.mjs +23 -0
- package/dist/chunks/token-6G3HCMNX.mjs +54 -0
- package/dist/chunks/token-util-UXYSDQIW.mjs +12 -0
- package/dist/chunks/tui-ODVYUIMT.mjs +197 -0
- package/dist/chunks/welcome-XHXFV7SH.mjs +32 -0
- package/dist/chunks/whatsapp-XSAMNGPJ.mjs +85412 -0
- package/dist/chunks/xterm-headless-YF53XWXE.mjs +3353 -0
- package/package.json +53 -0
- package/resources/wasm/coreutils.LICENSE +18 -0
- package/resources/wasm/coreutils.wasm +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(x, {
|
|
13
|
+
get: (a, b) => (typeof require < "u" ? require : a)[b]
|
|
14
|
+
}) : x)(function(x) {
|
|
15
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
16
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
|
+
});
|
|
18
|
+
var __esm = (fn, res) => function() {
|
|
19
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
20
|
+
};
|
|
21
|
+
var __commonJS = (cb, mod) => function() {
|
|
22
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
23
|
+
};
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
27
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
39
|
+
mod
|
|
40
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
__require,
|
|
44
|
+
__esm,
|
|
45
|
+
__commonJS,
|
|
46
|
+
__export,
|
|
47
|
+
__toESM,
|
|
48
|
+
__toCommonJS
|
|
49
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
external_exports
|
|
9
|
+
} from "./chunk-ZJKXHM4Q.mjs";
|
|
10
|
+
|
|
11
|
+
// src/shared/types/form-hints.types.ts
|
|
12
|
+
var FORM_CONTENT_TYPE = "application/vnd.adf.form+json", idPattern = /^[a-z0-9_-]+$/, FormOptionSchema = external_exports.object({
|
|
13
|
+
id: external_exports.string().min(1).max(8).regex(idPattern),
|
|
14
|
+
label: external_exports.string().min(1).max(100)
|
|
15
|
+
}), FormQuestionSchema = external_exports.object({
|
|
16
|
+
id: external_exports.string().min(1).max(8).regex(idPattern),
|
|
17
|
+
text: external_exports.string().min(1).max(1e3),
|
|
18
|
+
type: external_exports.enum(["choice", "multi", "text"]),
|
|
19
|
+
options: external_exports.array(FormOptionSchema).min(1).max(12).optional(),
|
|
20
|
+
required: external_exports.boolean().optional()
|
|
21
|
+
}).refine(
|
|
22
|
+
(q) => q.type === "text" || q.options && q.options.length > 0,
|
|
23
|
+
{ message: "choice/multi questions require options" }
|
|
24
|
+
), FormHintSchema = external_exports.object({
|
|
25
|
+
id: external_exports.string().min(1).max(16).regex(idPattern),
|
|
26
|
+
title: external_exports.string().max(200).optional(),
|
|
27
|
+
questions: external_exports.array(FormQuestionSchema).min(1).max(10),
|
|
28
|
+
/**
|
|
29
|
+
* REQUIRED rendering choice — the agent owns this decision; the adapter
|
|
30
|
+
* only validates and dispatches. A choice the form's shape doesn't satisfy
|
|
31
|
+
* fails the delivery with the precise reason. Telegram surfaces:
|
|
32
|
+
* 'poll' (native poll — single choice/multi question, 2-10 options,
|
|
33
|
+
* title+question <=300 chars, option labels <=100), 'compact' (one message,
|
|
34
|
+
* one combined keyboard — no text questions), 'per_question' (one message
|
|
35
|
+
* per question, any shape). Adapters without native form surfaces render
|
|
36
|
+
* the plain-text questionnaire regardless of this field.
|
|
37
|
+
*/
|
|
38
|
+
render: external_exports.enum(["poll", "compact", "per_question"]),
|
|
39
|
+
/** Verbatim plain-text rendering used by adapters without native form support */
|
|
40
|
+
fallback_text: external_exports.string().max(4e3).optional()
|
|
41
|
+
});
|
|
42
|
+
function parseFormHint(value) {
|
|
43
|
+
let result = FormHintSchema.safeParse(value);
|
|
44
|
+
return result.success ? result.data : null;
|
|
45
|
+
}
|
|
46
|
+
function encodeFormAction(formId, questionId, optionId) {
|
|
47
|
+
return `f|${formId}|${questionId}|${optionId}`;
|
|
48
|
+
}
|
|
49
|
+
function decodeFormAction(data) {
|
|
50
|
+
let parts = data.split("|");
|
|
51
|
+
if (parts.length !== 4 || parts[0] !== "f") return null;
|
|
52
|
+
let [, formId, questionId, optionId] = parts;
|
|
53
|
+
return !formId || !questionId || !optionId ? null : { formId, questionId, optionId };
|
|
54
|
+
}
|
|
55
|
+
var FORM_MULTI_DONE = "__done", FORM_ANSWERED = "__answered";
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
FORM_CONTENT_TYPE,
|
|
59
|
+
FormHintSchema,
|
|
60
|
+
parseFormHint,
|
|
61
|
+
encodeFormAction,
|
|
62
|
+
decodeFormAction,
|
|
63
|
+
FORM_MULTI_DONE,
|
|
64
|
+
FORM_ANSWERED
|
|
65
|
+
};
|
|
@@ -0,0 +1,263 @@
|
|
|
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
|
+
a2hex,
|
|
9
|
+
findZero
|
|
10
|
+
} from "./chunk-XX7OSWTO.mjs";
|
|
11
|
+
import {
|
|
12
|
+
fromBuffer
|
|
13
|
+
} from "./chunk-HBUENVQL.mjs";
|
|
14
|
+
import {
|
|
15
|
+
BasicParser,
|
|
16
|
+
FieldDecodingError,
|
|
17
|
+
InternalParserError,
|
|
18
|
+
StringType,
|
|
19
|
+
UINT16_LE,
|
|
20
|
+
UINT32_LE,
|
|
21
|
+
Uint8ArrayType,
|
|
22
|
+
makeUnexpectedFileContentError,
|
|
23
|
+
textDecode,
|
|
24
|
+
textEncode
|
|
25
|
+
} from "./chunk-I2HJYHFT.mjs";
|
|
26
|
+
import {
|
|
27
|
+
require_src
|
|
28
|
+
} from "./chunk-AUYKRQPJ.mjs";
|
|
29
|
+
import {
|
|
30
|
+
__toESM
|
|
31
|
+
} from "./chunk-M2RX3S2T.mjs";
|
|
32
|
+
|
|
33
|
+
// node_modules/music-metadata/lib/apev2/APEv2Parser.js
|
|
34
|
+
var import_debug = __toESM(require_src(), 1);
|
|
35
|
+
|
|
36
|
+
// node_modules/music-metadata/lib/common/FourCC.js
|
|
37
|
+
var validFourCC = /^[\x21-\x7e©][\x20-\x7e\x00()]{3}/, FourCcToken = {
|
|
38
|
+
len: 4,
|
|
39
|
+
get: (buf, off) => {
|
|
40
|
+
let id = textDecode(buf.subarray(off, off + FourCcToken.len), "latin1");
|
|
41
|
+
if (!id.match(validFourCC))
|
|
42
|
+
throw new FieldDecodingError(`FourCC contains invalid characters: ${a2hex(id)} "${id}"`);
|
|
43
|
+
return id;
|
|
44
|
+
},
|
|
45
|
+
put: (buffer, offset, id) => {
|
|
46
|
+
let str = textEncode(id, "latin1");
|
|
47
|
+
if (str.length !== 4)
|
|
48
|
+
throw new InternalParserError("Invalid length");
|
|
49
|
+
return buffer.set(str, offset), offset + 4;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// node_modules/music-metadata/lib/apev2/APEv2Token.js
|
|
54
|
+
var DataType = {
|
|
55
|
+
text_utf8: 0,
|
|
56
|
+
binary: 1,
|
|
57
|
+
external_info: 2,
|
|
58
|
+
reserved: 3
|
|
59
|
+
}, DescriptorParser = {
|
|
60
|
+
len: 52,
|
|
61
|
+
get: (buf, off) => ({
|
|
62
|
+
// should equal 'MAC '
|
|
63
|
+
ID: FourCcToken.get(buf, off),
|
|
64
|
+
// versionIndex number * 1000 (3.81 = 3810) (remember that 4-byte alignment causes this to take 4-bytes)
|
|
65
|
+
version: UINT32_LE.get(buf, off + 4) / 1e3,
|
|
66
|
+
// the number of descriptor bytes (allows later expansion of this header)
|
|
67
|
+
descriptorBytes: UINT32_LE.get(buf, off + 8),
|
|
68
|
+
// the number of header APE_HEADER bytes
|
|
69
|
+
headerBytes: UINT32_LE.get(buf, off + 12),
|
|
70
|
+
// the number of header APE_HEADER bytes
|
|
71
|
+
seekTableBytes: UINT32_LE.get(buf, off + 16),
|
|
72
|
+
// the number of header data bytes (from original file)
|
|
73
|
+
headerDataBytes: UINT32_LE.get(buf, off + 20),
|
|
74
|
+
// the number of bytes of APE frame data
|
|
75
|
+
apeFrameDataBytes: UINT32_LE.get(buf, off + 24),
|
|
76
|
+
// the high order number of APE frame data bytes
|
|
77
|
+
apeFrameDataBytesHigh: UINT32_LE.get(buf, off + 28),
|
|
78
|
+
// the terminating data of the file (not including tag data)
|
|
79
|
+
terminatingDataBytes: UINT32_LE.get(buf, off + 32),
|
|
80
|
+
// the MD5 hash of the file (see notes for usage... it's a little tricky)
|
|
81
|
+
fileMD5: new Uint8ArrayType(16).get(buf, off + 36)
|
|
82
|
+
})
|
|
83
|
+
}, Header = {
|
|
84
|
+
len: 24,
|
|
85
|
+
get: (buf, off) => ({
|
|
86
|
+
// the compression level (see defines I.E. COMPRESSION_LEVEL_FAST)
|
|
87
|
+
compressionLevel: UINT16_LE.get(buf, off),
|
|
88
|
+
// any format flags (for future use)
|
|
89
|
+
formatFlags: UINT16_LE.get(buf, off + 2),
|
|
90
|
+
// the number of audio blocks in one frame
|
|
91
|
+
blocksPerFrame: UINT32_LE.get(buf, off + 4),
|
|
92
|
+
// the number of audio blocks in the final frame
|
|
93
|
+
finalFrameBlocks: UINT32_LE.get(buf, off + 8),
|
|
94
|
+
// the total number of frames
|
|
95
|
+
totalFrames: UINT32_LE.get(buf, off + 12),
|
|
96
|
+
// the bits per sample (typically 16)
|
|
97
|
+
bitsPerSample: UINT16_LE.get(buf, off + 16),
|
|
98
|
+
// the number of channels (1 or 2)
|
|
99
|
+
channel: UINT16_LE.get(buf, off + 18),
|
|
100
|
+
// the sample rate (typically 44100)
|
|
101
|
+
sampleRate: UINT32_LE.get(buf, off + 20)
|
|
102
|
+
})
|
|
103
|
+
}, TagFooter = {
|
|
104
|
+
len: 32,
|
|
105
|
+
get: (buf, off) => ({
|
|
106
|
+
// should equal 'APETAGEX'
|
|
107
|
+
ID: new StringType(8, "ascii").get(buf, off),
|
|
108
|
+
// equals CURRENT_APE_TAG_VERSION
|
|
109
|
+
version: UINT32_LE.get(buf, off + 8),
|
|
110
|
+
// the complete size of the tag, including this footer (excludes header)
|
|
111
|
+
size: UINT32_LE.get(buf, off + 12),
|
|
112
|
+
// the number of fields in the tag
|
|
113
|
+
fields: UINT32_LE.get(buf, off + 16),
|
|
114
|
+
// reserved for later use (must be zero),
|
|
115
|
+
flags: parseTagFlags(UINT32_LE.get(buf, off + 20))
|
|
116
|
+
})
|
|
117
|
+
}, TagItemHeader = {
|
|
118
|
+
len: 8,
|
|
119
|
+
get: (buf, off) => ({
|
|
120
|
+
// Length of assigned value in bytes
|
|
121
|
+
size: UINT32_LE.get(buf, off),
|
|
122
|
+
// reserved for later use (must be zero),
|
|
123
|
+
flags: parseTagFlags(UINT32_LE.get(buf, off + 4))
|
|
124
|
+
})
|
|
125
|
+
};
|
|
126
|
+
function parseTagFlags(flags) {
|
|
127
|
+
return {
|
|
128
|
+
containsHeader: isBitSet(flags, 31),
|
|
129
|
+
containsFooter: isBitSet(flags, 30),
|
|
130
|
+
isHeader: isBitSet(flags, 29),
|
|
131
|
+
readOnly: isBitSet(flags, 0),
|
|
132
|
+
dataType: (flags & 6) >> 1
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function isBitSet(num, bit) {
|
|
136
|
+
return (num & 1 << bit) !== 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// node_modules/music-metadata/lib/apev2/APEv2Parser.js
|
|
140
|
+
var debug = (0, import_debug.default)("music-metadata:parser:APEv2"), tagFormat = "APEv2", preamble = "APETAGEX", ApeContentError = class extends makeUnexpectedFileContentError("APEv2") {
|
|
141
|
+
};
|
|
142
|
+
function tryParseApeHeader(metadata, tokenizer, options) {
|
|
143
|
+
return new APEv2Parser(metadata, tokenizer, options).tryParseApeHeader();
|
|
144
|
+
}
|
|
145
|
+
var APEv2Parser = class _APEv2Parser extends BasicParser {
|
|
146
|
+
constructor() {
|
|
147
|
+
super(...arguments), this.ape = {};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Calculate the media file duration
|
|
151
|
+
* @param ah ApeHeader
|
|
152
|
+
* @return {number} duration in seconds
|
|
153
|
+
*/
|
|
154
|
+
static calculateDuration(ah) {
|
|
155
|
+
let duration = ah.totalFrames > 1 ? ah.blocksPerFrame * (ah.totalFrames - 1) : 0;
|
|
156
|
+
return duration += ah.finalFrameBlocks, duration / ah.sampleRate;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Calculates the APEv1 / APEv2 first field offset
|
|
160
|
+
* @param tokenizer
|
|
161
|
+
* @param offset
|
|
162
|
+
*/
|
|
163
|
+
static async findApeFooterOffset(tokenizer, offset) {
|
|
164
|
+
let apeBuf = new Uint8Array(TagFooter.len), position = tokenizer.position;
|
|
165
|
+
if (offset <= TagFooter.len) {
|
|
166
|
+
debug(`Offset is too small to read APE footer: offset=${offset}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (offset > TagFooter.len) {
|
|
170
|
+
await tokenizer.readBuffer(apeBuf, { position: offset - TagFooter.len }), tokenizer.setPosition(position);
|
|
171
|
+
let tagFooter = TagFooter.get(apeBuf, 0);
|
|
172
|
+
if (tagFooter.ID === "APETAGEX")
|
|
173
|
+
return tagFooter.flags.isHeader ? debug(`APE Header found at offset=${offset - TagFooter.len}`) : (debug(`APE Footer found at offset=${offset - TagFooter.len}`), offset -= tagFooter.size), { footer: tagFooter, offset };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
static parseTagFooter(metadata, buffer, options) {
|
|
177
|
+
let footer = TagFooter.get(buffer, buffer.length - TagFooter.len);
|
|
178
|
+
if (footer.ID !== preamble)
|
|
179
|
+
throw new ApeContentError("Unexpected APEv2 Footer ID preamble value");
|
|
180
|
+
return fromBuffer(buffer), new _APEv2Parser(metadata, fromBuffer(buffer), options).parseTags(footer);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Parse APEv1 / APEv2 header if header signature found
|
|
184
|
+
*/
|
|
185
|
+
async tryParseApeHeader() {
|
|
186
|
+
if (this.tokenizer.fileInfo.size && this.tokenizer.fileInfo.size - this.tokenizer.position < TagFooter.len) {
|
|
187
|
+
debug("No APEv2 header found, end-of-file reached");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
let footer = await this.tokenizer.peekToken(TagFooter);
|
|
191
|
+
if (footer.ID === preamble)
|
|
192
|
+
return await this.tokenizer.ignore(TagFooter.len), this.parseTags(footer);
|
|
193
|
+
if (debug(`APEv2 header not found at offset=${this.tokenizer.position}`), this.tokenizer.fileInfo.size) {
|
|
194
|
+
let remaining = this.tokenizer.fileInfo.size - this.tokenizer.position, buffer = new Uint8Array(remaining);
|
|
195
|
+
return await this.tokenizer.readBuffer(buffer), _APEv2Parser.parseTagFooter(this.metadata, buffer, this.options);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async parse() {
|
|
199
|
+
let descriptor = await this.tokenizer.readToken(DescriptorParser);
|
|
200
|
+
if (descriptor.ID !== "MAC ")
|
|
201
|
+
throw new ApeContentError("Unexpected descriptor ID");
|
|
202
|
+
this.ape.descriptor = descriptor;
|
|
203
|
+
let lenExp = descriptor.descriptorBytes - DescriptorParser.len, header = await (lenExp > 0 ? this.parseDescriptorExpansion(lenExp) : this.parseHeader());
|
|
204
|
+
return this.metadata.setAudioOnly(), await this.tokenizer.ignore(header.forwardBytes), this.tryParseApeHeader();
|
|
205
|
+
}
|
|
206
|
+
async parseTags(footer) {
|
|
207
|
+
let keyBuffer = new Uint8Array(256), bytesRemaining = footer.size - TagFooter.len;
|
|
208
|
+
debug(`Parse APE tags at offset=${this.tokenizer.position}, size=${bytesRemaining}`);
|
|
209
|
+
for (let i = 0; i < footer.fields; i++) {
|
|
210
|
+
if (bytesRemaining < TagItemHeader.len) {
|
|
211
|
+
this.metadata.addWarning(`APEv2 Tag-header: ${footer.fields - i} items remaining, but no more tag data to read.`);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
let tagItemHeader = await this.tokenizer.readToken(TagItemHeader);
|
|
215
|
+
bytesRemaining -= TagItemHeader.len + tagItemHeader.size, await this.tokenizer.peekBuffer(keyBuffer, { length: Math.min(keyBuffer.length, bytesRemaining) });
|
|
216
|
+
let zero = findZero(keyBuffer), key = await this.tokenizer.readToken(new StringType(zero, "ascii"));
|
|
217
|
+
switch (await this.tokenizer.ignore(1), bytesRemaining -= key.length + 1, tagItemHeader.flags.dataType) {
|
|
218
|
+
case DataType.text_utf8: {
|
|
219
|
+
let values = (await this.tokenizer.readToken(new StringType(tagItemHeader.size, "utf8"))).split(/\x00/g);
|
|
220
|
+
await Promise.all(values.map((val) => this.metadata.addTag(tagFormat, key, val)));
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case DataType.binary:
|
|
224
|
+
if (this.options.skipCovers)
|
|
225
|
+
await this.tokenizer.ignore(tagItemHeader.size);
|
|
226
|
+
else {
|
|
227
|
+
let picData = new Uint8Array(tagItemHeader.size);
|
|
228
|
+
await this.tokenizer.readBuffer(picData), zero = findZero(picData);
|
|
229
|
+
let description = textDecode(picData.subarray(0, zero), "utf-8"), data = picData.subarray(zero + 1);
|
|
230
|
+
await this.metadata.addTag(tagFormat, key, {
|
|
231
|
+
description,
|
|
232
|
+
data
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
case DataType.external_info:
|
|
237
|
+
debug(`Ignore external info ${key}`), await this.tokenizer.ignore(tagItemHeader.size);
|
|
238
|
+
break;
|
|
239
|
+
case DataType.reserved:
|
|
240
|
+
debug(`Ignore external info ${key}`), this.metadata.addWarning(`APEv2 header declares a reserved datatype for "${key}"`), await this.tokenizer.ignore(tagItemHeader.size);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async parseDescriptorExpansion(lenExp) {
|
|
246
|
+
return await this.tokenizer.ignore(lenExp), this.parseHeader();
|
|
247
|
+
}
|
|
248
|
+
async parseHeader() {
|
|
249
|
+
let header = await this.tokenizer.readToken(Header);
|
|
250
|
+
if (this.metadata.setFormat("lossless", !0), this.metadata.setFormat("container", "Monkey's Audio"), this.metadata.setFormat("bitsPerSample", header.bitsPerSample), this.metadata.setFormat("sampleRate", header.sampleRate), this.metadata.setFormat("numberOfChannels", header.channel), this.metadata.setFormat("duration", _APEv2Parser.calculateDuration(header)), !this.ape.descriptor)
|
|
251
|
+
throw new ApeContentError("Missing APE descriptor");
|
|
252
|
+
return {
|
|
253
|
+
forwardBytes: this.ape.descriptor.seekTableBytes + this.ape.descriptor.headerDataBytes + this.ape.descriptor.apeFrameDataBytes + this.ape.descriptor.terminatingDataBytes
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export {
|
|
259
|
+
FourCcToken,
|
|
260
|
+
ApeContentError,
|
|
261
|
+
tryParseApeHeader,
|
|
262
|
+
APEv2Parser
|
|
263
|
+
};
|