This library is not a complete implementation for all ID3 tags. It has basic support for the most common v2.3 and v2.4 features. More advanced features, like frame encryption are not yet supported.
Detailed information about the meaning of certain frame fields/flags can be found in the file format reference at: http://id3.org/id3v2.3.0
Check out retagger for an example project on how to use this library.
Installation:
npm install -g mp3tag
Help command:
mp3tag --help
Printing out the most common tags and an overview of the available tags:
mp3tag --in "./input.mp3" --show-data
Saving the cover image into a file:
If no fileName
is provided then the file is exported as cover.png
or cover.jpeg
depending on the cover's MIME type.
mp3tag --in "./input.mp3" --export-cover [fileName]
Setting a new album and writing the changes into a new file:
If no output file is provided, the changes are written back into the input file. If possible without rewriting the whole file (if the file has a padding area).
mp3tag --in "./input.mp3" --set-album "test" --write "./output.mp3"
Install dependency:
npm install --save mp3tag
Code example:
const mp3tag = require('mp3tag');
const tagData = await mp3tag.readHeader('./file.mp3');
const buffer = tagData.getFrameBuffer('TALB');
if (buffer) {
console.log("Album: " + tagData.decoder.decodeString(buffer));
} else {
console.log("No album frame");
}
Reads in the source file at the specified path and returns a promise, which resolves to the parsed TagData
object.
All frames are loaded into memory when constructing this object so that the frame content can be read/written without performing any File-IO.
Returns the Decoder
object, which can be used to decode/encode the binary frame buffers.
If the parsed file contains a frame with the given id
then it is returned. When accessing the Frame's content, getFrameBuffer()
/setFrameBuffer()
should be used instead.
Returns all frames, which have the given frame id. (A mp3 file may contain multiple frames with the same id)
Directly returns the frame content as Buffer
. The frame's buffer should only be modified using setFrameBuffer()
to ensure proper frame alignment.
The binary frame content of text frames can be decoded as follows:
tagData.decoder.decodeString(buffer)
Same as getFrameBuffer()
but may return multiple Buffer
objects if there are multiple Frames with the same id
.
Assigns the given Buffer
object as the frame's new content. The frame will be created if the has no such frame and the frame will be resized to fit the passed buffer. The buffer is only assigend by reference and not copied, so modifying the assigned buffer will modify the frame's content.
Removes all frames with the given id
.
Loads the whole audio data from the file into a Buffer
and returns a promise, which resolves to this buffer.
Writes all changes back into the source file. When writing back the changes, the file's padding area resized to accomodate all changes without rewriting the audio data if possible.
Writes the change frames and audio data into the specified file.
Decodes the content of text frames. The buffer's first byte specifies the used buffer encoding and the remaining bytes are treated as string content.
Ids of text frames typically start with T
(eg. TALB
)
The decoded comment object contains three string properties: {language,short,long}
The comment is stored in the COMM
frame.
Encodes a comment object back into a buffer.
The decoded popularity object has the following fields:
-
email:string
- The user's email -
rating:number
- Rating value [0-255] -
playCount:number
- Number of times this has been played.
The popularity object is stored in the POPM
frame.
The decoded picture object contains the following properties:
mimeType:string
-
pictureType:number
- 0x3 = cover picture description:string
-
pictureData:Data
- a reference to the picture's data, which is basically aBuffer
wrapper. The buffer can be retrieved by callingtoBuffer()
on it.
The picture is stored in the APIC
frame.
Encodes a given picture data (see above) into a buffer to be written into an APIC
frame.