eidoriantan / mp3tag.js

MP3 tagging library written in pure JavaScript for Node.js and browsers
https://mp3tag.js.org
MIT License
85 stars 9 forks source link

Cannot Save Metatada To Track Using Write.js Example #611

Closed djcee-b closed 1 year ago

djcee-b commented 1 year ago

Using the write.js example. The first issue I am facing is that:

mp3tag.tags.save() is not a function.

Upon changing this to mp3tag.save()

and writing to the file sync i get: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of ArrayBuffer

This is the code I am using:

`const MP3Tag = require('mp3tag.js') const fs = require('fs')

const audioPath = '/Users/courtney/Music/House Music/01 More & More.mp3'

// Read the buffer of an audio file const buffer = fs.readFileSync(audioPath)

// Now, pass it to MP3Tag const mp3tag = new MP3Tag(buffer, true)

// Read the audio tags if there's any mp3tag.read()

// Write the tags you wanted to write mp3tag.tags.title = 'NEW TITLE' // title mp3tag.tags.artist = 'NEW ARTIST' // artist mp3tag.tags.album = 'NEW ALBUM' // album mp3tag.tags.comment = 'COMMENT' mp3tag.tags.track = '1' mp3tag.tags.genre = 'Pop'

// Save the tags mp3tag.tags.save()

// Handle error if there's any if (mp3tag.error !== '') throw new Error(mp3tag.error)

// Read the new buffer again mp3tag.read() console.log(mp3tag.tags)

// Write the new buffer to file fs.writeFileSync(audioPath, mp3tag.buffer)`

Could someone please help with this

eidoriantan commented 1 year ago

Hello,

Thank you for reporting this issue. I'm currently working on the fix and will publish a new version soon.

For now, you can just manually turn the ArrayBuffer to Buffer by:

const nodeBuffer = Buffer.from(mp3tag.buffer)
fs.writeFileSync(audioPath, nodeBuffer)
eidoriantan commented 1 year ago

I already published v3.4.1 and that should fix this issue. I'm closing this now