How to modify a MP3 metadata and save by Node.js?

10,145

Solution 1

For those coming to this question through Google, there is a node module that can do this, both read and write metadata: https://www.npmjs.org/package/ffmetadata

Solution 2

I don't know whether there's a way to actually do the meta data manipulation in NodeJS. This is a work around way but you could do this using child_process.exec and perl:

NodeJS Code

var exec = require('child_process').exec,
    child;

child = exec('perl changeTags.pl file.mp3',
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});

Perl code

#!/usr/bin/perl

use MP3::Tag;

$mp3 = MP3::Tag->new(@ARGV[0]); # create object 

$mp3->get_tags(); # read tags

print "Attempting to print tags for @ARGV[0]\n";

if (exists $mp3->{ID3v2}) {
  print "Comments: " . $mp3->{ID3v2}->comment . "\n";
    print "Zip: " . $mp3->{ID3v2}->album . "\n";
    print "Tags: " . $mp3->{ID3v2}->title . "\n";
} else {
    print "@ARGV[0] does not have ID3v2 tags\n";
}

$mp3->close(); # destroy object

Something like that. You'd obviously want to give more arguments for what you actually want to change the meta data to.... Good luck!

Solution 3

So far i found jsmediatags is best npm package to read ID3v2 tags

var jsmediatags = require("jsmediatags");

jsmediatags.read("./song.mp3", {
  onSuccess: function(tag) {
    console.log(tag);
  },
  onError: function(error) {
    console.log(':(', error.type, error.info);
  }
});
Share:
10,145

Related videos on Youtube

Zation
Author by

Zation

Focus on javascript and html5

Updated on October 09, 2022

Comments

  • Zation
    Zation over 1 year

    I want to achieve below goals:

    • Read a MP3 metadata
    • Modify the encoding of that metadata (if I could modify the content of that metadata, that would be better)
    • Save the modification to that MP3 file

    All these operations could be based on native Node.js (without browser). Is there any module provide such function or I can develop based on?

  • kentcdodds
    kentcdodds almost 11 years
    Why in the world did this get a down-vote?
  • inf3rno
    inf3rno about 10 years
    maybe because it is in perl ;-)
  • Denys Vitali
    Denys Vitali almost 10 years
    -1 because is not a native node module but a workaround instead
  • finiteloop
    finiteloop over 9 years
    Its worth noting that this has a dependence on ffmpeg.
  • Tacticus
    Tacticus almost 8 years
    For compatability with Windows Explorer, the plugin provides theid3v2.3 option which may be set to true. See the documentation of ffmetadata.
  • Mordred
    Mordred almost 6 years
    This seems to work well, but supports only a basic subset of tags.
  • oldboy
    oldboy over 4 years
    is there a package to that will allow me to edit the metadata of any file type?
  • oldboy
    oldboy over 4 years
    is there a package to that will allow me to edit the metadata of any file type?
  • user202729
    user202729 over 3 years
    ffmpeg isn't a native node module either...