Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

node-id3

Zazama258.6kMIT0.2.9TypeScript support: included

Pure JavaScript ID3v2 Tag writer and reader

ID3, ID3v2, metadata, tags, mp3, audio, music

readme

node-id3

GitHub package.json version Travis (.org) Codecov Code Climate maintainability npm

node-id3 is an ID3-Tag library written in JavaScript.

Installation

npm install node-id3

Usage

const NodeID3 = require('node-id3')

/* Variables found in the following usage examples */

const filebuffer = Buffer.from("Some Buffer of a (mp3) file")
const filepath = './path/to/(mp3)file'

const tags = {
    title: "Tomorrow",
    artist: "Kevin Penkin",
    album: "TVアニメ「メイドインアビス」オリジナルサウンドトラック",
    APIC: "./example/mia_cover.jpg",
    TRCK: "27"
}

Write tags to file

If you have an existing file/buffer (e.g. an mp3 file) you can use the write method to write your tags into it. It will remove existing tags and add yours.

const success = NodeID3.write(tags, filepath) // Returns true/Error
// async version
NodeID3.write(tags, file, function(err) {  })

Write tags to filebuffer

const success = NodeID3.write(tags, filebuffer) // Returns Buffer
// async version
NodeID3.write(tags, file, function(err, buffer) {  })

Update existing tags of file or buffer

The update method works like the write method but will keep or overwrite existing tags instead of removing them.

const success = NodeID3.update(tags, filepath) //  Returns true/Error
const success = NodeID3.update(tags, filebuffer) //  Returns Buffer
NodeID3.update(tags, filepath, function(err, buffer) {  })
NodeID3.update(tags, filebuffer, function(err, buffer) {  })

// Possible options
const options = {
    include: ['TALB', 'TIT2'],    // only read the specified tags (default: all)
    exclude: ['APIC']            // don't read the specified tags (default: [])
}

NodeID3.update(tags, filepath, options)
const success = NodeID3.update(tags, filebuffer, options)
NodeID3.update(tags, filepath, options, function(err, buffer) {  })
NodeID3.update(tags, filebuffer, options, function(err, buffer) {  })

Create tags as buffer

The create method will return a buffer of your ID3-Tag. You can use it to e.g. write it into a file yourself instead of using the write method.

const success = NodeID3.create(tags) // Returns ID3-Tag Buffer
// async version
NodeID3.create(tags, function(buffer) {  })

Reading ID3-Tags

const tags = NodeID3.read(file)
NodeID3.read(file, function(err, tags) {})
/*
    tags: {
        title: "Tomorrow",
        artist: "Kevin Penkin",
        image: {
          mime: "image/jpeg",
          type: {
            id: 3,
            name: "front cover"
          },
          description: String,
          imageBuffer: Buffer
        },
        raw: {
          TIT2: "Tomorrow",
          TPE1: "Kevin Penkin",
          APIC: Object (See above)
        }
      }
*/

// Possible options
const options = {
    include: ['TALB', 'TIT2'],    // only read the specified tags (default: all)
    exclude: ['APIC'],            // don't read the specified tags (default: [])
    onlyRaw: false,               // only return raw object (default: false)
    noRaw: false                  // don't generate raw object (default: false)
}
const tags = NodeID3.read(file, options)

Removing ID3-Tags from file/buffer

const success = NodeID3.removeTags(filepath)  //  returns true/Error
NodeID3.removeTags(filepath, function(err) {  })

let bufferWithoutID3Frame = NodeID3.removeTagsFromBuffer(filebuffer)  //  Returns Buffer

Using Promises (available starting with v0.2)

const NodeID3Promise = require('node-id3').Promise

NodeID3.write(tags, fileOrBuffer)
NodeID3.update(tags, fileOrBuffer)
NodeID3.create(tags)
NodeID3.read(filepath)
NodeID3.removeTags(filepath)

Supported aliases/fields

