首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >YouTube - MP4 to MP3搞砸了

YouTube - MP4 to MP3搞砸了
EN

Stack Overflow用户
提问于 2019-11-22 16:04:37
回答 1查看 983关注 0票数 0

它应该下载播放列表中的所有视频,并将它们转换为mp3。但这只是使mp4's和1空mp3的数字高于最大mp4。我的新手不知道怎么解决这个问题..。

代码语言:javascript
复制
var ytpl = require('ytpl');
var fs = require('fs-extra');
var path = require('path');
var ffmpeg = require('fluent-ffmpeg');
var binaries = require('ffmpeg-static');
var ytdl = require('ytdl-core');

var output_dir = path.join(__dirname+"/dl");

ytpl("PL8n8S4mVUWvprlN2dCAMoIo6h47ZwR_gn", (err, pl) => {
    if(err) throw err;

    let c = 0;

    pl.items.forEach((i) => {
        ytdl(i.url_simple+"", { filter: 'audioonly' }).pipe(fs.createWriteStream(output_dir+"/"+c+".mp4")).on('finish', () => {
            console.log("Finished MP4 DL, starting conversion...");
            ffmpeg(output_dir+"/"+c+".mp4")
                .setFfmpegPath(binaries.path)
                .format('mp3')
                .audioBitrate(320)
                .output(fs.createWriteStream(output_dir+"/"+c+".mp3"))
                .on('end', () => {
                    console.log("Finished MP3 Convert...");
                })
                .run();
        });
        c++;
    });

});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-22 23:09:22

使用ytdl-core 链接示例修复了

固定代码:

代码语言:javascript
复制
var ytpl = require('ytpl');
var fs = require('fs-extra');
var path = require('path');
var ffmpeg = require('fluent-ffmpeg');
var binaries = require('ffmpeg-static');
var sanitize = require('sanitize-filename');
var ytdl = require('ytdl-core');

var output_dir = path.join(__dirname+"/dl");

ytpl("PL8n8S4mVUWvprlN2dCAMoIo6h47ZwR_gn", (err, pl) => {
    if(err) throw err;

    for (const i of pl.items) {
        let stream = ytdl(i.id, {
            filter: 'audioonly'
        });

        ffmpeg(stream)
            .audioBitrate(320)
            .save(`${output_dir}/${sanitize(i.title + " (by " + i.author.name + ")")}.mp3`)
            .on('end', () => {
                console.log("Done! Downloaded \""+i.title + " (by " + i.author.name + ")"+"\"");
            });
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58997856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档