【问题标题】:Download youtube playlist下载 youtube 播放列表
【发布时间】:2020-11-08 21:30:47
【问题描述】:

我正在开发一个 Discord 机器人,我正在尝试找到一种方法让它播放 YouTube 上的整个播放列表或能够单独添加链接。用于此的资产是 Node.js、ESLint、ytdl-core、@discord/opus 和 ffmpeg(来自 this site)。

相关代码如下:

const ytdl = require('ytdl-core');
const { prefix, token } = require('./config.json');

client.on('message', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;
    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    if (message.content === '!play') {
        if (message.channel.type !== 'text') return;

        const voiceChannel = message.member.voice.channel;

        if (!voiceChannel) {
            return message.reply('please join a voice channel first!');
        }

        voiceChannel.join().then(connection => {
            const stream = ytdl('https://www.youtube.com/watch?v=1snEYPg8TXs');
            const dispatcher = connection.play(stream);

            dispatcher.on('finish', () => voiceChannel.leave());
        });

发布的代码没有问题,但正如您所见,它只允许一个 YouTube 视频。我对 ytdl 或任何相关函数一无所知,所以我尝试制作一个 var playlist = [etc.],但它根本不起作用,因为显然它已设置为期待链接。播放列表链接仅在完成动作之前播放第一首歌曲。

有什么建议吗?

【问题讨论】:

    标签: node.js audio youtube discord


    【解决方案1】:

    ytdl-core 不支持下载播放列表。您可能想尝试另一个库(例如ytpl)来获取播放列表中包含的视频,然后将其逐个传递给ytdl-core。

    【讨论】:

    • 谢谢!我吃完饭就试试。看起来应该很简单。
    • 我试过这个,但它会抛出一些错误,这些错误太长,无法粘贴到这里。第一个是标题:exports.removeHtml(importantTxt.match(PLAYLIST_NAME_REGEXP)[1]),TypeError: Cannot read property '1' of null
    猜你喜欢
    • 2017-12-12
    • 2018-07-03
    • 2020-10-12
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 2023-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多