Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@mattbasta/browser-id3-writer
Advanced tools
Pure JS library for writing ID3 tag to MP3 files in browsers and Node.js
Pure JS library for writing ID3 (v2.3) tag to MP3 files in browsers and Node.js. It can't read the tag so use another lib to do it.
Note: the library removes existing ID3 tag (v2.2, v2.3 and v2.4).
Works in Node.js 4+, IE10+ and all modern browsers.
Here is an online demonstration: egoroof.ru/browser-id3-writer/
For browsers you can include library via unpkg CDN (2.5 KiB gzip) or save it to local machine:
<script src="https://unpkg.com/browser-id3-writer@3.0.8" crossorigin="anonymous" integrity="sha384-Vu4x2MLn2tvsjtNzj/QUzhEV40nh0LVOOfbAyPiFuskxPbR4242zDbI2F1PAl+i1"></script>
For Node.js and browser module loaders like webpack
, browserify
, etc. install it via npm:
npm install browser-id3-writer --save
Then you will be able to use it:
const ID3Writer = require('browser-id3-writer');
You should first get ArrayBuffer of the song you would like to add ID3 tag.
For example you can create file input and use FileReader:
<input type="file" id="file" accept="audio/mpeg">
<script>
document.getElementById('file').addEventListener('change', function () {
if (!this.files.length) {
return;
}
const reader = new FileReader();
reader.onload = function () {
const arrayBuffer = reader.result;
// go next
};
reader.onerror = function () {
// handle error
console.error('Reader error', reader.error);
};
reader.readAsArrayBuffer(this.files[0]);
});
</script>
To get arrayBuffer from remote server you can use XMLHttpRequest:
const xhr = new XMLHttpRequest();
xhr.open('GET', urlToSongFile, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (xhr.status === 200) {
const arrayBuffer = xhr.response;
// go next
} else {
// handle error
console.error(xhr.statusText + ' (' + xhr.status + ')');
}
};
xhr.onerror = function() {
// handle error
console.error('Network error');
};
xhr.send();
Create new ID3Writer
instance with arrayBuffer of your song, set frames and add a tag:
// arrayBuffer of song or empty arrayBuffer if you just want only id3 tag without song
const writer = new ID3Writer(arrayBuffer);
writer.setFrame('TIT2', 'Home')
.setFrame('TPE1', ['Eminem', '50 Cent'])
.setFrame('TALB', 'Friday Night Lights')
.setFrame('TYER', 2004)
.setFrame('TRCK', '6/8')
.setFrame('TCON', ['Soundtrack'])
.setFrame('TBPM', 128)
.setFrame('WPAY', 'https://google.com')
.setFrame('TKEY', 'Fbm')
.setFrame('APIC', {
type: 3,
data: coverArrayBuffer,
description: 'Super picture'
});
writer.addTag();
Now you can save it to file as you want:
const taggedSongBuffer = writer.arrayBuffer;
const blob = writer.getBlob();
const url = writer.getURL();
For example you can save file using FileSaver.js:
saveAs(blob, 'song with tags.mp3');
If you are writing chromium extension you can save file using Downloads API:
chrome.downloads.download({
url: url,
filename: 'song with tags.mp3'
});
When you generate URLs via writer.getURL()
you should know
that whole file is kept in memory until you close the page or move to another one.
So if you generate lots of URLs in a single page you should manually free memory
after you finish downloading file:
URL.revokeObjectURL(url); // if you know url or
writer.revokeURL(); // if you have access to writer
Simple example with blocking IO:
const ID3Writer = require('browser-id3-writer');
const fs = require('fs');
const songBuffer = fs.readFileSync('path_to_song.mp3');
const coverBuffer = fs.readFileSync('path_to_cover.jpg');
const writer = new ID3Writer(songBuffer);
writer.setFrame('TIT2', 'Home')
.setFrame('TPE1', ['Eminem', '50 Cent'])
.setFrame('TALB', 'Friday Night Lights')
.setFrame('TYER', 2004)
.setFrame('APIC', {
type: 3,
data: coverBuffer,
description: 'Super picture'
});
writer.addTag();
const taggedSongBuffer = Buffer.from(writer.arrayBuffer);
fs.writeFileSync('song_with_tags.mp3', taggedSongBuffer);
You can also create only ID3 tag without song and use it as you want:
const writer = new ID3Writer(Buffer.alloc(0));
writer.padding = 0; // default 4096
writer.setFrame('TIT2', 'Home');
writer.addTag();
const id3Buffer = Buffer.from(writer.arrayBuffer);
Have not found needed frame? Open a new issue and we'll discuss it.
array of strings:
string
integer
object
writer.setFrame('COMM', {
description: 'description here',
text: 'text here'
});
writer.setFrame('USLT', {
description: 'description here',
lyrics: 'lyrics here'
});
writer.setFrame('TXXX', {
description: 'description here',
value: 'value here'
});
writer.setFrame('APIC', {
type: 3,
data: coverArrayBuffer,
description: 'description here'
});
Type | Name |
---|---|
0 | Other |
1 | 32x32 pixels 'file icon' (PNG only) |
2 | Other file icon |
3 | Cover (front) |
4 | Cover (back) |
5 | Leaflet page |
6 | Media (e.g. lable side of CD) |
7 | Lead artist/lead performer/soloist |
8 | Artist/performer |
9 | Conductor |
10 | Band/Orchestra |
11 | Composer |
12 | Lyricist/text writer |
13 | Recording Location |
14 | During recording |
15 | During performance |
16 | Movie/video screen capture |
17 | A bright coloured fish |
18 | Illustration |
19 | Band/artist logotype |
20 | Publisher/Studio logotype |
FAQs
Pure JS library for writing ID3 tag to MP3 files in browsers and Node.js
The npm package @mattbasta/browser-id3-writer receives a total of 1 weekly downloads. As such, @mattbasta/browser-id3-writer popularity was classified as not popular.
We found that @mattbasta/browser-id3-writer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.