taglib-wasm 0.3.13 → 0.3.15
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 +22 -35
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +117 -134
- package/dist/index.js.map +1 -0
- package/dist/src/constants.js +211 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.js +180 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/file-utils.d.ts +2 -2
- package/dist/src/file-utils.d.ts.map +1 -1
- package/dist/src/file-utils.js +394 -0
- package/dist/src/file-utils.js.map +1 -0
- package/dist/src/mod.d.ts +4 -4
- package/dist/src/mod.d.ts.map +1 -1
- package/dist/src/mod.js +7 -0
- package/dist/src/mod.js.map +1 -0
- package/dist/src/simple.d.ts +4 -4
- package/dist/src/simple.d.ts.map +1 -1
- package/dist/src/{simple.ts → simple.js} +193 -311
- package/dist/src/simple.js.map +1 -0
- package/dist/src/taglib.d.ts +3 -3
- package/dist/src/taglib.d.ts.map +1 -1
- package/dist/src/taglib.js +516 -0
- package/dist/src/taglib.js.map +1 -0
- package/dist/src/types.d.ts +2 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +239 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/file.js +65 -0
- package/dist/src/utils/file.js.map +1 -0
- package/dist/src/utils/write.js +49 -0
- package/dist/src/utils/write.js.map +1 -0
- package/dist/src/wasm-workers.d.ts +1 -1
- package/dist/src/wasm-workers.d.ts.map +1 -1
- package/dist/src/wasm-workers.js +148 -0
- package/dist/src/wasm-workers.js.map +1 -0
- package/dist/src/wasm.js +6 -0
- package/dist/src/wasm.js.map +1 -0
- package/dist/src/web-utils.d.ts +2 -2
- package/dist/src/web-utils.d.ts.map +1 -1
- package/{src/web-utils.ts → dist/src/web-utils.js} +102 -184
- package/dist/src/web-utils.js.map +1 -0
- package/dist/src/workers.d.ts +2 -2
- package/dist/src/workers.d.ts.map +1 -1
- package/dist/src/workers.js +389 -0
- package/dist/src/workers.js.map +1 -0
- package/dist/taglib-wrapper.js +8 -2528
- package/package.json +7 -10
- package/dist/index.ts +0 -221
- package/dist/src/constants.ts +0 -227
- package/dist/src/errors.ts +0 -254
- package/dist/src/file-utils.ts +0 -483
- package/dist/src/file.js +0 -52
- package/dist/src/global.d.ts +0 -12
- package/dist/src/mod.ts +0 -19
- package/dist/src/taglib.ts +0 -961
- package/dist/src/types.ts +0 -538
- package/dist/src/utils/file.ts +0 -86
- package/dist/src/utils/write.ts +0 -66
- package/dist/src/wasm-workers.ts +0 -176
- package/dist/src/wasm.ts +0 -133
- package/dist/src/web-utils.ts +0 -347
- package/dist/src/workers.ts +0 -461
- package/dist/src/write.js +0 -33
- package/index.ts +0 -221
- package/lib/taglib/COPYING.LGPL +0 -502
- package/lib/taglib/COPYING.MPL +0 -470
- package/lib/taglib/README.md +0 -24
- package/src/constants.ts +0 -227
- package/src/errors.ts +0 -254
- package/src/file-utils.ts +0 -483
- package/src/global.d.ts +0 -12
- package/src/mod.ts +0 -19
- package/src/simple.ts +0 -667
- package/src/taglib.ts +0 -961
- package/src/types.ts +0 -538
- package/src/utils/file.ts +0 -86
- package/src/utils/write.ts +0 -66
- package/src/wasm-workers.ts +0 -176
- package/src/wasm.ts +0 -133
- package/src/workers.ts +0 -461
package/src/types.ts
DELETED
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview TypeScript type definitions for taglib-wasm
|
|
3
|
-
*
|
|
4
|
-
* This module contains all the type definitions used throughout
|
|
5
|
-
* the taglib-wasm library, including metadata structures,
|
|
6
|
-
* audio properties, and format-specific mappings.
|
|
7
|
-
*
|
|
8
|
-
* @module taglib-wasm/types
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// Re-export commonly used classes from other modules
|
|
12
|
-
export type { TagLibModule } from "./wasm.ts";
|
|
13
|
-
// Note: AudioFile is not needed for JSR exports
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Supported file types detected by TagLib.
|
|
17
|
-
* "UNKNOWN" indicates the format could not be determined.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const file = await taglib.open(buffer);
|
|
22
|
-
* const format = file.getFormat();
|
|
23
|
-
* if (format === "MP3") {
|
|
24
|
-
* // Handle MP3-specific features
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export type FileType =
|
|
29
|
-
| "MP3"
|
|
30
|
-
| "MP4"
|
|
31
|
-
| "FLAC"
|
|
32
|
-
| "OGG"
|
|
33
|
-
| "OPUS"
|
|
34
|
-
| "WAV"
|
|
35
|
-
| "AIFF"
|
|
36
|
-
| "UNKNOWN";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Audio format types supported by TagLib.
|
|
40
|
-
* More comprehensive than FileType, includes additional formats
|
|
41
|
-
* that TagLib can read but may have limited support.
|
|
42
|
-
*/
|
|
43
|
-
export type AudioFormat =
|
|
44
|
-
| "MP3"
|
|
45
|
-
| "MP4"
|
|
46
|
-
| "M4A"
|
|
47
|
-
| "FLAC"
|
|
48
|
-
| "OGG"
|
|
49
|
-
| "OPUS"
|
|
50
|
-
| "WAV"
|
|
51
|
-
| "AIFF"
|
|
52
|
-
| "WMA"
|
|
53
|
-
| "APE"
|
|
54
|
-
| "MPC"
|
|
55
|
-
| "TTA"
|
|
56
|
-
| "WV"
|
|
57
|
-
| "MOD"
|
|
58
|
-
| "IT"
|
|
59
|
-
| "S3M"
|
|
60
|
-
| "XM";
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Audio properties containing technical information about the file.
|
|
64
|
-
* All properties are read-only and represent the actual audio stream data.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* const props = file.audioProperties();
|
|
69
|
-
* console.log(`Duration: ${props.length} seconds`);
|
|
70
|
-
* console.log(`Bitrate: ${props.bitrate} kbps`);
|
|
71
|
-
* console.log(`Sample rate: ${props.sampleRate} Hz`);
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export interface AudioProperties {
|
|
75
|
-
/** Length of the audio in seconds */
|
|
76
|
-
readonly length: number;
|
|
77
|
-
/** Bitrate in kb/s */
|
|
78
|
-
readonly bitrate: number;
|
|
79
|
-
/** Sample rate in Hz */
|
|
80
|
-
readonly sampleRate: number;
|
|
81
|
-
/** Number of audio channels */
|
|
82
|
-
readonly channels: number;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Basic metadata tags common to all audio formats.
|
|
87
|
-
* These are the standard fields supported by most audio files.
|
|
88
|
-
* All fields are optional as not all formats support all fields.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const tag: Tag = {
|
|
93
|
-
* title: "Song Title",
|
|
94
|
-
* artist: "Artist Name",
|
|
95
|
-
* album: "Album Name",
|
|
96
|
-
* year: 2025,
|
|
97
|
-
* track: 5
|
|
98
|
-
* };
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export interface Tag {
|
|
102
|
-
/** Track title */
|
|
103
|
-
title?: string;
|
|
104
|
-
/** Artist name */
|
|
105
|
-
artist?: string;
|
|
106
|
-
/** Album name */
|
|
107
|
-
album?: string;
|
|
108
|
-
/** Comment */
|
|
109
|
-
comment?: string;
|
|
110
|
-
/** Genre */
|
|
111
|
-
genre?: string;
|
|
112
|
-
/** Year */
|
|
113
|
-
year?: number;
|
|
114
|
-
/** Track number */
|
|
115
|
-
track?: number;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Extended metadata with format-agnostic field names.
|
|
120
|
-
* Includes advanced fields like MusicBrainz IDs, ReplayGain values,
|
|
121
|
-
* and other specialized metadata. Field availability depends on
|
|
122
|
-
* the audio format and existing metadata.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```typescript
|
|
126
|
-
* const extTag: ExtendedTag = {
|
|
127
|
-
* ...basicTag,
|
|
128
|
-
* albumArtist: "Various Artists",
|
|
129
|
-
* musicbrainzTrackId: "123e4567-e89b-12d3-a456-426614174000",
|
|
130
|
-
* replayGainTrackGain: "-6.54 dB",
|
|
131
|
-
* bpm: 120
|
|
132
|
-
* };
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
export interface ExtendedTag extends Tag {
|
|
136
|
-
/** AcoustID fingerprint (Chromaprint) */
|
|
137
|
-
acoustidFingerprint?: string;
|
|
138
|
-
/** AcoustID UUID */
|
|
139
|
-
acoustidId?: string;
|
|
140
|
-
/** MusicBrainz Track ID */
|
|
141
|
-
musicbrainzTrackId?: string;
|
|
142
|
-
/** MusicBrainz Release ID */
|
|
143
|
-
musicbrainzReleaseId?: string;
|
|
144
|
-
/** MusicBrainz Artist ID */
|
|
145
|
-
musicbrainzArtistId?: string;
|
|
146
|
-
/** MusicBrainz Release Group ID */
|
|
147
|
-
musicbrainzReleaseGroupId?: string;
|
|
148
|
-
/** Album artist (different from track artist) */
|
|
149
|
-
albumArtist?: string;
|
|
150
|
-
/** Composer */
|
|
151
|
-
composer?: string;
|
|
152
|
-
/** Disc number */
|
|
153
|
-
discNumber?: number;
|
|
154
|
-
/** Total tracks on album */
|
|
155
|
-
totalTracks?: number;
|
|
156
|
-
/** Total discs in release */
|
|
157
|
-
totalDiscs?: number;
|
|
158
|
-
/** BPM (beats per minute) */
|
|
159
|
-
bpm?: number;
|
|
160
|
-
/** Compilation flag */
|
|
161
|
-
compilation?: boolean;
|
|
162
|
-
/** Sort title for alphabetization */
|
|
163
|
-
titleSort?: string;
|
|
164
|
-
/** Sort artist for alphabetization */
|
|
165
|
-
artistSort?: string;
|
|
166
|
-
/** Sort album for alphabetization */
|
|
167
|
-
albumSort?: string;
|
|
168
|
-
|
|
169
|
-
// ReplayGain fields
|
|
170
|
-
/** ReplayGain track gain in dB (e.g., "-6.54 dB") */
|
|
171
|
-
replayGainTrackGain?: string;
|
|
172
|
-
/** ReplayGain track peak value (0.0-1.0) */
|
|
173
|
-
replayGainTrackPeak?: string;
|
|
174
|
-
/** ReplayGain album gain in dB */
|
|
175
|
-
replayGainAlbumGain?: string;
|
|
176
|
-
/** ReplayGain album peak value (0.0-1.0) */
|
|
177
|
-
replayGainAlbumPeak?: string;
|
|
178
|
-
|
|
179
|
-
// Apple Sound Check
|
|
180
|
-
/** Apple Sound Check normalization data (iTunNORM) */
|
|
181
|
-
appleSoundCheck?: string;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Format-specific field mapping for automatic tag mapping.
|
|
186
|
-
* Defines how a metadata field maps to different audio formats.
|
|
187
|
-
* Used internally for format-agnostic metadata operations.
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
* const artistMapping: FieldMapping = {
|
|
192
|
-
* id3v2: { frame: "TPE1" },
|
|
193
|
-
* vorbis: "ARTIST",
|
|
194
|
-
* mp4: "©ART",
|
|
195
|
-
* wav: "IART"
|
|
196
|
-
* };
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
export interface FieldMapping {
|
|
200
|
-
/** MP3 ID3v2 mapping */
|
|
201
|
-
id3v2?: {
|
|
202
|
-
frame: string;
|
|
203
|
-
description?: string; // For TXXX frames
|
|
204
|
-
};
|
|
205
|
-
/** FLAC/OGG Vorbis Comments mapping */
|
|
206
|
-
vorbis?: string;
|
|
207
|
-
/** MP4/M4A atom mapping */
|
|
208
|
-
mp4?: string;
|
|
209
|
-
/** WAV INFO chunk mapping */
|
|
210
|
-
wav?: string;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Complete metadata field mappings for all formats.
|
|
215
|
-
* This constant defines how each ExtendedTag field maps to
|
|
216
|
-
* format-specific metadata fields across different audio formats.
|
|
217
|
-
* Used for automatic tag mapping in format-agnostic operations.
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```typescript
|
|
221
|
-
* // Get the ID3v2 frame for the artist field
|
|
222
|
-
* const artistFrame = METADATA_MAPPINGS.artist.id3v2?.frame; // "TPE1"
|
|
223
|
-
*
|
|
224
|
-
* // Get the Vorbis comment field for album artist
|
|
225
|
-
* const vorbisField = METADATA_MAPPINGS.albumArtist.vorbis; // "ALBUMARTIST"
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
export const METADATA_MAPPINGS: Record<keyof ExtendedTag, FieldMapping> = {
|
|
229
|
-
// Basic fields (already handled by TagLib's standard API)
|
|
230
|
-
title: {
|
|
231
|
-
id3v2: { frame: "TIT2" },
|
|
232
|
-
vorbis: "TITLE",
|
|
233
|
-
mp4: "©nam",
|
|
234
|
-
wav: "INAM",
|
|
235
|
-
},
|
|
236
|
-
artist: {
|
|
237
|
-
id3v2: { frame: "TPE1" },
|
|
238
|
-
vorbis: "ARTIST",
|
|
239
|
-
mp4: "©ART",
|
|
240
|
-
wav: "IART",
|
|
241
|
-
},
|
|
242
|
-
album: {
|
|
243
|
-
id3v2: { frame: "TALB" },
|
|
244
|
-
vorbis: "ALBUM",
|
|
245
|
-
mp4: "©alb",
|
|
246
|
-
wav: "IPRD",
|
|
247
|
-
},
|
|
248
|
-
comment: {
|
|
249
|
-
id3v2: { frame: "COMM" },
|
|
250
|
-
vorbis: "COMMENT",
|
|
251
|
-
mp4: "©cmt",
|
|
252
|
-
wav: "ICMT",
|
|
253
|
-
},
|
|
254
|
-
genre: {
|
|
255
|
-
id3v2: { frame: "TCON" },
|
|
256
|
-
vorbis: "GENRE",
|
|
257
|
-
mp4: "©gen",
|
|
258
|
-
wav: "IGNR",
|
|
259
|
-
},
|
|
260
|
-
year: {
|
|
261
|
-
id3v2: { frame: "TDRC" },
|
|
262
|
-
vorbis: "DATE",
|
|
263
|
-
mp4: "©day",
|
|
264
|
-
wav: "ICRD",
|
|
265
|
-
},
|
|
266
|
-
track: {
|
|
267
|
-
id3v2: { frame: "TRCK" },
|
|
268
|
-
vorbis: "TRACKNUMBER",
|
|
269
|
-
mp4: "trkn",
|
|
270
|
-
wav: "ITRK",
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
// Advanced fields requiring format-specific handling
|
|
274
|
-
acoustidFingerprint: {
|
|
275
|
-
id3v2: { frame: "TXXX", description: "Acoustid Fingerprint" },
|
|
276
|
-
vorbis: "ACOUSTID_FINGERPRINT",
|
|
277
|
-
mp4: "----:com.apple.iTunes:Acoustid Fingerprint",
|
|
278
|
-
},
|
|
279
|
-
acoustidId: {
|
|
280
|
-
id3v2: { frame: "TXXX", description: "Acoustid Id" },
|
|
281
|
-
vorbis: "ACOUSTID_ID",
|
|
282
|
-
mp4: "----:com.apple.iTunes:Acoustid Id",
|
|
283
|
-
},
|
|
284
|
-
musicbrainzTrackId: {
|
|
285
|
-
id3v2: { frame: "UFID", description: "http://musicbrainz.org" },
|
|
286
|
-
vorbis: "MUSICBRAINZ_TRACKID",
|
|
287
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Track Id",
|
|
288
|
-
},
|
|
289
|
-
musicbrainzReleaseId: {
|
|
290
|
-
id3v2: { frame: "TXXX", description: "MusicBrainz Album Id" },
|
|
291
|
-
vorbis: "MUSICBRAINZ_ALBUMID",
|
|
292
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Album Id",
|
|
293
|
-
},
|
|
294
|
-
musicbrainzArtistId: {
|
|
295
|
-
id3v2: { frame: "TXXX", description: "MusicBrainz Artist Id" },
|
|
296
|
-
vorbis: "MUSICBRAINZ_ARTISTID",
|
|
297
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Artist Id",
|
|
298
|
-
},
|
|
299
|
-
musicbrainzReleaseGroupId: {
|
|
300
|
-
id3v2: { frame: "TXXX", description: "MusicBrainz Release Group Id" },
|
|
301
|
-
vorbis: "MUSICBRAINZ_RELEASEGROUPID",
|
|
302
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Release Group Id",
|
|
303
|
-
},
|
|
304
|
-
albumArtist: {
|
|
305
|
-
id3v2: { frame: "TPE2" },
|
|
306
|
-
vorbis: "ALBUMARTIST",
|
|
307
|
-
mp4: "aART",
|
|
308
|
-
},
|
|
309
|
-
composer: {
|
|
310
|
-
id3v2: { frame: "TCOM" },
|
|
311
|
-
vorbis: "COMPOSER",
|
|
312
|
-
mp4: "©wrt",
|
|
313
|
-
},
|
|
314
|
-
discNumber: {
|
|
315
|
-
id3v2: { frame: "TPOS" },
|
|
316
|
-
vorbis: "DISCNUMBER",
|
|
317
|
-
mp4: "disk",
|
|
318
|
-
},
|
|
319
|
-
totalTracks: {
|
|
320
|
-
id3v2: { frame: "TRCK" }, // Part of TRCK frame
|
|
321
|
-
vorbis: "TRACKTOTAL",
|
|
322
|
-
mp4: "trkn", // Part of trkn atom
|
|
323
|
-
},
|
|
324
|
-
totalDiscs: {
|
|
325
|
-
id3v2: { frame: "TPOS" }, // Part of TPOS frame
|
|
326
|
-
vorbis: "DISCTOTAL",
|
|
327
|
-
mp4: "disk", // Part of disk atom
|
|
328
|
-
},
|
|
329
|
-
bpm: {
|
|
330
|
-
id3v2: { frame: "TBPM" },
|
|
331
|
-
vorbis: "BPM",
|
|
332
|
-
mp4: "tmpo",
|
|
333
|
-
},
|
|
334
|
-
compilation: {
|
|
335
|
-
id3v2: { frame: "TCMP" },
|
|
336
|
-
vorbis: "COMPILATION",
|
|
337
|
-
mp4: "cpil",
|
|
338
|
-
},
|
|
339
|
-
titleSort: {
|
|
340
|
-
id3v2: { frame: "TSOT" },
|
|
341
|
-
vorbis: "TITLESORT",
|
|
342
|
-
mp4: "sonm",
|
|
343
|
-
},
|
|
344
|
-
artistSort: {
|
|
345
|
-
id3v2: { frame: "TSOP" },
|
|
346
|
-
vorbis: "ARTISTSORT",
|
|
347
|
-
mp4: "soar",
|
|
348
|
-
},
|
|
349
|
-
albumSort: {
|
|
350
|
-
id3v2: { frame: "TSOA" },
|
|
351
|
-
vorbis: "ALBUMSORT",
|
|
352
|
-
mp4: "soal",
|
|
353
|
-
},
|
|
354
|
-
|
|
355
|
-
// ReplayGain mappings
|
|
356
|
-
replayGainTrackGain: {
|
|
357
|
-
id3v2: { frame: "TXXX", description: "ReplayGain_Track_Gain" },
|
|
358
|
-
vorbis: "REPLAYGAIN_TRACK_GAIN",
|
|
359
|
-
mp4: "----:com.apple.iTunes:replaygain_track_gain",
|
|
360
|
-
},
|
|
361
|
-
replayGainTrackPeak: {
|
|
362
|
-
id3v2: { frame: "TXXX", description: "ReplayGain_Track_Peak" },
|
|
363
|
-
vorbis: "REPLAYGAIN_TRACK_PEAK",
|
|
364
|
-
mp4: "----:com.apple.iTunes:replaygain_track_peak",
|
|
365
|
-
},
|
|
366
|
-
replayGainAlbumGain: {
|
|
367
|
-
id3v2: { frame: "TXXX", description: "ReplayGain_Album_Gain" },
|
|
368
|
-
vorbis: "REPLAYGAIN_ALBUM_GAIN",
|
|
369
|
-
mp4: "----:com.apple.iTunes:replaygain_album_gain",
|
|
370
|
-
},
|
|
371
|
-
replayGainAlbumPeak: {
|
|
372
|
-
id3v2: { frame: "TXXX", description: "ReplayGain_Album_Peak" },
|
|
373
|
-
vorbis: "REPLAYGAIN_ALBUM_PEAK",
|
|
374
|
-
mp4: "----:com.apple.iTunes:replaygain_album_peak",
|
|
375
|
-
},
|
|
376
|
-
|
|
377
|
-
// Apple Sound Check mapping
|
|
378
|
-
appleSoundCheck: {
|
|
379
|
-
id3v2: { frame: "TXXX", description: "iTunNORM" },
|
|
380
|
-
vorbis: "ITUNNORM", // Some tools store it in Vorbis comments too
|
|
381
|
-
mp4: "----:com.apple.iTunes:iTunNORM",
|
|
382
|
-
},
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Extended metadata properties map.
|
|
387
|
-
* A flexible key-value structure where each key can have multiple values.
|
|
388
|
-
* Used for accessing all metadata in a file, including non-standard fields.
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* ```typescript
|
|
392
|
-
* const properties: PropertyMap = {
|
|
393
|
-
* "ARTIST": ["Artist Name"],
|
|
394
|
-
* "ALBUMARTIST": ["Album Artist"],
|
|
395
|
-
* "MUSICBRAINZ_TRACKID": ["123e4567-e89b-12d3-a456-426614174000"]
|
|
396
|
-
* };
|
|
397
|
-
* ```
|
|
398
|
-
*/
|
|
399
|
-
export interface PropertyMap {
|
|
400
|
-
[key: string]: string[];
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Re-export TagName type from constants
|
|
405
|
-
*/
|
|
406
|
-
export type { TagName } from "./constants.ts";
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Picture/artwork data embedded in audio files.
|
|
410
|
-
* Represents album art, artist photos, or other images.
|
|
411
|
-
*
|
|
412
|
-
* @example
|
|
413
|
-
* ```typescript
|
|
414
|
-
* const picture: Picture = {
|
|
415
|
-
* mimeType: "image/jpeg",
|
|
416
|
-
* data: new Uint8Array(imageBuffer),
|
|
417
|
-
* type: PictureType.FrontCover,
|
|
418
|
-
* description: "Album cover"
|
|
419
|
-
* };
|
|
420
|
-
* ```
|
|
421
|
-
*/
|
|
422
|
-
export interface Picture {
|
|
423
|
-
/** MIME type of the image */
|
|
424
|
-
mimeType: string;
|
|
425
|
-
/** Image data */
|
|
426
|
-
data: Uint8Array;
|
|
427
|
-
/** Picture type (front cover, back cover, etc.) */
|
|
428
|
-
type: PictureType;
|
|
429
|
-
/** Description */
|
|
430
|
-
description?: string;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Picture types as defined by ID3v2 APIC frame.
|
|
435
|
-
* Standard picture type codes used across different formats
|
|
436
|
-
* to categorize embedded images.
|
|
437
|
-
*
|
|
438
|
-
* @example
|
|
439
|
-
* ```typescript
|
|
440
|
-
* // Set front cover art
|
|
441
|
-
* const coverArt = {
|
|
442
|
-
* type: PictureType.FrontCover,
|
|
443
|
-
* mimeType: "image/jpeg",
|
|
444
|
-
* data: imageData
|
|
445
|
-
* };
|
|
446
|
-
* ```
|
|
447
|
-
*/
|
|
448
|
-
export enum PictureType {
|
|
449
|
-
Other = 0,
|
|
450
|
-
FileIcon = 1,
|
|
451
|
-
OtherFileIcon = 2,
|
|
452
|
-
FrontCover = 3,
|
|
453
|
-
BackCover = 4,
|
|
454
|
-
LeafletPage = 5,
|
|
455
|
-
Media = 6,
|
|
456
|
-
LeadArtist = 7,
|
|
457
|
-
Artist = 8,
|
|
458
|
-
Conductor = 9,
|
|
459
|
-
Band = 10,
|
|
460
|
-
Composer = 11,
|
|
461
|
-
Lyricist = 12,
|
|
462
|
-
RecordingLocation = 13,
|
|
463
|
-
DuringRecording = 14,
|
|
464
|
-
DuringPerformance = 15,
|
|
465
|
-
MovieScreenCapture = 16,
|
|
466
|
-
ColouredFish = 17,
|
|
467
|
-
Illustration = 18,
|
|
468
|
-
BandLogo = 19,
|
|
469
|
-
PublisherLogo = 20,
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Bitrate control modes for audio encoding (MP4/M4A specific).
|
|
474
|
-
* Indicates how the audio was encoded in terms of bitrate management.
|
|
475
|
-
*
|
|
476
|
-
* - Constant: Fixed bitrate throughout the file
|
|
477
|
-
* - LongTermAverage: Average bitrate over time
|
|
478
|
-
* - VariableConstrained: Variable within limits
|
|
479
|
-
* - Variable: Fully variable bitrate
|
|
480
|
-
*/
|
|
481
|
-
export type BitrateControlMode =
|
|
482
|
-
| "Constant"
|
|
483
|
-
| "LongTermAverage"
|
|
484
|
-
| "VariableConstrained"
|
|
485
|
-
| "Variable";
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Map of bitrate control mode names to their numeric values.
|
|
489
|
-
* Used for converting between string representations and numeric codes
|
|
490
|
-
* stored in MP4/M4A files.
|
|
491
|
-
*/
|
|
492
|
-
export const BITRATE_CONTROL_MODE_VALUES: Record<BitrateControlMode, number> = {
|
|
493
|
-
Constant: 0,
|
|
494
|
-
LongTermAverage: 1,
|
|
495
|
-
VariableConstrained: 2,
|
|
496
|
-
Variable: 3,
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Map of numeric values to bitrate control mode names.
|
|
501
|
-
* Used for converting numeric codes from MP4/M4A files
|
|
502
|
-
* to human-readable string representations.
|
|
503
|
-
*/
|
|
504
|
-
export const BITRATE_CONTROL_MODE_NAMES: Record<number, BitrateControlMode> = {
|
|
505
|
-
0: "Constant",
|
|
506
|
-
1: "LongTermAverage",
|
|
507
|
-
2: "VariableConstrained",
|
|
508
|
-
3: "Variable",
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Configuration options for TagLib initialization.
|
|
513
|
-
* Allows customization of memory limits and debug settings.
|
|
514
|
-
*
|
|
515
|
-
* @example
|
|
516
|
-
* ```typescript
|
|
517
|
-
* const config: TagLibConfig = {
|
|
518
|
-
* memory: {
|
|
519
|
-
* initial: 16 * 1024 * 1024, // 16MB
|
|
520
|
-
* maximum: 64 * 1024 * 1024 // 64MB
|
|
521
|
-
* },
|
|
522
|
-
* debug: true
|
|
523
|
-
* };
|
|
524
|
-
*
|
|
525
|
-
* const taglib = await TagLibWorkers.initialize(wasmBinary, config);
|
|
526
|
-
* ```
|
|
527
|
-
*/
|
|
528
|
-
export interface TagLibConfig {
|
|
529
|
-
/** Memory allocation settings */
|
|
530
|
-
memory?: {
|
|
531
|
-
/** Initial memory size in bytes */
|
|
532
|
-
initial?: number;
|
|
533
|
-
/** Maximum memory size in bytes */
|
|
534
|
-
maximum?: number;
|
|
535
|
-
};
|
|
536
|
-
/** Enable debug output */
|
|
537
|
-
debug?: boolean;
|
|
538
|
-
}
|
package/src/utils/file.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File reading utilities for taglib-wasm
|
|
3
|
-
* Provides cross-runtime support for reading files from various sources
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { EnvironmentError, FileOperationError } from "../errors.ts";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Read a file's data from various sources.
|
|
10
|
-
* Supports file paths (Node.js/Deno/Bun), buffers, and File objects (browser).
|
|
11
|
-
*
|
|
12
|
-
* @param file - File path, Uint8Array, ArrayBuffer, or File object
|
|
13
|
-
* @returns Promise resolving to Uint8Array of file data
|
|
14
|
-
* @throws {FileOperationError} If file read fails
|
|
15
|
-
* @throws {EnvironmentError} If environment doesn't support file paths
|
|
16
|
-
*/
|
|
17
|
-
export async function readFileData(
|
|
18
|
-
file: string | Uint8Array | ArrayBuffer | File,
|
|
19
|
-
): Promise<Uint8Array> {
|
|
20
|
-
// Already a Uint8Array
|
|
21
|
-
if (file instanceof Uint8Array) {
|
|
22
|
-
return file;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// ArrayBuffer - convert to Uint8Array
|
|
26
|
-
if (file instanceof ArrayBuffer) {
|
|
27
|
-
return new Uint8Array(file);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// File object (browser)
|
|
31
|
-
if (typeof File !== "undefined" && file instanceof File) {
|
|
32
|
-
return new Uint8Array(await file.arrayBuffer());
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// String path - read from filesystem
|
|
36
|
-
if (typeof file === "string") {
|
|
37
|
-
// Check environment support first
|
|
38
|
-
const hasDeno = typeof (globalThis as any).Deno !== "undefined";
|
|
39
|
-
const hasNode = typeof (globalThis as any).process !== "undefined" &&
|
|
40
|
-
(globalThis as any).process.versions &&
|
|
41
|
-
(globalThis as any).process.versions.node;
|
|
42
|
-
const hasBun = typeof (globalThis as any).Bun !== "undefined";
|
|
43
|
-
|
|
44
|
-
// If no runtime supports filesystem, throw EnvironmentError
|
|
45
|
-
if (!hasDeno && !hasNode && !hasBun) {
|
|
46
|
-
const env = "Browser";
|
|
47
|
-
throw new EnvironmentError(
|
|
48
|
-
env,
|
|
49
|
-
"does not support file path reading",
|
|
50
|
-
"filesystem access",
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
// Deno
|
|
56
|
-
if (hasDeno) {
|
|
57
|
-
return await (globalThis as any).Deno.readFile(file);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Node.js
|
|
61
|
-
if (hasNode) {
|
|
62
|
-
const { readFile } = await import("fs/promises");
|
|
63
|
-
return new Uint8Array(await readFile(file));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Bun
|
|
67
|
-
if (hasBun) {
|
|
68
|
-
const bunFile = (globalThis as any).Bun.file(file);
|
|
69
|
-
return new Uint8Array(await bunFile.arrayBuffer());
|
|
70
|
-
}
|
|
71
|
-
} catch (error) {
|
|
72
|
-
// Convert system file errors to FileOperationError
|
|
73
|
-
throw new FileOperationError(
|
|
74
|
-
"read",
|
|
75
|
-
(error as Error).message,
|
|
76
|
-
file,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const inputType = Object.prototype.toString.call(file);
|
|
82
|
-
throw new FileOperationError(
|
|
83
|
-
"read",
|
|
84
|
-
`Invalid file input type: ${inputType}. Expected string path, Uint8Array, ArrayBuffer, or File object.`,
|
|
85
|
-
);
|
|
86
|
-
}
|
package/src/utils/write.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File writing utilities for taglib-wasm
|
|
3
|
-
* Provides cross-runtime support for writing files
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { EnvironmentError, FileOperationError } from "../errors.ts";
|
|
7
|
-
import process from "node:process";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Write data to a file across different runtimes.
|
|
11
|
-
* Supports Node.js, Deno, and Bun environments.
|
|
12
|
-
*
|
|
13
|
-
* @param path - File path to write to
|
|
14
|
-
* @param data - Data to write (Uint8Array)
|
|
15
|
-
* @throws {FileOperationError} If file write fails
|
|
16
|
-
* @throws {EnvironmentError} If environment doesn't support file writing
|
|
17
|
-
*/
|
|
18
|
-
export async function writeFileData(
|
|
19
|
-
path: string,
|
|
20
|
-
data: Uint8Array,
|
|
21
|
-
): Promise<void> {
|
|
22
|
-
try {
|
|
23
|
-
// Deno
|
|
24
|
-
if (typeof (globalThis as any).Deno !== "undefined") {
|
|
25
|
-
await (globalThis as any).Deno.writeFile(path, data);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Node.js
|
|
30
|
-
if (
|
|
31
|
-
typeof (globalThis as any).process !== "undefined" &&
|
|
32
|
-
(globalThis as any).process.versions &&
|
|
33
|
-
(globalThis as any).process.versions.node
|
|
34
|
-
) {
|
|
35
|
-
const { writeFile } = await import("fs/promises");
|
|
36
|
-
await writeFile(path, data);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Bun
|
|
41
|
-
if (typeof (globalThis as any).Bun !== "undefined") {
|
|
42
|
-
await (globalThis as any).Bun.write(path, data);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
} catch (error) {
|
|
46
|
-
// Convert system file errors to FileOperationError
|
|
47
|
-
throw new FileOperationError(
|
|
48
|
-
"write",
|
|
49
|
-
(error as Error).message,
|
|
50
|
-
path,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const env = typeof (globalThis as any).Deno !== "undefined"
|
|
55
|
-
? "Deno"
|
|
56
|
-
: typeof (globalThis as any).process !== "undefined"
|
|
57
|
-
? "Node.js"
|
|
58
|
-
: typeof (globalThis as any).Bun !== "undefined"
|
|
59
|
-
? "Bun"
|
|
60
|
-
: "Browser";
|
|
61
|
-
throw new EnvironmentError(
|
|
62
|
-
env,
|
|
63
|
-
"does not support file path writing",
|
|
64
|
-
"filesystem access",
|
|
65
|
-
);
|
|
66
|
-
}
|