UNPKG

7.13 kBMarkdownView Raw
1# node-id3
2
3node-id3 is an ID3-Tag library written in JavaScript.
4
5## Installation
6```
7npm install node-id3
8```
9
10## Usage
11
12```javascript
13const NodeID3 = require('node-id3')
14
15/* Variables found in the following usage examples */
16
17const filebuffer = new Buffer("Some Buffer of a (mp3) file")
18const filepath = './path/to/(mp3)file'
19
20const tags = {
21 title: "Tomorrow",
22 artist: "Kevin Penkin",
23 album: "TVアニメ「メイドインアビス」オリジナルサウンドトラック",
24 APIC: "./example/mia_cover.jpg",
25 TRCK: "27"
26}
27```
28
29### Write tags to file
30```javascript
31const success = NodeID3.write(tags, filepath) // Returns true/Error
32// async version
33NodeID3.write(tags, file, function(err) { })
34```
35
36### Write tags to filebuffer
37```javascript
38const success = NodeID3.write(tags, filebuffer) // Returns Buffer
39// async version
40NodeID3.write(tags, file, function(err, buffer) { })
41```
42
43### Update existing tags of file or buffer
44This will write new/changed values but keep all others
45```javascript
46const success = NodeID3.update(tags, filepath) // Returns true/Error
47const success = NodeID3.update(tags, filebuffer) // Returns Buffer
48NodeID3.update(tags, filepath, function(err, buffer) { })
49NodeID3.update(tags, filebuffer, function(err, buffer) { })
50```
51
52### Create tags as buffer
53```javascript
54const success = NodeID3.create(tags) // Returns ID3-Tag Buffer
55// async version
56NodeID3.create(tags, function(buffer) { })
57```
58
59### Reading ID3-Tags
60
61```javascript
62const tags = NodeID3.read(file)
63NodeID3.read(file, function(err, tags) {})
64/*
65 tags: {
66 title: "Tomorrow",
67 artist: "Kevin Penkin",
68 image: {
69 mime: "jpeg",
70 type: {
71 id: 3,
72 name: "front cover"
73 },
74 description: String,
75 imageBuffer: Buffer
76 },
77 raw: {
78 TIT2: "Tomorrow",
79 TPE1: "Kevin Penkin",
80 APIC: Object (See above)
81 }
82 }
83*/
84
85// Possible options
86const options = {
87 include: ['TALB', 'TIT2'], // only read the specified tags (default: all)
88 exclude: ['APIC'], // don't read the specified tags (default: [])
89 onlyRaw: false, // only return raw object (default: false)
90 noRaw: false // don't generate raw object (default: false)
91}
92const tags = NodeID3.read(file, options)
93```
94
95### Removing ID3-Tags from file/buffer
96
97```javascript
98const success = NodeID3.removeTags(filepath) // returns true/Error
99NodeID3.removeTags(filepath, function(err) { })
100
101let bufferWithoutID3Frame = NodeID3.removeTagsFromBuffer(filebuffer) // Returns Buffer
102```
103
104### Using Promises (available starting with v0.2)
105
106```javascript
107const NodeID3Promise = require('node-id3').Promise
108
109NodeID3.write(tags, fileOrBuffer)
110NodeID3.update(tags, fileOrBuffer)
111NodeID3.create(tags)
112NodeID3.read(filepath)
113NodeID3.removeTags(filepath)
114```
115
116## Supported aliases/fields
117```
118album:
119bpm:
120composer:
121genre:
122copyright:
123date:
124playlistDelay:
125encodedBy:
126textWriter:
127fileType:
128time:
129contentGroup:
130title:
131subtitle:
132initialKey:
133language:
134length:
135mediaType:
136originalTitle:
137originalFilename:
138originalTextwriter:
139originalArtist:
140originalYear:
141fileOwner:
142artist:
143performerInfo:
144conductor:
145remixArtist:
146partOfSet:
147publisher:
148trackNumber:
149recordingDates:
150internetRadioName:
151internetRadioOwner:
152size:
153ISRC:
154encodingTechnology:
155year:
156comment: {
157 language: "eng",
158 text: "mycomment"
159}
160unsynchronisedLyrics: {
161 language: "eng",
162 text: "lyrics"
163}
164userDefinedText: [{
165 description: "txxx name",
166 value: "TXXX value text"
167}, {
168 description: "txxx name 2",
169 value: "TXXX value text 2"
170}] // Care, update doesn't delete non-passed array items!
171image: {
172 mime: "png/jpeg"/undefined,
173 type: {
174 id: 3,
175 name: "front cover
176 }, // See https://en.wikipedia.org/wiki/ID3#ID3v2_embedded_image_extension
177 description: "image description",
178 imageBuffer: (file buffer)
179},
180popularimeter: {
181 email: "mail@example.com",
182 rating: 192, // 1-255
183 counter: 12
184},
185private: [{
186 ownerIdentifier: "AbC",
187 data: "asdoahwdiohawdaw"
188}, {
189 ownerIdentifier: "AbCSSS",
190 data: Buffer.from([0x01, 0x02, 0x05])
191}],
192chapter: [{
193 elementID: "Hey!", // THIS MUST BE UNIQUE!
194 startTimeMs: 5000,
195 endTimeMs: 8000,
196 startOffsetBytes: 123, // OPTIONAL!
197 endOffsetBytes: 456, // OPTIONAL!
198 tags: { // OPTIONAL
199 title: "abcdef",
200 artist: "akshdas"
201 }
202}],
203tableOfContents: [{
204 elementID: "toc1", // THIS MUST BE UNIQUE!
205 isOrdered: false, // OPTIONAL, tells a player etc. if elements are in a specific order
206 elements: ['chap1'], // OPTIONAL but most likely needed, contains the chapter/tableOfContents elementIDs
207 tags: { // OPTIONAL
208 title: "abcdef"
209 }
210}],
211commercialUrl: ["commercialurl.com"], // array or single string
212copyrightUrl: "example.com",
213fileUrl: "example.com",
214artistUrl: ["example.com"], // array or single string
215audioSourceUrl: "example.com",
216radioStationUrl: "example.com",
217paymentUrl: "example.com",
218publisherUrl: "example.com",
219userDefinedUrl: [{
220 description: "URL description"
221 url: "https://example.com/"
222}] // array or single object
223```
224
225### Supported raw IDs
226You can also use the currently supported raw tags like TALB instead of album etc.
227```
228album: "TALB"
229bpm: "TBPM"
230composer: "TCOM"
231genre: "TCON"
232copyright: "TCOP"
233date: "TDAT"
234playlistDelay: "TDLY"
235encodedBy: "TENC"
236textWriter: "TEXT"
237fileType: "TFLT"
238time: "TIME"
239contentGroup: "TIT1"
240title: "TIT2"
241subtitle: "TIT3"
242initialKey: "TKEY"
243language: "TLAN"
244length: "TLEN"
245mediaType: "TMED"
246originalTitle: "TOAL"
247originalFilename: "TOFN"
248originalTextwriter: "TOLY"
249originalArtist: "TOPE"
250originalYear: "TORY"
251fileOwner: "TOWN"
252artist: "TPE1"
253performerInfo: "TPE2"
254conductor: "TPE3"
255remixArtist: "TPE4"
256partOfSet: "TPOS"
257publisher: "TPUB"
258trackNumber: "TRCK"
259recordingDates: "TRDA"
260internetRadioName: "TRSN"
261internetRadioOwner: "TRSO"
262size: "TSIZ"
263ISRC: "TSRC"
264encodingTechnology: "TSSE"
265year: "TYER"
266comment: "COMM"
267image: "APIC"
268unsynchronisedLyrics "USLT"
269userDefinedText "TXXX"
270popularimeter "POPM"
271private "PRIV"
272chapter "CHAP"
273tableOfContents "CTOC"
274commercialUrl "WCOM"
275copyrightUrl "WCOP"
276fileUrl "WOAF"
277artistUrl "WOAR"
278audioSourceUrl "WOAS"
279radioStationUrl "WORS"
280paymentUrl "WPAY"
281publisherUrl "WPUB"
282userDefinedUrl "WXXX"
283```