如何修改MP3元数据并按Node.js保存?

Zat*_*ion 13 node.js node-modules

我想实现以下目标:

  • 阅读MP3元数据
  • 修改该元数据的编码(如果我可以修改该元数据的内容,那会更好)
  • 将修改保存到该MP3文件

所有这些操作都可以基于本机Node.js(没有浏览器).是否有任何模块提供这样的功能或我可以开发基于?

msp*_*ars 12

对于那些通过Google提出这个问题的人来说,有一个节点模块可以做到这一点,包括读写元数据:https: //www.npmjs.org/package/ffmetadata

  • 值得注意的是,这依赖于ffmpeg. (6认同)

ken*_*dds 2

我不知道是否有办法在 NodeJS 中实际进行元数据操作。这是一种解决方法,但您可以使用child_process.execperl 来完成此操作:

NodeJS 代码

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);
    }
});
Run Code Online (Sandbox Code Playgroud)

Perl代码

#!/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
Run Code Online (Sandbox Code Playgroud)

类似的事情。您显然想要为您实际想要将元数据更改为的内容提供更多参数......祝您好运!

  • 也许是因为它是用 Perl 编写的;-) (9认同)
  • ffmpeg 也不是本机节点模块...... (3认同)
  • -1,因为不是本机节点模块,而是一种解决方法 (2认同)