album:
bpm:
composer:
genre:
copyright:
encodingTime:
date:
playlistDelay:
originalReleaseTime:
recordingTime:
releaseTime:
taggingTime:
encodedBy:
textWriter:
fileType:
involvedPeopleList:
time:
contentGroup:
title:
subtitle:
initialKey:
language:
length:
musicianCreditsList:
mediaType:
mood:
originalTitle:
originalFilename:
originalTextwriter:
originalArtist:
originalYear:
fileOwner:
artist:
performerInfo: // (album artist)
conductor:
remixArtist:
partOfSet:
producedNotice:
publisher:
trackNumber:
recordingDates:
internetRadioName:
internetRadioOwner:
albumSortOrder:
performerSortOrder:
titleSortOrder:
size:
ISRC:
encodingTechnology:
setSubtitle:
year:
comment: {
  language: "eng",
  text: "mycomment"
}
unsynchronisedLyrics: {
  language: "eng",
  text: "lyrics"
}
// See https://id3.org/ documentation for more details.
synchronisedLyrics: [{
  language: "eng",
  timeStampFormat: TagConstants.TimeStampFormat.MILLISECONDS,
  contentType: TagConstants.SynchronisedLyrics.ContentType.LYRICS,
  shortText: "Content descriptor",
  synchronisedText: [{
    text: "part 1",
    timeStamp: 0 // Must be a positive integer value
  }, {
    text: "part 2",
    timeStamp: 1000 // Must be a positive integer value
  }]
}]
userDefinedText: [{
  description: "txxx name",
  value: "TXXX value text"
}, {
  description: "txxx name 2",
  value: "TXXX value text 2"
}] // Care, update doesn't delete non-passed array items!
image: {
  mime: "image/png",
  type: {
    id: TagConstants.AttachedPicture.PictureType.FRONT_COVER
  }, // See https://en.wikipedia.org/wiki/ID3#ID3v2_embedded_image_extension
  description: "image description",
  imageBuffer: (file buffer)
},
popularimeter: {
  email: "mail@example.com",
  rating: 192,  // 1-255
  counter: 12
},
private: [{
  ownerIdentifier: "AbC",
  data: "asdoahwdiohawdaw"
}, {
  ownerIdentifier: "AbCSSS",
  data: Buffer.from([0x01, 0x02, 0x05])
}],
uniqueFileIdentifier: [{
  ownerIdentifier: "owner-id-1",
  identifier: Buffer.from("identifier-1")
}], {
  ownerIdentifier: "owner-id-2",
  identifier: Buffer.from("identifier-2")
},
chapter: [{
  elementID: "Hey!", // THIS MUST BE UNIQUE!
  startTimeMs: 5000,
  endTimeMs: 8000,
  startOffsetBytes: 123, // OPTIONAL!
  endOffsetBytes: 456,   // OPTIONAL!
  tags: {                // OPTIONAL
    title: "abcdef",
    artist: "akshdas"
  }
}],
tableOfContents: [{
  elementID: "toc1",    // THIS MUST BE UNIQUE!
  isOrdered: false,     // OPTIONAL, tells a player etc. if elements are in a specific order
  elements: ['chap1'],  // OPTIONAL but most likely needed, contains the chapter/tableOfContents elementIDs
  tags: {               // OPTIONAL
    title: "abcdef"
  }
}],
commercialUrl: ["commercialurl.com"], // array or single string
copyrightUrl: "example.com",
fileUrl: "example.com",
artistUrl: ["example.com"], // array or single string
audioSourceUrl: "example.com",
radioStationUrl: "example.com",
paymentUrl: "example.com",
publisherUrl: "example.com",
userDefinedUrl: [{
  description: "URL description"
  url: "https://example.com/"
}], // array or single object
eventTimingCodes: {
  timeStampFormat: TagConstants.TimeStampFormat.MILLISECONDS,
  keyEvents: [{
    type: TagConstants.EventTimingCodes.EventType.INTRO_START,
    timeStamp: 1000 // Must be a positive integer value
  }]
},
commercialFrame: [{
  prices: {
    'EUR': 15,
    'DKK': 17.922
  },
  validUntil: { year: 2023, month: 9, day: 1},
  contactUrl: 'https://example.com',
  receivedAs: TagConstants.CommercialFrame.ReceivedAs.OTHER,
  nameOfSeller: 'Someone',
  description: 'Something',
  sellerLogo: {
    mimeType: 'image/',
    picture: Buffer.alloc(15, 0x13)
  }
}]
generalObject: [{
  mimeType: 'application/octet-stream',
  filename: 'filename',
  contentDescription: 'description',
  encapsulatedObject: Buffer.alloc(15, 0x13),
}]

