首页 > 解决方案 > 如何在 Telegram 中发送下载 50 毫克以上的视频?

问题描述

我创建了一个电报机器人来下载 youtube 视频。我使用 telegraf api (javascripts) 和 youtube-dl。据我所知,电报机器人目前可以发送最大 50 MB 的视频文件,但我需要配置下载更多,例如 1 GB。我怎么能做到这一点,有什么想法吗?

代码:

const { Telegraf } = require('telegraf');
const fs = require('fs');
const youtubedl = require('youtube-dl');

const bot = new Telegraf('mytoken');

var DOWN_URL = "https://www.youtube.com/watch?v=";
var TeleMaxData = 50;
var videosize;
let downloaded = 0

bot.command('/video', async (ctx) => {
    try {
        //let userID = ctx.from["id"];
        let videoURL = 'someYoutubeUrl';
        ctx.reply(`Youtube video URL: ${videoURL}`);

        var video = youtubedl(videoURL,
            ['--format=18'],
            { cwd: __dirname });

        video.on('info', function (info) {
            infor = info;
            ctx.reply('info', info)
            videosize = infor.size / 1000000;

            if (videosize < TeleMaxData) {
                ctx.reply('Download Started')
                video.pipe(fs.createWriteStream(`test.mp4`, { flags: 'a' }));

                video.on('end', async function () {
                    ctx.reply("Download completed");
                    try {
                        ctx.reply(`Download completed!\nVideo gets Send! - This might take a few Seconds! \n \n Title: \n ${infor.title}. It's ${videosize}mb big.`);
                        await ctx.replyWithVideo({
                            source: fs.createReadStream(`test.mp4`)
                        })
                    } catch (err) {
                        ctx.reply('Error: sendVideo' + err);
                    }
                })
            } else {
                ctx.reply(`The Video is ${videosize}mb. The maximum size for sending videos from Telegram is ${TeleMaxData}mb.`);
            }
        });
    } catch (err) {
        ctx.reply("ERROR" + err);
    }
})

标签: javascripttelegramyoutube-dltelegraf

解决方案


推荐阅读