14

我想实现以下目标:

  • 读取 MP3 元数据
  • 修改该元数据的编码(如果我可以修改该元数据的内容,那就更好了)
  • 保存对该 MP3 文件的修改

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

4

3 回答 3

13

对于那些通过谷歌提出这个问题的人,有一个节点模块可以做到这一点,读取和写入元数据: https ://www.npmjs.org/package/ffmetadata

于 2014-04-10T17:01:01.080 回答
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);
    }
});

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

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

于 2013-07-12T17:38:32.243 回答
1

到目前为止,我发现jsmediatagsnpm是读取ID3v2标签的最佳包

var jsmediatags = require("jsmediatags");

jsmediatags.read("./song.mp3", {
  onSuccess: function(tag) {
    console.log(tag);
  },
  onError: function(error) {
    console.log(':(', error.type, error.info);
  }
});
于 2017-07-04T17:38:32.907 回答