Supported raw IDs

You can also use the currently supported raw tags like TALB instead of album etc.

album:                "TALB"
bpm:                  "TBPM"
composer:             "TCOM"
genre:                "TCON"
copyright:            "TCOP"
date:                 "TDAT"
encodingTime:         "TDEN"
playlistDelay:        "TDLY"
originalReleaseTime:  "TDOR"
recordingTime:        "TDRC"
releaseTime:          "TDRL"
taggingTime:          "TDTG"
encodedBy:            "TENC"
textWriter:           "TEXT"
fileType:             "TFLT"
time:                 "TIME"
involvedPeopleList:   "TIPL"
contentGroup:         "TIT1"
title:                "TIT2"
subtitle:             "TIT3"
initialKey:           "TKEY"
language:             "TLAN"
length:               "TLEN"
musicianCreditsList:  "TMCL"
mediaType:            "TMED"
mood:                 "TMOO"
originalTitle:        "TOAL"
originalFilename:     "TOFN"
originalTextwriter:   "TOLY"
originalArtist:       "TOPE"
originalYear:         "TORY"
fileOwner:            "TOWN"
artist:               "TPE1"
performerInfo:        "TPE2"    (album artist)
conductor:            "TPE3"
remixArtist:          "TPE4"
partOfSet:            "TPOS"
producedNotice:       "TPRO"
publisher:            "TPUB"
trackNumber:          "TRCK"
recordingDates:       "TRDA"
internetRadioName:    "TRSN"
internetRadioOwner:   "TRSO"
size:                 "TSIZ"
albumSortOrder:       "TSOA"
performerSortOrder:   "TSOP"
titleSortOrder:       "TSOT"
ISRC:                 "TSRC"
encodingTechnology:   "TSSE"
setSubtitle:          "TSST"
year:                 "TYER"
comment:              "COMM"
image:                "APIC"
unsynchronisedLyrics  "USLT"
synchronisedLyrics    "SYLT"
userDefinedText       "TXXX"
popularimeter         "POPM"
private               "PRIV"
uniqueFileIdentifier  "UFID"
chapter               "CHAP"
tableOfContents       "CTOC"
commercialUrl         "WCOM"
copyrightUrl          "WCOP"
fileUrl               "WOAF"
artistUrl             "WOAR"
audioSourceUrl        "WOAS"
radioStationUrl       "WORS"
paymentUrl            "WPAY"
publisherUrl          "WPUB"
userDefinedUrl        "WXXX"
eventTimingCodes      "ETCO"
commercialFrame       "COMR"
generalObject         "GEOB"

changelog

Changelog

[0.2.9]

Fixed

  • Fix TXXX and PRIV tags from tuple to array in type file (by @pbricout)

[0.2.8]

Fixed

  • Make GEOB tag optional in type file (by @Nytrm)

[0.2.7] - 2025-02-04

Added

  • Add support for GEOB tag by @Nytrm

[0.2.6] - 2023-02-18

Fixed

  • Improve support for integer values
  • Fix splitting null terminated buffer

[0.2.5] - 2022-12-02

Added

  • Add ETCO and COMR frames
  • Add constants for usage in tags (by @pbricout)
  • Add ID3v2.4.0 text frames
  • Allow mixing of ID3v2.3.0 and ID3v2.4.0 frames

Changed

  • Internal refactor of code to simplify functions (by @pbricout)

Fixed

  • Frame compression is now handled correctly

[0.2.4] - 2022-11-09

  • Add synchronised lyrics (SYLT frame) (by @pbricout)

[0.2.3] - 2021-04-30

  • Don't change APIC mime type on read
  • Fix unsynchronisation implementation

[0.2.2] - 2021-01-01

Fixed

  • Bug in iTunes where artwork doesn't show up when description is empty
  • Creating tags with undefined, terminated UTF-16 value now passes FF FE 00 00 instead of 00 00
  • Add raw to TypeScript definition
  • Add removeTags async to TypeScript definition

Added

  • Added options to update

[0.2.1] - 2020-10-30

Fixed

  • Removed wrong import from TypeScript definition file
  • Added Promises to TypeScript definition file

