import jamp3 from "jamp3"; import { readFileSync } from "node:fs"; async function run() { const id3v2 = new jamp3.ID3v2(); const filename = "demo.mp3"; // Read the existing tag const existingTag = await id3v2.read(filename); // Initialize the builder from the existing tag to preserve all frames const builder = new jamp3.ID3V24TagBuilder(); if (existingTag) { builder.loadTag(existingTag); } // Single-value frames (title, artist, …) are replaced by their setter. // Multi-value frames (picture, comment, …) are appended — use the // matching clear…() method first when you want to replace them. const coverBuffer = readFileSync("cover.jpg"); builder .title("Updated title") .artist("Updated artist") .clearPictures() // remove existing artwork .picture(3, "", "image/jpeg", coverBuffer); // attach new artwork const options = { keepBackup: true, // keep a filename.mp3.bak copy of the original file paddingSize: 10 // add padding zeros between id3v2 and the audio (in bytes) }; await id3v2.writeBuilder(filename, builder, options); console.log("id3v2.4 updated"); } run().catch(console.error);