taglib-wasm 0.2.4 → 0.2.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 +81 -14
- package/build/taglib.js +1 -16
- package/build/taglib.wasm +0 -0
- package/index.ts +1 -1
- package/package.json +4 -2
- package/src/enhanced-api.ts +1 -1
- package/src/simple-jsr.ts +201 -0
- package/src/simple.ts +313 -0
- package/src/taglib-embind.ts +231 -0
- package/src/taglib-jsr.ts +152 -2
- package/src/taglib.ts +150 -1
- package/src/types.ts +30 -1
- package/src/wasm-embind.ts +55 -0
- package/src/wasm-jsr.ts +156 -55
- package/src/wasm-workers.ts +4 -4
- package/src/wasm.ts +17 -5
package/src/taglib.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type {
|
|
6
6
|
AudioFormat,
|
|
7
7
|
AudioProperties,
|
|
8
|
+
BitrateControlMode,
|
|
8
9
|
ExtendedTag,
|
|
9
10
|
FieldMapping,
|
|
10
11
|
Picture,
|
|
@@ -12,7 +13,11 @@ import type {
|
|
|
12
13
|
Tag,
|
|
13
14
|
TagLibConfig,
|
|
14
15
|
} from "./types.ts";
|
|
15
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
BITRATE_CONTROL_MODE_NAMES,
|
|
18
|
+
BITRATE_CONTROL_MODE_VALUES,
|
|
19
|
+
METADATA_MAPPINGS
|
|
20
|
+
} from "./types.ts";
|
|
16
21
|
import {
|
|
17
22
|
cStringToJS,
|
|
18
23
|
jsToCString,
|
|
@@ -168,6 +173,150 @@ export class AudioFile {
|
|
|
168
173
|
this.module._taglib_tag_set_track(this.tagPtr, track);
|
|
169
174
|
}
|
|
170
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Get all properties as a PropertyMap
|
|
178
|
+
*/
|
|
179
|
+
properties(): PropertyMap {
|
|
180
|
+
const jsonPtr = this.module._taglib_file_properties_json(this.fileId);
|
|
181
|
+
if (jsonPtr === 0) return {};
|
|
182
|
+
|
|
183
|
+
const jsonStr = cStringToJS(this.module, jsonPtr);
|
|
184
|
+
try {
|
|
185
|
+
return JSON.parse(jsonStr);
|
|
186
|
+
} catch {
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Set properties from a PropertyMap
|
|
193
|
+
*/
|
|
194
|
+
setProperties(properties: PropertyMap): boolean {
|
|
195
|
+
const jsonStr = JSON.stringify(properties);
|
|
196
|
+
const jsonPtr = jsToCString(this.module, jsonStr);
|
|
197
|
+
try {
|
|
198
|
+
return this.module._taglib_file_set_properties_json(this.fileId, jsonPtr) !== 0;
|
|
199
|
+
} finally {
|
|
200
|
+
this.module._free(jsonPtr);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Get a specific property value
|
|
206
|
+
*/
|
|
207
|
+
getProperty(key: string): string[] | undefined {
|
|
208
|
+
const keyPtr = jsToCString(this.module, key);
|
|
209
|
+
try {
|
|
210
|
+
const valuePtr = this.module._taglib_file_get_property(this.fileId, keyPtr);
|
|
211
|
+
if (valuePtr === 0) return undefined;
|
|
212
|
+
|
|
213
|
+
const value = cStringToJS(this.module, valuePtr);
|
|
214
|
+
return value ? [value] : undefined;
|
|
215
|
+
} finally {
|
|
216
|
+
this.module._free(keyPtr);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Set a specific property value
|
|
222
|
+
*/
|
|
223
|
+
setProperty(key: string, values: string | string[]): boolean {
|
|
224
|
+
const value = Array.isArray(values) ? values[0] : values;
|
|
225
|
+
if (!value) return false;
|
|
226
|
+
|
|
227
|
+
const keyPtr = jsToCString(this.module, key);
|
|
228
|
+
const valuePtr = jsToCString(this.module, value);
|
|
229
|
+
try {
|
|
230
|
+
return this.module._taglib_file_set_property(this.fileId, keyPtr, valuePtr) !== 0;
|
|
231
|
+
} finally {
|
|
232
|
+
this.module._free(keyPtr);
|
|
233
|
+
this.module._free(valuePtr);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Check if this is an MP4 file
|
|
239
|
+
*/
|
|
240
|
+
isMP4(): boolean {
|
|
241
|
+
return this.module._taglib_file_is_mp4(this.fileId) !== 0;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Get MP4-specific item (for custom atoms)
|
|
246
|
+
*/
|
|
247
|
+
getMP4Item(key: string): string | undefined {
|
|
248
|
+
if (!this.isMP4()) return undefined;
|
|
249
|
+
|
|
250
|
+
const keyPtr = jsToCString(this.module, key);
|
|
251
|
+
try {
|
|
252
|
+
const valuePtr = this.module._taglib_mp4_get_item(this.fileId, keyPtr);
|
|
253
|
+
if (valuePtr === 0) return undefined;
|
|
254
|
+
|
|
255
|
+
return cStringToJS(this.module, valuePtr);
|
|
256
|
+
} finally {
|
|
257
|
+
this.module._free(keyPtr);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Set MP4-specific item (for custom atoms)
|
|
263
|
+
*/
|
|
264
|
+
setMP4Item(key: string, value: string): boolean {
|
|
265
|
+
if (!this.isMP4()) return false;
|
|
266
|
+
|
|
267
|
+
const keyPtr = jsToCString(this.module, key);
|
|
268
|
+
const valuePtr = jsToCString(this.module, value);
|
|
269
|
+
try {
|
|
270
|
+
return this.module._taglib_mp4_set_item(this.fileId, keyPtr, valuePtr) !== 0;
|
|
271
|
+
} finally {
|
|
272
|
+
this.module._free(keyPtr);
|
|
273
|
+
this.module._free(valuePtr);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Remove MP4-specific item
|
|
279
|
+
*/
|
|
280
|
+
removeMP4Item(key: string): boolean {
|
|
281
|
+
if (!this.isMP4()) return false;
|
|
282
|
+
|
|
283
|
+
const keyPtr = jsToCString(this.module, key);
|
|
284
|
+
try {
|
|
285
|
+
return this.module._taglib_mp4_remove_item(this.fileId, keyPtr) !== 0;
|
|
286
|
+
} finally {
|
|
287
|
+
this.module._free(keyPtr);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Get bitrate control mode (MP4/M4A specific)
|
|
293
|
+
* Reads from the 'acbf' atom
|
|
294
|
+
*/
|
|
295
|
+
getBitrateControlMode(): BitrateControlMode | undefined {
|
|
296
|
+
if (!this.isMP4()) return undefined;
|
|
297
|
+
|
|
298
|
+
const value = this.getMP4Item("acbf");
|
|
299
|
+
if (!value) return undefined;
|
|
300
|
+
|
|
301
|
+
const numValue = parseInt(value, 10);
|
|
302
|
+
if (isNaN(numValue) || numValue < 0 || numValue > 3) return undefined;
|
|
303
|
+
|
|
304
|
+
return BITRATE_CONTROL_MODE_NAMES[numValue];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Set bitrate control mode (MP4/M4A specific)
|
|
309
|
+
* Writes to the 'acbf' atom
|
|
310
|
+
*/
|
|
311
|
+
setBitrateControlMode(mode: BitrateControlMode): boolean {
|
|
312
|
+
if (!this.isMP4()) return false;
|
|
313
|
+
|
|
314
|
+
const numValue = BITRATE_CONTROL_MODE_VALUES[mode];
|
|
315
|
+
if (numValue === undefined) return false;
|
|
316
|
+
|
|
317
|
+
return this.setMP4Item("acbf", numValue.toString());
|
|
318
|
+
}
|
|
319
|
+
|
|
171
320
|
/**
|
|
172
321
|
* Save changes to the file
|
|
173
322
|
*/
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview TypeScript type definitions for
|
|
2
|
+
* @fileoverview TypeScript type definitions for taglib-wasm
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// Re-export commonly used classes from other modules
|
|
@@ -341,6 +341,35 @@ export enum PictureType {
|
|
|
341
341
|
PublisherLogo = 20,
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Bitrate control modes for audio encoding (MP4/M4A specific)
|
|
346
|
+
*/
|
|
347
|
+
export type BitrateControlMode =
|
|
348
|
+
| "Constant"
|
|
349
|
+
| "LongTermAverage"
|
|
350
|
+
| "VariableConstrained"
|
|
351
|
+
| "Variable";
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Map of bitrate control mode names to their numeric values
|
|
355
|
+
*/
|
|
356
|
+
export const BITRATE_CONTROL_MODE_VALUES: Record<BitrateControlMode, number> = {
|
|
357
|
+
Constant: 0,
|
|
358
|
+
LongTermAverage: 1,
|
|
359
|
+
VariableConstrained: 2,
|
|
360
|
+
Variable: 3,
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Map of numeric values to bitrate control mode names
|
|
365
|
+
*/
|
|
366
|
+
export const BITRATE_CONTROL_MODE_NAMES: Record<number, BitrateControlMode> = {
|
|
367
|
+
0: "Constant",
|
|
368
|
+
1: "LongTermAverage",
|
|
369
|
+
2: "VariableConstrained",
|
|
370
|
+
3: "Variable",
|
|
371
|
+
};
|
|
372
|
+
|
|
344
373
|
/**
|
|
345
374
|
* Configuration options for TagLib initialization
|
|
346
375
|
*/
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebAssembly module interface for Embind version
|
|
3
|
+
*/
|
|
4
|
+
export interface WasmModule {
|
|
5
|
+
// Memory access
|
|
6
|
+
HEAP8: Int8Array;
|
|
7
|
+
HEAP16: Int16Array;
|
|
8
|
+
HEAP32: Int32Array;
|
|
9
|
+
HEAPU8: Uint8Array;
|
|
10
|
+
HEAPU16: Uint16Array;
|
|
11
|
+
HEAPU32: Uint32Array;
|
|
12
|
+
HEAPF32: Float32Array;
|
|
13
|
+
HEAPF64: Float64Array;
|
|
14
|
+
|
|
15
|
+
// Runtime methods
|
|
16
|
+
allocate: (size: number, type: number) => number;
|
|
17
|
+
_malloc: (size: number) => number;
|
|
18
|
+
_free: (ptr: number) => void;
|
|
19
|
+
getValue: (ptr: number, type: string) => number;
|
|
20
|
+
setValue: (ptr: number, value: number, type: string) => void;
|
|
21
|
+
UTF8ToString: (ptr: number) => string;
|
|
22
|
+
stringToUTF8: (str: string, outPtr: number, maxBytesToWrite: number) => void;
|
|
23
|
+
lengthBytesUTF8: (str: string) => number;
|
|
24
|
+
|
|
25
|
+
// Allocation types
|
|
26
|
+
ALLOC_NORMAL: number;
|
|
27
|
+
ALLOC_STACK: number;
|
|
28
|
+
|
|
29
|
+
// Embind classes (these will be available after module loads)
|
|
30
|
+
FileHandle: any;
|
|
31
|
+
TagWrapper: any;
|
|
32
|
+
AudioPropertiesWrapper: any;
|
|
33
|
+
createFileHandle: () => any;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Extended module interface with our Embind classes
|
|
38
|
+
*/
|
|
39
|
+
export interface TagLibModule extends WasmModule {
|
|
40
|
+
// These are the actual class constructors from Embind
|
|
41
|
+
FileHandle: {
|
|
42
|
+
new(): any;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
TagWrapper: {
|
|
46
|
+
new(tagPtr: number): any;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
AudioPropertiesWrapper: {
|
|
50
|
+
new(propsPtr: number): any;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Factory function
|
|
54
|
+
createFileHandle: () => any;
|
|
55
|
+
}
|
package/src/wasm-jsr.ts
CHANGED
|
@@ -59,54 +59,144 @@ export interface TagLibModule {
|
|
|
59
59
|
_taglib_audioproperties_bitrate: (props: number) => number;
|
|
60
60
|
_taglib_audioproperties_samplerate: (props: number) => number;
|
|
61
61
|
_taglib_audioproperties_channels: (props: number) => number;
|
|
62
|
+
|
|
63
|
+
// PropertyMap operations
|
|
64
|
+
_taglib_file_properties_json: (fileId: number) => number;
|
|
65
|
+
_taglib_file_set_properties_json: (fileId: number, json: number) => number;
|
|
66
|
+
_taglib_file_get_property: (fileId: number, key: number) => number;
|
|
67
|
+
_taglib_file_set_property: (fileId: number, key: number, value: number) => number;
|
|
68
|
+
|
|
69
|
+
// MP4-specific operations
|
|
70
|
+
_taglib_file_is_mp4: (fileId: number) => number;
|
|
71
|
+
_taglib_mp4_get_item: (fileId: number, key: number) => number;
|
|
72
|
+
_taglib_mp4_set_item: (fileId: number, key: number, value: number) => number;
|
|
73
|
+
_taglib_mp4_remove_item: (fileId: number, key: number) => number;
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
/**
|
|
65
|
-
* Load
|
|
77
|
+
* Load taglib-wasm module for JSR
|
|
66
78
|
*/
|
|
67
79
|
export async function loadTagLibModuleJSR(
|
|
68
80
|
config?: TagLibConfig,
|
|
69
81
|
): Promise<TagLibModule> {
|
|
70
|
-
// Load WASM file as bytes
|
|
82
|
+
// Load WASM file as bytes (same file for all platforms)
|
|
71
83
|
const wasmUrl = new URL("../build/taglib.wasm", import.meta.url);
|
|
72
84
|
const wasmBytes = await fetch(wasmUrl).then((r) => r.arrayBuffer());
|
|
73
85
|
|
|
74
|
-
//
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
// Create memory
|
|
87
|
+
const memory = new WebAssembly.Memory({ initial: 256, maximum: 4096 });
|
|
88
|
+
|
|
89
|
+
// Create heap views (initialized after memory is created)
|
|
90
|
+
let HEAP8!: Int8Array;
|
|
91
|
+
let HEAPU8!: Uint8Array;
|
|
92
|
+
let HEAP16!: Int16Array;
|
|
93
|
+
let HEAPU16!: Uint16Array;
|
|
94
|
+
let HEAP32!: Int32Array;
|
|
95
|
+
let HEAPU32!: Uint32Array;
|
|
96
|
+
let HEAPF32!: Float32Array;
|
|
97
|
+
let HEAPF64!: Float64Array;
|
|
98
|
+
|
|
99
|
+
function updateMemoryViews() {
|
|
100
|
+
const buffer = memory.buffer;
|
|
101
|
+
HEAP8 = new Int8Array(buffer);
|
|
102
|
+
HEAPU8 = new Uint8Array(buffer);
|
|
103
|
+
HEAP16 = new Int16Array(buffer);
|
|
104
|
+
HEAPU16 = new Uint16Array(buffer);
|
|
105
|
+
HEAP32 = new Int32Array(buffer);
|
|
106
|
+
HEAPU32 = new Uint32Array(buffer);
|
|
107
|
+
HEAPF32 = new Float32Array(buffer);
|
|
108
|
+
HEAPF64 = new Float64Array(buffer);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
updateMemoryViews();
|
|
112
|
+
|
|
113
|
+
// Import functions expected by the WASM module (still minified with -O3)
|
|
114
|
+
const wasmImports = {
|
|
115
|
+
a: {
|
|
116
|
+
// a: ___cxa_throw
|
|
117
|
+
a: (ptr: number, type: number, destructor: number) => {
|
|
118
|
+
throw new Error('Exception thrown from WASM');
|
|
119
|
+
},
|
|
120
|
+
// e: __abort_js
|
|
121
|
+
e: () => {
|
|
122
|
+
throw new Error('Abort called from WASM');
|
|
123
|
+
},
|
|
124
|
+
// b: __tzset_js
|
|
125
|
+
b: (timezone: number, daylight: number, std_name: number, dst_name: number) => {
|
|
126
|
+
// Minimal timezone implementation
|
|
127
|
+
},
|
|
128
|
+
// f: _emscripten_resize_heap
|
|
129
|
+
f: (requestedSize: number) => {
|
|
130
|
+
const oldSize = HEAPU8.length;
|
|
131
|
+
const newSize = Math.max(oldSize, requestedSize);
|
|
132
|
+
const pages = Math.ceil((newSize - memory.buffer.byteLength) / 65536);
|
|
133
|
+
try {
|
|
134
|
+
memory.grow(pages);
|
|
135
|
+
updateMemoryViews();
|
|
136
|
+
return 1;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
// c: _environ_get
|
|
142
|
+
c: (__environ: number, environ_buf: number) => 0,
|
|
143
|
+
// d: _environ_sizes_get
|
|
144
|
+
d: (penviron_count: number, penviron_buf_size: number) => {
|
|
145
|
+
HEAPU32[penviron_count >> 2] = 0;
|
|
146
|
+
HEAPU32[penviron_buf_size >> 2] = 0;
|
|
147
|
+
return 0;
|
|
148
|
+
},
|
|
149
|
+
// g: memory
|
|
150
|
+
g: memory,
|
|
81
151
|
},
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// Instantiate WASM with the expected imports
|
|
155
|
+
const wasmModule = await WebAssembly.instantiate(wasmBytes, wasmImports);
|
|
86
156
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
157
|
+
const exports = wasmModule.instance.exports as any;
|
|
158
|
+
|
|
159
|
+
// Update memory reference from exports (g is memory in minified version)
|
|
160
|
+
if (exports.g) {
|
|
161
|
+
updateMemoryViews();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Initialize runtime (h is the init function in minified version)
|
|
165
|
+
if (exports.h) {
|
|
166
|
+
exports.h();
|
|
167
|
+
}
|
|
90
168
|
|
|
91
169
|
// Build the module interface
|
|
92
170
|
const module: TagLibModule = {
|
|
93
171
|
// Memory arrays
|
|
94
|
-
HEAPU8
|
|
95
|
-
HEAP8
|
|
96
|
-
HEAP16
|
|
97
|
-
HEAP32
|
|
98
|
-
HEAPU16
|
|
99
|
-
HEAPU32
|
|
100
|
-
HEAPF32
|
|
101
|
-
HEAPF64
|
|
102
|
-
|
|
103
|
-
// Standard functions
|
|
104
|
-
_malloc: exports.
|
|
172
|
+
HEAPU8,
|
|
173
|
+
HEAP8,
|
|
174
|
+
HEAP16,
|
|
175
|
+
HEAP32,
|
|
176
|
+
HEAPU16,
|
|
177
|
+
HEAPU32,
|
|
178
|
+
HEAPF32,
|
|
179
|
+
HEAPF64,
|
|
180
|
+
|
|
181
|
+
// Standard functions (minified with -O3)
|
|
182
|
+
_malloc: exports.P || (() => {
|
|
105
183
|
throw new Error("malloc not available");
|
|
106
184
|
}),
|
|
107
|
-
_free: exports.
|
|
185
|
+
_free: exports.Q || (() => {}),
|
|
108
186
|
allocate: (array: Uint8Array, type: number) => {
|
|
109
187
|
const ptr = module._malloc(array.length);
|
|
188
|
+
// Ensure we have the latest memory view
|
|
189
|
+
if (memory.buffer !== module.HEAPU8.buffer) {
|
|
190
|
+
updateMemoryViews();
|
|
191
|
+
module.HEAPU8 = HEAPU8;
|
|
192
|
+
module.HEAP8 = HEAP8;
|
|
193
|
+
module.HEAP16 = HEAP16;
|
|
194
|
+
module.HEAP32 = HEAP32;
|
|
195
|
+
module.HEAPU16 = HEAPU16;
|
|
196
|
+
module.HEAPU32 = HEAPU32;
|
|
197
|
+
module.HEAPF32 = HEAPF32;
|
|
198
|
+
module.HEAPF64 = HEAPF64;
|
|
199
|
+
}
|
|
110
200
|
module.HEAPU8.set(array, ptr);
|
|
111
201
|
return ptr;
|
|
112
202
|
},
|
|
@@ -118,33 +208,44 @@ export async function loadTagLibModuleJSR(
|
|
|
118
208
|
ALLOC_DYNAMIC: 3,
|
|
119
209
|
ALLOC_NONE: 4,
|
|
120
210
|
|
|
121
|
-
// TagLib functions - map from WASM exports
|
|
122
|
-
_taglib_file_new_from_buffer: exports.
|
|
123
|
-
_taglib_file_delete: exports.
|
|
124
|
-
_taglib_file_save: exports.
|
|
125
|
-
_taglib_file_is_valid: exports.
|
|
126
|
-
_taglib_file_format: exports.
|
|
127
|
-
_taglib_file_tag: exports.
|
|
128
|
-
_taglib_tag_title: exports.
|
|
129
|
-
_taglib_tag_artist: exports.
|
|
130
|
-
_taglib_tag_album: exports.
|
|
131
|
-
_taglib_tag_comment: exports.
|
|
132
|
-
_taglib_tag_genre: exports.
|
|
133
|
-
_taglib_tag_year: exports.
|
|
134
|
-
_taglib_tag_track: exports.
|
|
135
|
-
_taglib_tag_set_title: exports.
|
|
136
|
-
_taglib_tag_set_artist: exports.
|
|
137
|
-
_taglib_tag_set_album: exports.
|
|
138
|
-
_taglib_tag_set_comment: exports.
|
|
139
|
-
_taglib_tag_set_genre: exports.
|
|
140
|
-
_taglib_tag_set_year: exports.
|
|
141
|
-
_taglib_tag_set_track: exports.
|
|
142
|
-
_taglib_file_audioproperties: exports.
|
|
143
|
-
_taglib_audioproperties_length: exports.
|
|
144
|
-
_taglib_audioproperties_bitrate: exports.
|
|
145
|
-
_taglib_audioproperties_samplerate:
|
|
146
|
-
|
|
147
|
-
|
|
211
|
+
// TagLib functions - map from minified WASM exports (with -O3)
|
|
212
|
+
_taglib_file_new_from_buffer: exports.i,
|
|
213
|
+
_taglib_file_delete: exports.j,
|
|
214
|
+
_taglib_file_save: exports.k,
|
|
215
|
+
_taglib_file_is_valid: exports.l,
|
|
216
|
+
_taglib_file_format: exports.m,
|
|
217
|
+
_taglib_file_tag: exports.n,
|
|
218
|
+
_taglib_tag_title: exports.o,
|
|
219
|
+
_taglib_tag_artist: exports.p,
|
|
220
|
+
_taglib_tag_album: exports.q,
|
|
221
|
+
_taglib_tag_comment: exports.r,
|
|
222
|
+
_taglib_tag_genre: exports.s,
|
|
223
|
+
_taglib_tag_year: exports.t,
|
|
224
|
+
_taglib_tag_track: exports.u,
|
|
225
|
+
_taglib_tag_set_title: exports.v,
|
|
226
|
+
_taglib_tag_set_artist: exports.w,
|
|
227
|
+
_taglib_tag_set_album: exports.x,
|
|
228
|
+
_taglib_tag_set_comment: exports.y,
|
|
229
|
+
_taglib_tag_set_genre: exports.z,
|
|
230
|
+
_taglib_tag_set_year: exports.A,
|
|
231
|
+
_taglib_tag_set_track: exports.B,
|
|
232
|
+
_taglib_file_audioproperties: exports.C,
|
|
233
|
+
_taglib_audioproperties_length: exports.D,
|
|
234
|
+
_taglib_audioproperties_bitrate: exports.E,
|
|
235
|
+
_taglib_audioproperties_samplerate: exports.F,
|
|
236
|
+
_taglib_audioproperties_channels: exports.G,
|
|
237
|
+
|
|
238
|
+
// PropertyMap operations
|
|
239
|
+
_taglib_file_properties_json: exports.H,
|
|
240
|
+
_taglib_file_set_properties_json: exports.I,
|
|
241
|
+
_taglib_file_get_property: exports.J,
|
|
242
|
+
_taglib_file_set_property: exports.K,
|
|
243
|
+
|
|
244
|
+
// MP4-specific operations
|
|
245
|
+
_taglib_file_is_mp4: exports.L,
|
|
246
|
+
_taglib_mp4_get_item: exports.M,
|
|
247
|
+
_taglib_mp4_set_item: exports.N,
|
|
248
|
+
_taglib_mp4_remove_item: exports.O,
|
|
148
249
|
};
|
|
149
250
|
|
|
150
251
|
return module;
|
package/src/wasm-workers.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { TagLibConfig, TagLibModule } from "./types.ts";
|
|
|
8
8
|
export type { TagLibModule };
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Default configuration for
|
|
11
|
+
* Default configuration for taglib-wasm module in Workers environment
|
|
12
12
|
* Reduced memory limits to fit within Workers constraints
|
|
13
13
|
*/
|
|
14
14
|
const DEFAULT_WORKERS_CONFIG: Required<TagLibConfig> = {
|
|
@@ -50,7 +50,7 @@ export async function loadTagLibModuleForWorkers(
|
|
|
50
50
|
printErr: mergedConfig.debug ? console.error : () => {},
|
|
51
51
|
onRuntimeInitialized: () => {
|
|
52
52
|
if (mergedConfig.debug) {
|
|
53
|
-
console.log("
|
|
53
|
+
console.log("taglib-wasm module initialized in Workers");
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
// Workers-specific settings
|
|
@@ -69,7 +69,7 @@ export async function loadTagLibModuleForWorkers(
|
|
|
69
69
|
const TagLibWASM = await createWorkersCompatibleModule();
|
|
70
70
|
|
|
71
71
|
if (typeof TagLibWASM !== "function") {
|
|
72
|
-
throw new Error("Failed to load
|
|
72
|
+
throw new Error("Failed to load taglib-wasm module for Workers");
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
const wasmInstance = await TagLibWASM(moduleConfig);
|
|
@@ -92,7 +92,7 @@ export async function loadTagLibModuleForWorkers(
|
|
|
92
92
|
return wasmInstance as TagLibModule;
|
|
93
93
|
} catch (error) {
|
|
94
94
|
throw new Error(
|
|
95
|
-
`Failed to load
|
|
95
|
+
`Failed to load taglib-wasm for Workers: ${(error as Error).message}`,
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
98
|
}
|
package/src/wasm.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { TagLibConfig } from "./types.ts";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Emscripten module interface for
|
|
8
|
+
* Emscripten module interface for taglib-wasm
|
|
9
9
|
*/
|
|
10
10
|
export interface TagLibModule {
|
|
11
11
|
// Emscripten standard properties
|
|
@@ -75,6 +75,18 @@ export interface TagLibModule {
|
|
|
75
75
|
_taglib_audioproperties_samplerate: (props: number) => number;
|
|
76
76
|
_taglib_audioproperties_channels: (props: number) => number;
|
|
77
77
|
|
|
78
|
+
// PropertyMap operations
|
|
79
|
+
_taglib_file_properties_json: (fileId: number) => number;
|
|
80
|
+
_taglib_file_set_properties_json: (fileId: number, json: number) => number;
|
|
81
|
+
_taglib_file_get_property: (fileId: number, key: number) => number;
|
|
82
|
+
_taglib_file_set_property: (fileId: number, key: number, value: number) => number;
|
|
83
|
+
|
|
84
|
+
// MP4-specific operations
|
|
85
|
+
_taglib_file_is_mp4: (fileId: number) => number;
|
|
86
|
+
_taglib_mp4_get_item: (fileId: number, key: number) => number;
|
|
87
|
+
_taglib_mp4_set_item: (fileId: number, key: number, value: number) => number;
|
|
88
|
+
_taglib_mp4_remove_item: (fileId: number, key: number) => number;
|
|
89
|
+
|
|
78
90
|
// String utilities
|
|
79
91
|
_taglib_string_new: (str: number) => number;
|
|
80
92
|
_taglib_string_delete: (str: number) => void;
|
|
@@ -84,7 +96,7 @@ export interface TagLibModule {
|
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
/**
|
|
87
|
-
* Default configuration for
|
|
99
|
+
* Default configuration for taglib-wasm module
|
|
88
100
|
*/
|
|
89
101
|
const DEFAULT_CONFIG: Required<TagLibConfig> = {
|
|
90
102
|
memory: {
|
|
@@ -144,7 +156,7 @@ export async function loadTagLibModule(
|
|
|
144
156
|
printErr: mergedConfig.debug ? console.error : () => {},
|
|
145
157
|
onRuntimeInitialized: () => {
|
|
146
158
|
if (mergedConfig.debug) {
|
|
147
|
-
console.log("
|
|
159
|
+
console.log("taglib-wasm module initialized");
|
|
148
160
|
}
|
|
149
161
|
},
|
|
150
162
|
};
|
|
@@ -201,7 +213,7 @@ export async function loadTagLibModule(
|
|
|
201
213
|
}
|
|
202
214
|
|
|
203
215
|
if (typeof TagLibWASM !== "function") {
|
|
204
|
-
throw new Error("Failed to load
|
|
216
|
+
throw new Error("Failed to load taglib-wasm module");
|
|
205
217
|
}
|
|
206
218
|
|
|
207
219
|
const wasmInstance = await TagLibWASM(moduleConfig);
|
|
@@ -224,7 +236,7 @@ export async function loadTagLibModule(
|
|
|
224
236
|
|
|
225
237
|
return wasmInstance as TagLibModule;
|
|
226
238
|
} catch (error) {
|
|
227
|
-
throw new Error(`Failed to load
|
|
239
|
+
throw new Error(`Failed to load taglib-wasm: ${(error as Error).message}`);
|
|
228
240
|
}
|
|
229
241
|
}
|
|
230
242
|
|