taglib-wasm 0.3.24 β 0.3.26
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 +337 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# TagLib-Wasm
|
|
2
|
+
|
|
3
|
+
[](https://github.com/CharlesWiltgen/taglib-wasm/actions/workflows/test.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/taglib-wasm)
|
|
5
|
+
[](https://www.npmjs.com/package/taglib-wasm)
|
|
6
|
+
[](https://github.com/CharlesWiltgen/taglib-wasm/blob/main/LICENSE)
|
|
7
|
+
<br>[](https://www.typescriptlang.org/)
|
|
8
|
+
[](https://emscripten.org/)
|
|
9
|
+
[](https://webassembly.org/)
|
|
10
|
+
[](https://taglib.org/)
|
|
11
|
+
<br>[](https://deno.land/)
|
|
12
|
+
[](https://nodejs.org/)
|
|
13
|
+
[](https://bun.sh/)
|
|
14
|
+
[](https://workers.cloudflare.com/)
|
|
15
|
+
[](https://www.electronjs.org/)
|
|
16
|
+
[](https://html.spec.whatwg.org/multipage/)
|
|
17
|
+
|
|
18
|
+
TagLib-Wasm is the **universal tagging library for TypeScript/JavaScript**
|
|
19
|
+
(TS|JS) platforms: **Deno**, **Node.js**, **Bun**, **Cloudflare Workers**,
|
|
20
|
+
**Electron**, and **browsers**.
|
|
21
|
+
|
|
22
|
+
This project exists because the TS|JS ecosystem had no battle-tested audio
|
|
23
|
+
tagging library that supports reading and writing music metadata to all popular
|
|
24
|
+
audio formats. It aspires to be a universal solution for all TS|JS-capable
|
|
25
|
+
platforms β Deno, Node.js, Bun, Electron, Cloudflare Workers, and browsers.
|
|
26
|
+
|
|
27
|
+
TagLib-Wasm stands on the shoulders of giants, including
|
|
28
|
+
[TagLib](https://taglib.org/) itself, [Emscripten](https://emscripten.org/), and
|
|
29
|
+
[Wasm](https://webassembly.org/) ([WebAssembly](https://webassembly.org/)).
|
|
30
|
+
TagLib itself is legendary, and a core dependency of many music apps.
|
|
31
|
+
|
|
32
|
+
## π― Features
|
|
33
|
+
|
|
34
|
+
- **β
Full audio format support** β Supports all audio formats supported by
|
|
35
|
+
TagLib
|
|
36
|
+
- **β
TypeScript first** β Complete type definitions and modern API
|
|
37
|
+
- **β
Wide TS/JS runtime support** β Deno, Node.js, Bun, Electron, Cloudflare
|
|
38
|
+
Workers, and browsers
|
|
39
|
+
- **β
Format abstraction** β Handles container format details automagically
|
|
40
|
+
when possible
|
|
41
|
+
- **β
Zero dependencies** β Self-contained Wasm bundle
|
|
42
|
+
- **β
Production ready** β Growing test suite helps ensure safety and
|
|
43
|
+
reliability
|
|
44
|
+
- **β
Two API styles** β Use the βSimpleβ API (3 functions), or the full βCoreβ
|
|
45
|
+
API for more advanced applications
|
|
46
|
+
|
|
47
|
+
## π¦ Installation
|
|
48
|
+
|
|
49
|
+
### Deno
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { TagLib } from "@charlesw/taglib-wasm";
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Node.js
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install taglib-wasm
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> **Note:** Requires Node.js v22.6.0 or higher. If you want to use the
|
|
62
|
+
> TypeScript version with Node.js, see the
|
|
63
|
+
> [installation guide](https://charleswiltgen.github.io/taglib-wasm/guide/installation.html).
|
|
64
|
+
|
|
65
|
+
### Bun
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bun add taglib-wasm
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Electron
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install taglib-wasm
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Works in both main and renderer processes:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Main process
|
|
81
|
+
import { TagLib } from "taglib-wasm";
|
|
82
|
+
|
|
83
|
+
// Renderer process (with nodeIntegration: true)
|
|
84
|
+
const { TagLib } = require("taglib-wasm");
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Deno Compiled Binaries (Offline Support)
|
|
88
|
+
|
|
89
|
+
For Deno compiled binaries that need to work offline, you can embed the WASM file:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// 1. Prepare your build by copying the WASM file
|
|
93
|
+
import { prepareWasmForEmbedding } from "@charlesw/taglib-wasm";
|
|
94
|
+
await prepareWasmForEmbedding("./taglib.wasm");
|
|
95
|
+
|
|
96
|
+
// 2. In your application, use the helper for automatic handling
|
|
97
|
+
import { initializeForDenoCompile } from "@charlesw/taglib-wasm";
|
|
98
|
+
const taglib = await initializeForDenoCompile();
|
|
99
|
+
|
|
100
|
+
// 3. Compile with the embedded WASM
|
|
101
|
+
// deno compile --allow-read --include taglib.wasm myapp.ts
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
For manual control:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// Load embedded WASM in compiled binaries
|
|
108
|
+
const wasmBinary = await Deno.readFile(new URL("./taglib.wasm", import.meta.url));
|
|
109
|
+
const taglib = await TagLib.initialize({ wasmBinary });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## π Quick Start
|
|
113
|
+
|
|
114
|
+
### Simple API
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { applyTags, readTags, updateTags } from "taglib-wasm/simple";
|
|
118
|
+
|
|
119
|
+
// Read tags - just one function call!
|
|
120
|
+
const tags = await readTags("song.mp3");
|
|
121
|
+
console.log(tags.title, tags.artist, tags.album);
|
|
122
|
+
|
|
123
|
+
// Apply tags and get modified buffer (in-memory)
|
|
124
|
+
const modifiedBuffer = await applyTags("song.mp3", {
|
|
125
|
+
title: "New Title",
|
|
126
|
+
artist: "New Artist",
|
|
127
|
+
album: "New Album",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Or update tags on disk (requires file path)
|
|
131
|
+
await updateTags("song.mp3", {
|
|
132
|
+
title: "New Title",
|
|
133
|
+
artist: "New Artist",
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Core API
|
|
138
|
+
|
|
139
|
+
The full Core API might be a better choice for apps and utilities focused on
|
|
140
|
+
advanced metadata management.
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { TagLib } from "taglib-wasm";
|
|
144
|
+
|
|
145
|
+
// Initialize taglib-wasm
|
|
146
|
+
const taglib = await TagLib.initialize();
|
|
147
|
+
|
|
148
|
+
// Load audio file
|
|
149
|
+
const file = await taglib.open("song.mp3");
|
|
150
|
+
|
|
151
|
+
// Read and update metadata
|
|
152
|
+
const tag = file.tag();
|
|
153
|
+
tag.setTitle("New Title");
|
|
154
|
+
tag.setArtist("New Artist");
|
|
155
|
+
|
|
156
|
+
// Save changes
|
|
157
|
+
file.save();
|
|
158
|
+
|
|
159
|
+
// Clean up
|
|
160
|
+
file.dispose();
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Working with Cover Art
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { getCoverArt, setCoverArt } from "taglib-wasm/simple";
|
|
167
|
+
|
|
168
|
+
// Extract cover art
|
|
169
|
+
const coverData = await getCoverArt("song.mp3");
|
|
170
|
+
if (coverData) {
|
|
171
|
+
await Deno.writeFile("cover.jpg", coverData);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Set new cover art
|
|
175
|
+
const imageData = await Deno.readFile("new-cover.jpg");
|
|
176
|
+
const modifiedBuffer = await setCoverArt("song.mp3", imageData, "image/jpeg");
|
|
177
|
+
// Save modifiedBuffer to file if needed
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Codec Detection and Audio Properties
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { readProperties } from "taglib-wasm/simple";
|
|
184
|
+
|
|
185
|
+
// Get detailed audio properties including codec info
|
|
186
|
+
const props = await readProperties("song.m4a");
|
|
187
|
+
|
|
188
|
+
console.log(props.codec); // "AAC" or "ALAC"
|
|
189
|
+
console.log(props.isLossless); // false for AAC, true for ALAC
|
|
190
|
+
console.log(props.bitsPerSample); // 16 for most formats
|
|
191
|
+
console.log(props.bitrate); // 256 (kbps)
|
|
192
|
+
console.log(props.sampleRate); // 44100 (Hz)
|
|
193
|
+
console.log(props.length); // 180 (duration in seconds)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Supported codec detection:
|
|
197
|
+
|
|
198
|
+
- **MP3** β Returns "MP3" (lossy)
|
|
199
|
+
- **M4A/MP4** β Distinguishes between "AAC" (lossy) and "ALAC" (lossless)
|
|
200
|
+
- **FLAC** β Returns "FLAC" (lossless)
|
|
201
|
+
- **OGG** β Returns "Vorbis" (lossy) or "Opus" (lossy)
|
|
202
|
+
- **WAV** β Returns "PCM" (uncompressed)
|
|
203
|
+
|
|
204
|
+
## π Documentation
|
|
205
|
+
|
|
206
|
+
**[π View Full Documentation](https://charleswiltgen.github.io/taglib-wasm/)**
|
|
207
|
+
|
|
208
|
+
### Getting Started
|
|
209
|
+
|
|
210
|
+
- [Installation Guide](https://charleswiltgen.github.io/taglib-wasm/guide/installation.html)
|
|
211
|
+
- [Quick Start Tutorial](https://charleswiltgen.github.io/taglib-wasm/guide/quick-start.html)
|
|
212
|
+
- [All Examples](https://charleswiltgen.github.io/taglib-wasm/guide/examples.html)
|
|
213
|
+
|
|
214
|
+
### Guides
|
|
215
|
+
|
|
216
|
+
- [API Reference](https://charleswiltgen.github.io/taglib-wasm/API.html)
|
|
217
|
+
- [Platform Examples](https://charleswiltgen.github.io/taglib-wasm/guide/platform-examples.html)
|
|
218
|
+
- [Working with Cover Art](https://charleswiltgen.github.io/taglib-wasm/guide/cover-art.html)
|
|
219
|
+
- [Cloudflare Workers Setup](https://charleswiltgen.github.io/taglib-wasm/guide/workers-setup.html)
|
|
220
|
+
- [Error Handling](https://charleswiltgen.github.io/taglib-wasm/Error-Handling.html)
|
|
221
|
+
|
|
222
|
+
### Development
|
|
223
|
+
|
|
224
|
+
- [Testing Guide](https://charleswiltgen.github.io/taglib-wasm/development/testing.html)
|
|
225
|
+
- [Future Improvements](https://charleswiltgen.github.io/taglib-wasm/development/improvements.html)
|
|
226
|
+
- [Contributing](https://charleswiltgen.github.io/taglib-wasm/CONTRIBUTING.html)
|
|
227
|
+
|
|
228
|
+
## π Supported Formats
|
|
229
|
+
|
|
230
|
+
`taglib-wasm` is designed to support all formats supported by TagLib:
|
|
231
|
+
|
|
232
|
+
- β
**.mp3** β ID3v2 and ID3v1 tags
|
|
233
|
+
- β
**.m4a/.mp4** β MPEG-4/AAC metadata for AAC and Apple Lossless audio
|
|
234
|
+
- β
**.flac** β Vorbis comments and audio properties
|
|
235
|
+
- β
**.ogg** β Ogg Vorbis format with full metadata support
|
|
236
|
+
- β
**.wav** β INFO chunk metadata
|
|
237
|
+
- β
**Additional formats** β Opus, APE, MPC, WavPack, TrueAudio, AIFF, WMA, and
|
|
238
|
+
more
|
|
239
|
+
|
|
240
|
+
## π― Key Features
|
|
241
|
+
|
|
242
|
+
### Extended Metadata Support
|
|
243
|
+
|
|
244
|
+
Beyond basic tags, taglib-wasm supports extended metadata:
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { Tags } from "taglib-wasm";
|
|
248
|
+
|
|
249
|
+
// AcoustID fingerprints
|
|
250
|
+
file.setProperty(
|
|
251
|
+
Tags.AcoustidFingerprint,
|
|
252
|
+
"AQADtMmybfGO8NCNEESLnzHyXNOHeHnG...",
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// MusicBrainz IDs
|
|
256
|
+
file.setProperty(
|
|
257
|
+
Tags.MusicBrainzTrackId,
|
|
258
|
+
"f4d1b6b8-8c1e-4d9a-9f2a-1234567890ab",
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
// ReplayGain volume normalization
|
|
262
|
+
file.setProperty(Tags.TrackGain, "-6.54 dB");
|
|
263
|
+
file.setProperty(Tags.TrackPeak, "0.987654");
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
[View all supported tag constants β](https://charleswiltgen.github.io/taglib-wasm/Tag-Name-Constants.html)
|
|
267
|
+
|
|
268
|
+
## ποΈ Development
|
|
269
|
+
|
|
270
|
+
### Build from Source
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Prerequisites: Emscripten SDK
|
|
274
|
+
# Install via: https://emscripten.org/docs/getting_started/downloads.html
|
|
275
|
+
|
|
276
|
+
# Clone and build
|
|
277
|
+
git clone https://github.com/CharlesWiltgen/taglib-wasm.git
|
|
278
|
+
cd taglib-wasm
|
|
279
|
+
|
|
280
|
+
# Build Wasm module
|
|
281
|
+
npm run build:wasm
|
|
282
|
+
|
|
283
|
+
# Run tests
|
|
284
|
+
npm test
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
[View full development guide β](CONTRIBUTING.md)
|
|
288
|
+
|
|
289
|
+
## π Runtime Compatibility
|
|
290
|
+
|
|
291
|
+
`taglib-wasm` works across all major JavaScript runtimes:
|
|
292
|
+
|
|
293
|
+
| Runtime | Status | Installation | Notes |
|
|
294
|
+
| ---------------------- | ------- | ------------------------- | ------------------------- |
|
|
295
|
+
| **Deno** | β
Full | `npm:taglib-wasm` | Native TypeScript |
|
|
296
|
+
| **Node.js** | β
Full | `npm install taglib-wasm` | TypeScript via tsx |
|
|
297
|
+
| **Bun** | β
Full | `bun add taglib-wasm` | Native TypeScript |
|
|
298
|
+
| **Browser** | β
Full | Via bundler | Full API support |
|
|
299
|
+
| **Cloudflare Workers** | β
Full | `taglib-wasm/workers` | Memory-optimized build |
|
|
300
|
+
| **Electron** | β
Full | `npm install taglib-wasm` | Main & renderer processes |
|
|
301
|
+
|
|
302
|
+
## π§ Known Limitations
|
|
303
|
+
|
|
304
|
+
- **Memory Usage** β Entire file must be loaded into memory (may be an issue for
|
|
305
|
+
very large files)
|
|
306
|
+
- **Concurrent Access** β Not thread-safe (JavaScript single-threaded nature
|
|
307
|
+
mitigates this)
|
|
308
|
+
- **Cloudflare Workers** β Limited to 128MB memory per request; files larger
|
|
309
|
+
than ~100MB may fail
|
|
310
|
+
|
|
311
|
+
## π€ Contributing
|
|
312
|
+
|
|
313
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md)
|
|
314
|
+
for details on our code of conduct and the process for submitting pull requests.
|
|
315
|
+
|
|
316
|
+
## π License
|
|
317
|
+
|
|
318
|
+
This project uses dual licensing:
|
|
319
|
+
|
|
320
|
+
- **TypeScript/JavaScript code** β MIT License (see [LICENSE](LICENSE))
|
|
321
|
+
- **WebAssembly binary (taglib.wasm)** β LGPL-2.1-or-later (inherited from
|
|
322
|
+
TagLib)
|
|
323
|
+
|
|
324
|
+
The TagLib library is dual-licensed under LGPL/MPL. When compiled to
|
|
325
|
+
WebAssembly, the resulting binary must comply with LGPL requirements. This
|
|
326
|
+
means:
|
|
327
|
+
|
|
328
|
+
- You can use taglib-wasm in commercial projects
|
|
329
|
+
- If you modify the TagLib C++ code, you must share those changes
|
|
330
|
+
- You must provide a way for users to relink with a modified TagLib
|
|
331
|
+
|
|
332
|
+
For details, see [lib/taglib/COPYING.LGPL](lib/taglib/COPYING.LGPL)
|
|
333
|
+
|
|
334
|
+
## π Acknowledgments
|
|
335
|
+
|
|
336
|
+
- [TagLib](https://taglib.org/) β Excellent audio metadata library
|
|
337
|
+
- [Emscripten](https://emscripten.org/) β WebAssembly compilation toolchain
|
package/package.json
CHANGED