mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
28 lines
796 B
JavaScript
28 lines
796 B
JavaScript
var exec = require('child_process').exec;
|
|
|
|
async function DownloadFromYoutube(command) {
|
|
return new Promise((resolve, reject) => {
|
|
|
|
exec(command, (error, stdout, stderr) => {
|
|
if (error) {
|
|
reject({ error, stdout, stderr });
|
|
} else {
|
|
resolve({ error, stdout, stderr });
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = (bot) => {
|
|
bot.command('yt', async (ctx) => {
|
|
const args = ctx.message.text.split(' ').slice(1).join(' ');
|
|
const ytCommand = 'yt-dlp ' + args + ' -o video.mp4';
|
|
await DownloadFromYoutube(ytCommand);
|
|
try{
|
|
await ctx.replyWithVideo({source: 'video.mp4'});
|
|
}catch (error){
|
|
console.log(error);
|
|
}
|
|
}
|
|
)
|
|
} |