更改 mp3 文件的作者

change author of mp3 file

我想根据用户发送的数据来设置一个mp3文件的作者。

到目前为止,我设法获得了用户发送的数据(无论如何都算不上漏洞利用),但我无法设法更改文件的作者。我试过同时使用 node-id3 package and ffmetadata package, as suggested by this answer,但是 none 有效。

node-id3 方法

这是我为 node-id3 方法编写的代码的一部分,而 readTags 中显示的标签确实是我在 update 方法中添加的标签,它不会当我在我的计算机上(使用 iTunes)或 android phone(使用三星音乐)阅读文件时,请不要更改文件的作者,这意味着这种方法不起作用。

const NodeID3 = require('node-id3')    

//getting the filename and fileAuthor, as well as creating the file on the server

let tags = {
    title: filename,
    composer: fileAuthor,
    artist: fileAuthor,
    remixArtist: fileAuthor,
    conductor: fileAuthor,
    originalArtist: fileAuthor,
}

let success = NodeID3.update(tags, toBeDownloadedFilePath)

console.log(success)

let readTags = NodeID3.read(toBeDownloadedFilePath)

console.log(readTags)

ffmetadata 方法

这是使用 ffmetadata 方法编写的同一部分:

const ffmetadata = require("ffmetadata");  

//getting the filename and fileAuthor, as well as creating the file on the server

let tags = {
    artist: fileAuthor,
}

ffmetadata.write(toBeDownloadedFilePath, tags, function(err) {
    if (err) console.error("Error writing metadata", err);
    else console.log("Data written");
});

使用这种方法,我得到了错误:

[mp3 @ 0x7f90f8000000] Format mp3 detected only with low score of 1, misdetection possible! [mp3 @ 0x7f90f8000000] Failed to read frame size: Could not seek to 1026. music1.mp3: Invalid argument

music1.mp3 是我的文件名),我测试过的所有音频 reader 都能完美识别我的 mp3 文件。

非常感谢您的帮助。

所以我终于找到了问题出在哪里(至少使用 node-id3 方法):

为了更好地理解它,我将在在服务器上创建文件的步骤中添加一些细节。

这是我的无效代码:

const NodeID3 = require('node-id3') 
const fs = require('fs-extra');  // file system   

fs.ensureFileSync(toBeDownloadedFilePath); //because I need to create the file if it doesn't exist
const toBeDownloadedFile = fs.createWriteStream(toBeDownloadedFilePath);

//the way the audio stream is created isn't relevant, but if you're interested, it's a youtube stream, as per https://www.npmjs.com/package/youtube-audio-stream
let fileWriteStream = audioStream.pipe(toBeDownloadedFile)

let tags = {
    title: filename,
    composer: fileAuthor,
    artist: fileAuthor,
    remixArtist: fileAuthor,
    conductor: fileAuthor,
    originalArtist: fileAuthor,
}

let success = NodeID3.update(tags, toBeDownloadedFilePath)

console.log(success)

let readTags = NodeID3.read(toBeDownloadedFilePath)

console.log(readTags)

问题是我写了标签,但立即被 audiostream.pipe

删除了

因此解决方案非常简单,我最终得到了这段代码:

const NodeID3 = require('node-id3') 
const fs = require('fs-extra');  // file system   

fs.ensureFileSync(toBeDownloadedFilePath); //because I need to create the file if it doesn't exist
const toBeDownloadedFile = fs.createWriteStream(toBeDownloadedFilePath);

let fileWriteStream = audiSstream.pipe(toBeDownloadedFile)

fileWriteStream.on('finish', () => {
    let tags = {
        title: filename,
        artist: fileAuthor,
    }

    NodeID3.update(tags, toBeDownloadedFilePath)

    //any additional action, in my case, send the file for a download
})

希望这对遇到类似问题的人有所帮助。