【问题标题】:change author of mp3 file更改 mp3 文件的作者
【发布时间】:2018-12-13 21:00:06
【问题描述】:

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

到目前为止,我设法获取了用户发送的数据(无论如何几乎没有漏洞利用),但我无法更改文件的作者。正如this answer 所建议的那样,我尝试使用node-id3 包和ffmetadata 包,但这些都不起作用。

node-id3 方法

这是我为 node-id3 方法编写的部分代码,虽然readTags 中显示的标签确实是我在update 方法中添加的标签,但它并没有改变作者当我在我的电脑(使用 iTunes)或我的安卓手机(使用三星音乐)上阅读该文件时,这意味着这种方法不起作用。

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] mp3 格式仅检测到低分 1,可能误检测! [mp3 @ 0x7f90f8000000] 无法读取帧大小:无法搜索到 1026。 music1.mp3:无效参数

music1.mp3 是我的文件名),我的 mp3 文件被我测试过的所有音频阅读器完全识别。

非常感谢您的帮助。

【问题讨论】:

    标签: node.js metadata mp3


    【解决方案1】:

    所以我终于找到了问题所在(至少使用 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
    })
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多