[0.2.0] - 2020-10-26

Added

  • Tests & checks with jsmediatags to ensure more consistency
  • Support for UTF-8 & UTF-16LE
  • Promise versions of methods are available by calling require('node-id3').Promise
  • Exposed functions have JSDoc comments
  • Changelog
  • Pass options to .read (include, exclude, noRaw, onlyRaw)
  • Read unsynchronisation & dataLengthIndicator of frame header (v2.4.0)
  • Skip extended header if present

Changed

  • Frames are now build/read by a frame builder definition instead of the manual programmed way
  • Change the way definitions are saved to make code simpler
  • Internal functions are not exposed by index.js anymore
  • Change from exporting a function constructor to exporting every function itself

Fixed

  • async read function didn't return anything when buffer was passend

[0.1.21] - 2020-10-23

Fixed

  • Fix image reading for UTF16 descriptions

[0.1.20] - 2020-10-22

Added

  • Implemented CTOC frame

Fixed

  • Correctly write image description

[0.1.19] - 2020-09-25

Fixed

  • Pass Buffer.read32BE(0) optional argument
  • Fix TypeScript return type for text frames

[0.1.18] - 2020-07-30

Added

  • Add URL support

Fixed

  • Fix ID3v2.2 bug

[0.1.17] - 2020-06-01

Added

  • Add TypeScript annotation for chapter frame (by @pablobirukov)
  • Add URL frames support (WCOM, ..., WXXX) with TypeScript annotation (by @FelicitusNeko)

Changed

  • Set iconv-lite version to 0.5.1 (by @pablobirukov)

Fixed

  • Fix chapter starting at 0ms skipped bug (by @pablobirukov)
  • Pass Buffer offset argument required by node v10+ (by @pablobirukov)

[0.1.16] - 2020-03-22

Fixed

  • rename private var to _private

[0.1.15] - 2020-03-21

Added

  • Add chapters (CHAP frame)

[0.1.14] - 2020-03-02

Added

  • Add private frame

Fixed

  • Fix buffer index error

[0.1.13] - 2019-11-24

Added

  • Add popularimeter #56 thanks to @tiusnonos

[0.1.12] - 2019-11-04

Added

  • added basic ID3v2.2.0 support

Fixed

  • prevents buffer alloc from overflowing when frame body size is too big

[0.1.11] - 2019-08-01

Added

  • Add TXXX support

[0.1.8] - 2019-07-15

Changed

  • improve read speed performance by up to 10x

Fixed

  • fix variable leak

[0.1.7] - 2018-10-06

Fixed

  • fix read of apic description from breaking data

[0.1.6] - 2018-09-12

Fixed

  • fix wrong frame size for id3v2.4.0

[0.1.3] - 2018-02-07

Added

  • add unsynchronised lyrics

Changed

  • rearrange comment reading/writing

Fixed

  • use correct text encoding

[0.1.0] - 2017-10-11

Added

  • add create / update method
  • add async versions

Changed

  • more comments and improved code quality
  • better reading mechanism

[0.0.10] - 2017-08-06

Added

  • add ability to use raw tag names
  • add ability to use buffer containing an image instead of only a filepath

Fixed

  • fix problems with null characters

[0.0.9] - 2017-01-14

Added

  • Add image read support

Fixed

  • CRITICAL: Fix wrong implementation of tag sizes

[0.0.8] - 2017-01-12

Added

  • added comment tag

Changed

  • changed default encoding from ISO to UTF-16
  • improved decode

[0.0.7] - 2016-11-11

Fixed

  • Fixed encoding issues when reading ID3 tags

[0.0.6] - 2016-10-24

Changed

  • Write picture as cover to create better compatibility with certain devices

[0.0.5] - 2016-09-09

Added

  • Partial read support

Fixed

  • Fix node v6

unreleased 0.2.7 0.2.6 0.2.5 0.2.4 0.2.3 0.2.2 0.2.1 0.2.0 0.1.21 0.1.20 0.1.19 0.1.18 0.1.17 0.1.16 0.1.15 0.1.14 0.1.13 0.1.12 0.1.11 0.1.8 0.1.7 0.1.6 0.1.3 0.1.0 0.0.10 0.0.9 0.0.8 0.0.7 0.0.6 0.0.5