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

你。 提交于 2019-11-30 11:39:21

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

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!

Sumit Ridhal

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);
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!