I create a telegram bot for downloading youtube videos.
I use telegraf api (javascripts) and youtube-dl. As I know telegram bot can currently send video files of up to 50 MB in size, but I need to configure downloading more, e.g 1 gb. How I can do this, any ideas?
Code:
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);
}
})
2
Answers
I know some article, where person makes some agent who will upload file and bot just resend this message. This article in Russian, but i can translate some steps.
instructions sign up your app
api_hash
How it works?
Btw, this person write on python, there some photos of his code, hope you will understand this.
Sorry for my English, it’s not perfect
Link: https://habr.com/ru/post/348234/
Using a Local Bot API Server you can send a large file up to 2GB.
GitHub Source Code:
Official Documentation
You can
build and install
this to your server by following the instructions on this link https://tdlib.github.io/telegram-bot-api/build.htmlbasic setup :
./telegram-bot-api --api-id=<your-app-id> --api-hash=<your-app-hash> --verbosity=20
http://127.0.0.1:8081/bot<token>/METHOD_NAME
reference: https://core.telegram.org/bots/apiExample Code with axios: