taglib-wasm 1.0.4 → 1.0.6
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 +38 -443
- package/dist/index.browser.d.ts +2 -1
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +49 -101
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/simple.browser.js +47 -101
- package/dist/src/errors/base.d.ts +1 -1
- package/dist/src/errors/base.d.ts.map +1 -1
- package/dist/src/errors/base.js +2 -1
- package/dist/src/folder-api/folder-operations.d.ts +2 -1
- package/dist/src/folder-api/folder-operations.d.ts.map +1 -1
- package/dist/src/folder-api/types.d.ts.map +1 -1
- package/dist/src/folder-api/types.js +4 -1
- package/dist/src/runtime/wasi-adapter/file-handle.d.ts.map +1 -1
- package/dist/src/runtime/wasi-adapter/file-handle.js +3 -1
- package/dist/src/runtime/wasi-adapter/wasm-io.d.ts.map +1 -1
- package/dist/src/runtime/wasi-adapter/wasm-io.js +9 -0
- package/dist/src/runtime/wasi-host.d.ts.map +1 -1
- package/dist/src/runtime/wasi-host.js +5 -0
- package/dist/src/simple/batch-operations.d.ts +4 -4
- package/dist/src/simple/batch-operations.d.ts.map +1 -1
- package/dist/src/simple/batch-operations.js +4 -1
- package/dist/src/simple/picture-operations.d.ts.map +1 -1
- package/dist/src/simple/picture-operations.js +6 -50
- package/dist/src/simple/tag-operations.d.ts.map +1 -1
- package/dist/src/simple/tag-operations.js +12 -65
- package/dist/src/simple/with-audio-file.d.ts +5 -0
- package/dist/src/simple/with-audio-file.d.ts.map +1 -0
- package/dist/src/simple/with-audio-file.js +32 -0
- package/dist/src/taglib/audio-file-base.d.ts +3 -3
- package/dist/src/taglib/audio-file-base.d.ts.map +1 -1
- package/dist/src/taglib/audio-file-impl.d.ts +2 -2
- package/dist/src/taglib/audio-file-impl.d.ts.map +1 -1
- package/dist/src/taglib/taglib-class.d.ts +3 -2
- package/dist/src/taglib/taglib-class.d.ts.map +1 -1
- package/dist/src/taglib/taglib-class.js +9 -5
- package/dist/src/types/audio-formats.d.ts +12 -3
- package/dist/src/types/audio-formats.d.ts.map +1 -1
- package/dist/src/types/audio-formats.js +6 -0
- package/dist/src/types/format-property-keys.d.ts +1 -1
- package/dist/src/types/format-property-keys.d.ts.map +1 -1
- package/dist/taglib-web.wasm +0 -0
- package/dist/taglib-wrapper.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-handle.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/file-handle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"file-handle.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/file-handle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAuChE,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,SAAS,CAAS;gBAEd,UAAU,EAAE,UAAU;IAIlC,OAAO,CAAC,iBAAiB;IAQzB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO;IAW3C,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAOpC,OAAO,IAAI,OAAO;IAKlB,IAAI,IAAI,OAAO;IAcf,MAAM,IAAI,UAAU;IASpB,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"
|
|
30
|
+
ASF: "ASF",
|
|
31
|
+
Matroska: "MATROSKA"
|
|
31
32
|
};
|
|
32
33
|
const NUMERIC_FIELD_ALIASES = {
|
|
33
34
|
date: "year",
|
|
@@ -156,6 +157,7 @@ class WasiFileHandle {
|
|
|
156
157
|
if (magic[0] === 119 && magic[1] === 118 && magic[2] === 112 && magic[3] === 107) return "WV";
|
|
157
158
|
if (magic[0] === 84 && magic[1] === 84 && magic[2] === 65 && magic[3] === 49) return "TTA";
|
|
158
159
|
if (this.fileData.length >= 16 && magic[0] === 48 && magic[1] === 38 && magic[2] === 178 && magic[3] === 117) return "ASF";
|
|
160
|
+
if (magic[0] === 26 && magic[1] === 69 && magic[2] === 223 && magic[3] === 163) return "MATROSKA";
|
|
159
161
|
const ftyp = this.fileData.slice(4, 8);
|
|
160
162
|
if (ftyp[0] === 102 && ftyp[1] === 116 && ftyp[2] === 121 && ftyp[3] === 112) return "MP4";
|
|
161
163
|
return "unknown";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-io.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/wasm-io.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"wasm-io.d.ts","sourceRoot":"","sources":["../../../../src/runtime/wasi-adapter/wasm-io.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAQhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,UAAU,GACjB,UAAU,CAoCZ;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,WAAW,GACnB,UAAU,GAAG,IAAI,CA8BnB"}
|
|
@@ -47,7 +47,10 @@ import {
|
|
|
47
47
|
WasmArena,
|
|
48
48
|
WasmMemoryError
|
|
49
49
|
} from "../wasi-memory.js";
|
|
50
|
+
import { InvalidFormatError } from "../../errors/classes.js";
|
|
50
51
|
import { encodeTagData } from "../../msgpack/encoder.js";
|
|
52
|
+
const TL_ERROR_UNSUPPORTED_FORMAT = -2;
|
|
53
|
+
const TL_ERROR_PARSE_FAILED = -6;
|
|
51
54
|
function readTagsFromWasm(wasi, buffer) {
|
|
52
55
|
var _stack = [];
|
|
53
56
|
try {
|
|
@@ -62,6 +65,12 @@ function readTagsFromWasm(wasi, buffer) {
|
|
|
62
65
|
);
|
|
63
66
|
if (resultPtr === 0) {
|
|
64
67
|
const errorCode = wasi.tl_get_last_error_code();
|
|
68
|
+
if (errorCode === TL_ERROR_UNSUPPORTED_FORMAT || errorCode === TL_ERROR_PARSE_FAILED) {
|
|
69
|
+
throw new InvalidFormatError(
|
|
70
|
+
"File may be corrupted or in an unsupported format",
|
|
71
|
+
buffer.length
|
|
72
|
+
);
|
|
73
|
+
}
|
|
65
74
|
throw new WasmMemoryError(
|
|
66
75
|
`error code ${errorCode}. Buffer size: ${buffer.length} bytes`,
|
|
67
76
|
"read tags",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasi-host.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAGhF,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,EAAE,EAAE,kBAAkB,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CACrC;AAgBD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAA;CAAE,CAAC;AAE9E,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,EAC/B,MAAM,EAAE,cAAc,GACrB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"wasi-host.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAGhF,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,EAAE,EAAE,kBAAkB,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CACrC;AAgBD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAA;CAAE,CAAC;AAE9E,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,EAC/B,MAAM,EAAE,cAAc,GACrB,oBAAoB,CA+NtB"}
|
|
@@ -176,6 +176,11 @@ function createWasiImports(memory, config) {
|
|
|
176
176
|
dv.setBigUint64(timePtr, BigInt(Date.now()) * 1000000n, true);
|
|
177
177
|
return WASI_ESUCCESS;
|
|
178
178
|
},
|
|
179
|
+
random_get: (bufPtr, bufLen) => {
|
|
180
|
+
const buf = new Uint8Array(memory.buffer, bufPtr, bufLen);
|
|
181
|
+
crypto.getRandomValues(buf);
|
|
182
|
+
return WASI_ESUCCESS;
|
|
183
|
+
},
|
|
179
184
|
proc_exit: (code) => {
|
|
180
185
|
throw new Error(`WASI proc_exit called: code ${code}`);
|
|
181
186
|
},
|
|
@@ -26,7 +26,7 @@ export interface BatchResult<T> {
|
|
|
26
26
|
/**
|
|
27
27
|
* Read tags from multiple files with configurable concurrency.
|
|
28
28
|
*
|
|
29
|
-
* @param files - Array of file paths, Uint8Arrays, ArrayBuffers,
|
|
29
|
+
* @param files - Array of file paths, Uint8Arrays, ArrayBuffers, File objects, or NamedAudioInputs.
|
|
30
30
|
* @param options - Batch processing options (concurrency, error handling, progress).
|
|
31
31
|
* @returns Batch result containing a `BatchItem` per file and total duration in ms.
|
|
32
32
|
* @throws If `continueOnError` is `false` and any file fails to process.
|
|
@@ -35,7 +35,7 @@ export declare function readTagsBatch(files: AudioFileInput[], options?: BatchOp
|
|
|
35
35
|
/**
|
|
36
36
|
* Read audio properties from multiple files with configurable concurrency.
|
|
37
37
|
*
|
|
38
|
-
* @param files - Array of file paths, Uint8Arrays, ArrayBuffers,
|
|
38
|
+
* @param files - Array of file paths, Uint8Arrays, ArrayBuffers, File objects, or NamedAudioInputs.
|
|
39
39
|
* @param options - Batch processing options (concurrency, error handling, progress).
|
|
40
40
|
* @returns Batch result containing a `BatchItem` per file and total duration in ms.
|
|
41
41
|
* @throws If `continueOnError` is `false` and any file fails to process.
|
|
@@ -51,7 +51,7 @@ export interface FileMetadata {
|
|
|
51
51
|
/**
|
|
52
52
|
* Read complete metadata (tags, properties, cover art, dynamics) from a single file.
|
|
53
53
|
*
|
|
54
|
-
* @param file - A file path, Uint8Array, ArrayBuffer,
|
|
54
|
+
* @param file - A file path, Uint8Array, ArrayBuffer, File object, or NamedAudioInput.
|
|
55
55
|
* @returns The file's complete metadata.
|
|
56
56
|
* @throws `InvalidFormatError` if the file is corrupted or in an unsupported format.
|
|
57
57
|
*/
|
|
@@ -59,7 +59,7 @@ export declare function readMetadata(file: AudioFileInput): Promise<FileMetadata
|
|
|
59
59
|
/**
|
|
60
60
|
* Read complete metadata from multiple files with configurable concurrency.
|
|
61
61
|
*
|
|
62
|
-
* @param files - Array of file paths, Uint8Arrays, ArrayBuffers,
|
|
62
|
+
* @param files - Array of file paths, Uint8Arrays, ArrayBuffers, File objects, or NamedAudioInputs.
|
|
63
63
|
* @param options - Batch processing options (concurrency, error handling, progress).
|
|
64
64
|
* @returns Batch result containing a `BatchItem` per file and total duration in ms.
|
|
65
65
|
* @throws If `continueOnError` is `false` and any file fails to process.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-operations.d.ts","sourceRoot":"","sources":["../../../src/simple/batch-operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"batch-operations.d.ts","sourceRoot":"","sources":["../../../src/simple/batch-operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAMhF,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7E,gEAAgE;IAChE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,yEAAyE;AACzE,MA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../errors.js";
|
|
2
3
|
import { mapPropertiesToExtendedTag } from "../utils/tag-mapping.js";
|
|
3
4
|
import { getTagLib } from "./config.js";
|
|
@@ -14,7 +15,7 @@ async function executeBatch(files, options, processor) {
|
|
|
14
15
|
const chunk = files.slice(i, i + concurrency);
|
|
15
16
|
const chunkPromises = chunk.map(async (file, idx) => {
|
|
16
17
|
const index = i + idx;
|
|
17
|
-
const fileName = typeof file === "string" ? file : `
|
|
18
|
+
const fileName = typeof file === "string" ? file : file instanceof File ? file.name : isNamedAudioInput(file) ? file.name : `buffer-${index}`;
|
|
18
19
|
try {
|
|
19
20
|
const audioFile = await taglib.open(file);
|
|
20
21
|
try {
|
|
@@ -86,6 +87,8 @@ async function readMetadata(file) {
|
|
|
86
87
|
name = file;
|
|
87
88
|
} else if (file instanceof File) {
|
|
88
89
|
name = file.name;
|
|
90
|
+
} else if (isNamedAudioInput(file)) {
|
|
91
|
+
name = file.name;
|
|
89
92
|
} else {
|
|
90
93
|
name = `buffer (${file.byteLength} bytes)`;
|
|
91
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture-operations.d.ts","sourceRoot":"","sources":["../../../src/simple/picture-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"picture-operations.d.ts","sourceRoot":"","sources":["../../../src/simple/picture-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGxE;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,OAAO,EAAE,CAAC,CAEpB;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,OAAO,EAAE,GAClB,OAAO,CAAC,UAAU,CAAC,CAIrB;AAED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,UAAU,CAAC,CAIrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,UAAU,CAAC,CAErB;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAYjC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,cAAc,EACpB,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC,CAQrB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,OAAO,EAAE,EACnB,IAAI,EAAE,WAAW,GAChB,OAAO,GAAG,SAAS,CAErB;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,cAAc,EACpB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,UAAU,CAAC,CAUrB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,cAAc,GACnB,OAAO,CACR,KAAK,CAAC;IACJ,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CACH,CAQA"}
|
|
@@ -1,60 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getTagLib } from "./config.js";
|
|
1
|
+
import { withAudioFile, withAudioFileSave } from "./with-audio-file.js";
|
|
3
2
|
async function readPictures(file) {
|
|
4
|
-
|
|
5
|
-
const audioFile = await taglib.open(file);
|
|
6
|
-
try {
|
|
7
|
-
if (!audioFile.isValid()) {
|
|
8
|
-
throw new InvalidFormatError(
|
|
9
|
-
"File may be corrupted or in an unsupported format"
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
return audioFile.getPictures();
|
|
13
|
-
} finally {
|
|
14
|
-
audioFile.dispose();
|
|
15
|
-
}
|
|
3
|
+
return withAudioFile(file, (audioFile) => audioFile.getPictures());
|
|
16
4
|
}
|
|
17
5
|
async function applyPictures(file, pictures) {
|
|
18
|
-
|
|
19
|
-
const audioFile = await taglib.open(file);
|
|
20
|
-
try {
|
|
21
|
-
if (!audioFile.isValid()) {
|
|
22
|
-
throw new InvalidFormatError(
|
|
23
|
-
"File may be corrupted or in an unsupported format"
|
|
24
|
-
);
|
|
25
|
-
}
|
|
6
|
+
return withAudioFileSave(file, (audioFile) => {
|
|
26
7
|
audioFile.setPictures(pictures);
|
|
27
|
-
|
|
28
|
-
throw new FileOperationError(
|
|
29
|
-
"save",
|
|
30
|
-
"Failed to save picture changes. The file may be read-only or corrupted."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
return audioFile.getFileBuffer();
|
|
34
|
-
} finally {
|
|
35
|
-
audioFile.dispose();
|
|
36
|
-
}
|
|
8
|
+
});
|
|
37
9
|
}
|
|
38
10
|
async function addPicture(file, picture) {
|
|
39
|
-
|
|
40
|
-
const audioFile = await taglib.open(file);
|
|
41
|
-
try {
|
|
42
|
-
if (!audioFile.isValid()) {
|
|
43
|
-
throw new InvalidFormatError(
|
|
44
|
-
"File may be corrupted or in an unsupported format"
|
|
45
|
-
);
|
|
46
|
-
}
|
|
11
|
+
return withAudioFileSave(file, (audioFile) => {
|
|
47
12
|
audioFile.addPicture(picture);
|
|
48
|
-
|
|
49
|
-
throw new FileOperationError(
|
|
50
|
-
"save",
|
|
51
|
-
"Failed to save picture changes. The file may be read-only or corrupted."
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
return audioFile.getFileBuffer();
|
|
55
|
-
} finally {
|
|
56
|
-
audioFile.dispose();
|
|
57
|
-
}
|
|
13
|
+
});
|
|
58
14
|
}
|
|
59
15
|
async function clearPictures(file) {
|
|
60
16
|
return applyPictures(file, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag-operations.d.ts","sourceRoot":"","sources":["../../../src/simple/tag-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,WAAW,EACX,QAAQ,EACR,QAAQ,EACT,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tag-operations.d.ts","sourceRoot":"","sources":["../../../src/simple/tag-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,WAAW,EACX,QAAQ,EACR,QAAQ,EACT,MAAM,aAAa,CAAC;AAUrB;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,WAAW,CAAC,CAKtB;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GACtB,OAAO,CAAC,UAAU,CAAC,CAIrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GACtB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,eAAe,CAAC,CAY1B;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAW/B;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,UAAU,CAAC,CAKrB"}
|
|
@@ -1,49 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FileOperationError,
|
|
3
|
-
InvalidFormatError,
|
|
4
|
-
MetadataError
|
|
5
|
-
} from "../errors.js";
|
|
1
|
+
import { FileOperationError, MetadataError } from "../errors.js";
|
|
6
2
|
import { writeFileData } from "../utils/write.js";
|
|
7
3
|
import {
|
|
8
4
|
mapPropertiesToExtendedTag,
|
|
9
5
|
mergeTagUpdates
|
|
10
6
|
} from "../utils/tag-mapping.js";
|
|
11
7
|
import { getTagLib } from "./config.js";
|
|
8
|
+
import { withAudioFile, withAudioFileSave } from "./with-audio-file.js";
|
|
12
9
|
async function readTags(file) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
throw new InvalidFormatError(
|
|
18
|
-
"File may be corrupted or in an unsupported format"
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
const props = audioFile.properties();
|
|
22
|
-
return mapPropertiesToExtendedTag(props);
|
|
23
|
-
} finally {
|
|
24
|
-
audioFile.dispose();
|
|
25
|
-
}
|
|
10
|
+
return withAudioFile(
|
|
11
|
+
file,
|
|
12
|
+
(audioFile) => mapPropertiesToExtendedTag(audioFile.properties())
|
|
13
|
+
);
|
|
26
14
|
}
|
|
27
15
|
async function applyTags(file, tags) {
|
|
28
|
-
|
|
29
|
-
const audioFile = await taglib.open(file);
|
|
30
|
-
try {
|
|
31
|
-
if (!audioFile.isValid()) {
|
|
32
|
-
throw new InvalidFormatError(
|
|
33
|
-
"File may be corrupted or in an unsupported format"
|
|
34
|
-
);
|
|
35
|
-
}
|
|
16
|
+
return withAudioFileSave(file, (audioFile) => {
|
|
36
17
|
mergeTagUpdates(audioFile, tags);
|
|
37
|
-
|
|
38
|
-
throw new FileOperationError(
|
|
39
|
-
"save",
|
|
40
|
-
"Failed to save metadata changes. The file may be read-only or corrupted."
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
return audioFile.getFileBuffer();
|
|
44
|
-
} finally {
|
|
45
|
-
audioFile.dispose();
|
|
46
|
-
}
|
|
18
|
+
});
|
|
47
19
|
}
|
|
48
20
|
async function applyTagsToFile(file, tags) {
|
|
49
21
|
if (typeof file !== "string") {
|
|
@@ -56,14 +28,7 @@ async function applyTagsToFile(file, tags) {
|
|
|
56
28
|
await writeFileData(file, modifiedBuffer);
|
|
57
29
|
}
|
|
58
30
|
async function readProperties(file) {
|
|
59
|
-
|
|
60
|
-
const audioFile = await taglib.open(file);
|
|
61
|
-
try {
|
|
62
|
-
if (!audioFile.isValid()) {
|
|
63
|
-
throw new InvalidFormatError(
|
|
64
|
-
"File may be corrupted or in an unsupported format"
|
|
65
|
-
);
|
|
66
|
-
}
|
|
31
|
+
return withAudioFile(file, (audioFile) => {
|
|
67
32
|
const props = audioFile.audioProperties();
|
|
68
33
|
if (!props) {
|
|
69
34
|
throw new MetadataError(
|
|
@@ -73,9 +38,7 @@ async function readProperties(file) {
|
|
|
73
38
|
);
|
|
74
39
|
}
|
|
75
40
|
return props;
|
|
76
|
-
}
|
|
77
|
-
audioFile.dispose();
|
|
78
|
-
}
|
|
41
|
+
});
|
|
79
42
|
}
|
|
80
43
|
async function isValidAudioFile(file) {
|
|
81
44
|
try {
|
|
@@ -103,26 +66,10 @@ async function readFormat(file) {
|
|
|
103
66
|
}
|
|
104
67
|
}
|
|
105
68
|
async function clearTags(file) {
|
|
106
|
-
|
|
107
|
-
const audioFile = await taglib.open(file);
|
|
108
|
-
try {
|
|
109
|
-
if (!audioFile.isValid()) {
|
|
110
|
-
throw new InvalidFormatError(
|
|
111
|
-
"File may be corrupted or in an unsupported format"
|
|
112
|
-
);
|
|
113
|
-
}
|
|
69
|
+
return withAudioFileSave(file, (audioFile) => {
|
|
114
70
|
audioFile.setProperties({});
|
|
115
71
|
audioFile.removePictures();
|
|
116
|
-
|
|
117
|
-
throw new FileOperationError(
|
|
118
|
-
"save",
|
|
119
|
-
"Failed to save metadata changes. The file may be read-only or corrupted."
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
return audioFile.getFileBuffer();
|
|
123
|
-
} finally {
|
|
124
|
-
audioFile.dispose();
|
|
125
|
-
}
|
|
72
|
+
});
|
|
126
73
|
}
|
|
127
74
|
export {
|
|
128
75
|
applyTags,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AudioFile } from "../taglib/audio-file-interface.js";
|
|
2
|
+
import type { AudioFileInput } from "../types.js";
|
|
3
|
+
export declare function withAudioFile<T>(file: AudioFileInput, fn: (audioFile: AudioFile) => T): Promise<T>;
|
|
4
|
+
export declare function withAudioFileSave(file: AudioFileInput, fn: (audioFile: AudioFile) => void): Promise<Uint8Array>;
|
|
5
|
+
//# sourceMappingURL=with-audio-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-audio-file.d.ts","sourceRoot":"","sources":["../../../src/simple/with-audio-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GACjC,OAAO,CAAC,UAAU,CAAC,CAWrB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FileOperationError, InvalidFormatError } from "../errors.js";
|
|
2
|
+
import { getTagLib } from "./config.js";
|
|
3
|
+
async function withAudioFile(file, fn) {
|
|
4
|
+
const taglib = await getTagLib();
|
|
5
|
+
const audioFile = await taglib.open(file);
|
|
6
|
+
try {
|
|
7
|
+
if (!audioFile.isValid()) {
|
|
8
|
+
throw new InvalidFormatError(
|
|
9
|
+
"File may be corrupted or in an unsupported format"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return fn(audioFile);
|
|
13
|
+
} finally {
|
|
14
|
+
audioFile.dispose();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function withAudioFileSave(file, fn) {
|
|
18
|
+
return withAudioFile(file, (audioFile) => {
|
|
19
|
+
fn(audioFile);
|
|
20
|
+
if (!audioFile.save()) {
|
|
21
|
+
throw new FileOperationError(
|
|
22
|
+
"save",
|
|
23
|
+
"Failed to save metadata changes. The file may be read-only or corrupted."
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return audioFile.getFileBuffer();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
withAudioFile,
|
|
31
|
+
withAudioFileSave
|
|
32
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FileHandle, TagLibModule } from "../wasm.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AudioProperties, FileType, OpenOptions, PropertyMap } from "../types.js";
|
|
3
3
|
import type { MutableTag } from "./mutable-tag.js";
|
|
4
4
|
import type { TypedAudioFile } from "./audio-file-interface.js";
|
|
5
5
|
/**
|
|
@@ -13,10 +13,10 @@ export declare abstract class BaseAudioFileImpl {
|
|
|
13
13
|
protected fileHandle: FileHandle | null;
|
|
14
14
|
protected cachedAudioProperties: AudioProperties | null;
|
|
15
15
|
protected readonly sourcePath?: string;
|
|
16
|
-
protected originalSource?:
|
|
16
|
+
protected originalSource?: string | Uint8Array | ArrayBuffer | File;
|
|
17
17
|
protected isPartiallyLoaded: boolean;
|
|
18
18
|
protected readonly partialLoadOptions?: OpenOptions;
|
|
19
|
-
constructor(module: TagLibModule, fileHandle: FileHandle, sourcePath?: string, originalSource?:
|
|
19
|
+
constructor(module: TagLibModule, fileHandle: FileHandle, sourcePath?: string, originalSource?: string | Uint8Array | ArrayBuffer | File, isPartiallyLoaded?: boolean, partialLoadOptions?: OpenOptions);
|
|
20
20
|
protected get handle(): FileHandle;
|
|
21
21
|
getFormat(): FileType;
|
|
22
22
|
isFormat<F extends FileType>(format: F): this is TypedAudioFile<F>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-file-base.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAEV,
|
|
1
|
+
{"version":3,"file":"audio-file-base.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAEV,eAAe,EAEf,QAAQ,EACR,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;;GAKG;AACH,8BAAsB,iBAAiB;IASnC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY;IARzC,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IACxC,SAAS,CAAC,qBAAqB,EAAE,eAAe,GAAG,IAAI,CAAQ;IAC/D,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IACvC,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,CAAC;IACpE,SAAS,CAAC,iBAAiB,EAAE,OAAO,CAAS;IAC7C,SAAS,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,WAAW,CAAC;gBAG/B,MAAM,EAAE,YAAY,EACvC,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,EACzD,iBAAiB,GAAE,OAAe,EAClC,kBAAkB,CAAC,EAAE,WAAW;IASlC,SAAS,KAAK,MAAM,IAAI,UAAU,CAKjC;IAED,SAAS,IAAI,QAAQ;IAIrB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC;IAIlE,GAAG,IAAI,UAAU;IA+DjB,eAAe,IAAI,eAAe,GAAG,SAAS;IAuB9C,UAAU,IAAI,WAAW;IAIzB,aAAa,CAAC,UAAU,EAAE,WAAW,GAAG,IAAI;IAQ5C,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAK5C,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7C,KAAK,IAAI,OAAO;IAIhB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAQ3C,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAO5C,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAOhC,OAAO,IAAI,OAAO;IAIlB,OAAO,IAAI,IAAI;IAQf,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FileHandle, TagLibModule } from "../wasm.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { OpenOptions, Picture } from "../types.js";
|
|
3
3
|
import type { Rating } from "../constants/complex-properties.js";
|
|
4
4
|
import type { AudioFile } from "./audio-file-interface.js";
|
|
5
5
|
import { BaseAudioFileImpl } from "./audio-file-base.js";
|
|
@@ -10,7 +10,7 @@ import { BaseAudioFileImpl } from "./audio-file-base.js";
|
|
|
10
10
|
* Use TagLib.open() to create instances.
|
|
11
11
|
*/
|
|
12
12
|
export declare class AudioFileImpl extends BaseAudioFileImpl implements AudioFile {
|
|
13
|
-
constructor(module: TagLibModule, fileHandle: FileHandle, sourcePath?: string, originalSource?:
|
|
13
|
+
constructor(module: TagLibModule, fileHandle: FileHandle, sourcePath?: string, originalSource?: string | Uint8Array | ArrayBuffer | File, isPartiallyLoaded?: boolean, partialLoadOptions?: OpenOptions);
|
|
14
14
|
save(): boolean;
|
|
15
15
|
getFileBuffer(): Uint8Array;
|
|
16
16
|
saveToFile(path?: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-file-impl.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"audio-file-impl.d.ts","sourceRoot":"","sources":["../../../src/taglib/audio-file-impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAIjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,iBAAkB,YAAW,SAAS;gBAErE,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,EACzD,iBAAiB,GAAE,OAAe,EAClC,kBAAkB,CAAC,EAAE,WAAW;IAYlC,IAAI,IAAI,OAAO;IAYf,aAAa,IAAI,UAAU;IAKrB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA8D9C,WAAW,IAAI,OAAO,EAAE;IAUxB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAStC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IASlC,cAAc,IAAI,IAAI;IAItB,UAAU,IAAI,MAAM,EAAE;IAUtB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAQnC,SAAS,IAAI,MAAM,GAAG,SAAS;IAK/B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;CAGhD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { WasmModule } from "../wasm.js";
|
|
2
2
|
import type { AudioFileInput, OpenOptions, TagInput } from "../types.js";
|
|
3
3
|
import type { LoadTagLibOptions } from "../runtime/loader-types.js";
|
|
4
|
+
import { type NamedAudioInput } from "../types/audio-formats.js";
|
|
4
5
|
import type { AudioFile } from "./audio-file-interface.js";
|
|
5
6
|
/**
|
|
6
7
|
* Main TagLib interface for audio metadata operations.
|
|
@@ -17,7 +18,7 @@ export declare class TagLib {
|
|
|
17
18
|
static initialize(options?: LoadTagLibOptions): Promise<TagLib>;
|
|
18
19
|
/**
|
|
19
20
|
* Open an audio file for reading and writing metadata.
|
|
20
|
-
* @param input - File path, Uint8Array, ArrayBuffer,
|
|
21
|
+
* @param input - File path, Uint8Array, ArrayBuffer, File object, or NamedAudioInput.
|
|
21
22
|
* @param options - Partial-loading options for large files.
|
|
22
23
|
* @returns An AudioFile instance (use `using` for automatic cleanup).
|
|
23
24
|
* @throws {TagLibInitializationError} If the module is not properly initialized.
|
|
@@ -35,7 +36,7 @@ export declare class TagLib {
|
|
|
35
36
|
* @throws {FileOperationError} If saving to disk fails.
|
|
36
37
|
*/
|
|
37
38
|
edit(input: string, fn: (file: AudioFile) => void | Promise<void>): Promise<void>;
|
|
38
|
-
edit(input: Uint8Array | ArrayBuffer | File, fn: (file: AudioFile) => void | Promise<void>): Promise<Uint8Array>;
|
|
39
|
+
edit(input: Uint8Array | ArrayBuffer | File | NamedAudioInput, fn: (file: AudioFile) => void | Promise<void>): Promise<Uint8Array>;
|
|
39
40
|
/**
|
|
40
41
|
* Update tags in a file and save to disk in one operation.
|
|
41
42
|
* @param path - Path to the audio file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taglib-class.d.ts","sourceRoot":"","sources":["../../../src/taglib/taglib-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"taglib-class.d.ts","sourceRoot":"","sources":["../../../src/taglib/taglib-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAK3D;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,MAAM,EAAE,UAAU;IAI9B;;;;;OAKG;WACU,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAMrE;;;;;;;OAOG;IACG,IAAI,CACR,KAAK,EAAE,cAAc,EACrB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,SAAS,CAAC;IAyDrB;;;;;;;;;OASG;IACG,IAAI,CACR,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC;IACV,IAAI,CACR,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,GAAG,eAAe,EACxD,EAAE,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC5C,OAAO,CAAC,UAAU,CAAC;IAmBtB;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtE;;;;;;;OAOG;IACG,YAAY,CAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GACtB,OAAO,CAAC,IAAI,CAAC;IAUhB,oEAAoE;IACpE,OAAO,IAAI,MAAM;CAGlB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtE"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import {
|
|
5
|
+
isNamedAudioInput
|
|
6
|
+
} from "../types/audio-formats.js";
|
|
4
7
|
import { InvalidFormatError, TagLibInitializationError } from "../errors.js";
|
|
5
8
|
import { AudioFileImpl } from "./audio-file-impl.js";
|
|
6
9
|
import { loadAudioData } from "./load-audio-data.js";
|
|
@@ -23,7 +26,7 @@ class TagLib {
|
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Open an audio file for reading and writing metadata.
|
|
26
|
-
* @param input - File path, Uint8Array, ArrayBuffer,
|
|
29
|
+
* @param input - File path, Uint8Array, ArrayBuffer, File object, or NamedAudioInput.
|
|
27
30
|
* @param options - Partial-loading options for large files.
|
|
28
31
|
* @returns An AudioFile instance (use `using` for automatic cleanup).
|
|
29
32
|
* @throws {TagLibInitializationError} If the module is not properly initialized.
|
|
@@ -35,7 +38,8 @@ class TagLib {
|
|
|
35
38
|
"TagLib module not properly initialized: createFileHandle not found. Make sure the module is fully loaded before calling open."
|
|
36
39
|
);
|
|
37
40
|
}
|
|
38
|
-
const
|
|
41
|
+
const actualInput = isNamedAudioInput(input) ? input.data : input;
|
|
42
|
+
const sourcePath = typeof actualInput === "string" ? actualInput : void 0;
|
|
39
43
|
const opts = {
|
|
40
44
|
partial: false,
|
|
41
45
|
maxHeaderSize: 1024 * 1024,
|
|
@@ -43,7 +47,7 @@ class TagLib {
|
|
|
43
47
|
...options
|
|
44
48
|
};
|
|
45
49
|
const { data: audioData, isPartiallyLoaded } = await loadAudioData(
|
|
46
|
-
|
|
50
|
+
actualInput,
|
|
47
51
|
opts
|
|
48
52
|
);
|
|
49
53
|
const buffer = audioData.buffer.slice(
|
|
@@ -64,7 +68,7 @@ class TagLib {
|
|
|
64
68
|
this.module,
|
|
65
69
|
fileHandle,
|
|
66
70
|
sourcePath,
|
|
67
|
-
|
|
71
|
+
actualInput,
|
|
68
72
|
isPartiallyLoaded,
|
|
69
73
|
opts
|
|
70
74
|
);
|
|
@@ -124,7 +128,7 @@ class TagLib {
|
|
|
124
128
|
}
|
|
125
129
|
/** Returns the taglib-wasm version with embedded TagLib version. */
|
|
126
130
|
version() {
|
|
127
|
-
return "1.0.
|
|
131
|
+
return "1.0.6 (TagLib 2.2.1)";
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
async function createTagLib(module) {
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named audio input for buffer-based operations.
|
|
3
|
+
* Provides a name for correlation in batch results.
|
|
4
|
+
*/
|
|
5
|
+
export interface NamedAudioInput {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly data: Uint8Array | ArrayBuffer;
|
|
8
|
+
}
|
|
1
9
|
/**
|
|
2
10
|
* Input types accepted by TagLib-Wasm for audio files
|
|
3
11
|
*/
|
|
4
|
-
export type AudioFileInput = string | Uint8Array | ArrayBuffer | File;
|
|
12
|
+
export type AudioFileInput = string | Uint8Array | ArrayBuffer | File | NamedAudioInput;
|
|
13
|
+
export declare function isNamedAudioInput(input: AudioFileInput): input is NamedAudioInput;
|
|
5
14
|
/**
|
|
6
15
|
* Supported file types detected by TagLib.
|
|
7
16
|
* "unknown" indicates the format could not be determined.
|
|
@@ -15,7 +24,7 @@ export type AudioFileInput = string | Uint8Array | ArrayBuffer | File;
|
|
|
15
24
|
* }
|
|
16
25
|
* ```
|
|
17
26
|
*/
|
|
18
|
-
export type FileType = "MP3" | "MP4" | "FLAC" | "OGG" | "OPUS" | "WAV" | "AIFF" | "ASF" | "APE" | "DSF" | "DSDIFF" | "WV" | "MPC" | "TTA" | "SHN" | "MOD" | "S3M" | "IT" | "XM" | "OggFLAC" | "SPEEX" | "unknown";
|
|
27
|
+
export type FileType = "MP3" | "MP4" | "FLAC" | "OGG" | "OPUS" | "WAV" | "AIFF" | "ASF" | "APE" | "DSF" | "DSDIFF" | "WV" | "MPC" | "TTA" | "SHN" | "MOD" | "S3M" | "IT" | "XM" | "OggFLAC" | "SPEEX" | "MATROSKA" | "unknown";
|
|
19
28
|
/**
|
|
20
29
|
* Container formats for audio files.
|
|
21
30
|
* A container format defines how audio data and metadata are stored in a file.
|
|
@@ -28,7 +37,7 @@ export type FileType = "MP3" | "MP4" | "FLAC" | "OGG" | "OPUS" | "WAV" | "AIFF"
|
|
|
28
37
|
* console.log(`Codec: ${props.codec}`); // "AAC"
|
|
29
38
|
* ```
|
|
30
39
|
*/
|
|
31
|
-
export type ContainerFormat = "MP3" | "MP4" | "FLAC" | "OGG" | "WAV" | "AIFF" | "ASF" | "APE" | "DSF" | "DSDIFF" | "WavPack" | "MPC" | "TTA" | "Shorten" | "MOD" | "S3M" | "IT" | "XM" | "unknown";
|
|
40
|
+
export type ContainerFormat = "MP3" | "MP4" | "FLAC" | "OGG" | "WAV" | "AIFF" | "ASF" | "APE" | "DSF" | "DSDIFF" | "WavPack" | "MPC" | "TTA" | "Shorten" | "MOD" | "S3M" | "IT" | "XM" | "Matroska" | "unknown";
|
|
32
41
|
/**
|
|
33
42
|
* Audio codecs (compression formats) for audio data.
|
|
34
43
|
* A codec defines how audio is encoded/compressed within a container.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-formats.d.ts","sourceRoot":"","sources":["../../../src/types/audio-formats.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"audio-formats.d.ts","sourceRoot":"","sources":["../../../src/types/audio-formats.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,UAAU,GACV,WAAW,GACX,IAAI,GACJ,eAAe,CAAC;AAEpB,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,cAAc,GACpB,KAAK,IAAI,eAAe,CAU1B;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,QAAQ,GAChB,KAAK,GACL,KAAK,GACL,MAAM,GACN,KAAK,GACL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AQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,wCAAwC;IACxC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { FileType } from "./audio-formats.js";
|
|
8
8
|
export type TagFormat = "ID3v2" | "MP4" | "Vorbis" | "WAV";
|
|
9
|
-
export type FileTypeToTagFormat<F extends FileType> = F extends "MP3" | "AIFF" ? "ID3v2" : F extends "MP4" ? "MP4" : F extends "FLAC" | "OGG" | "OPUS" | "OggFLAC" | "SPEEX" ? "Vorbis" : F extends "WAV" ? "WAV" : TagFormat;
|
|
9
|
+
export type FileTypeToTagFormat<F extends FileType> = F extends "MP3" | "AIFF" ? "ID3v2" : F extends "MP4" ? "MP4" : F extends "FLAC" | "OGG" | "OPUS" | "OggFLAC" | "SPEEX" | "MATROSKA" ? "Vorbis" : F extends "WAV" ? "WAV" : TagFormat;
|
|
10
10
|
type AllPropertyDefs = typeof import("../constants/basic-properties.js").BASIC_PROPERTIES & typeof import("../constants/general-extended-properties.js").GENERAL_EXTENDED_PROPERTIES & typeof import("../constants/specialized-properties.js").SPECIALIZED_PROPERTIES;
|
|
11
11
|
type PropertyKeysForTagFormat<TF extends TagFormat> = {
|
|
12
12
|
[K in keyof AllPropertyDefs]: TF extends AllPropertyDefs[K]["supportedFormats"][number] ? K : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-property-keys.d.ts","sourceRoot":"","sources":["../../../src/types/format-property-keys.ts"],"names":[],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,CAAC,MAAM,eAAe,CAAC,CAAC;AAEzB,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,QAAQ,IAAI,wBAAwB,CAC1E,mBAAmB,CAAC,CAAC,CAAC,CACvB,CAAC"}
|
package/dist/taglib-web.wasm
CHANGED
|
Binary file
|