2024-09-26 17:08:30 -03:00
|
|
|
var exec = require('child_process').exec;
|
2024-09-26 21:56:50 -03:00
|
|
|
const fs = require('fs');
|
2024-09-27 15:30:14 -03:00
|
|
|
const { getStrings } = require('../plugins/checklang');
|
2024-09-26 17:08:30 -03:00
|
|
|
|
|
|
|
async function DownloadFromYoutube(command) {
|
|
|
|
return new Promise((resolve, reject) => {
|
2024-09-26 21:56:50 -03:00
|
|
|
|
2024-09-26 17:08:30 -03:00
|
|
|
exec(command, (error, stdout, stderr) => {
|
|
|
|
if (error) {
|
|
|
|
reject({ error, stdout, stderr });
|
|
|
|
} else {
|
|
|
|
resolve({ error, stdout, stderr });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = (bot) => {
|
|
|
|
bot.command('yt', async (ctx) => {
|
2024-09-27 15:30:14 -03:00
|
|
|
const Strings = getStrings(ctx.from.language_code);
|
2024-09-26 17:08:30 -03:00
|
|
|
const args = ctx.message.text.split(' ').slice(1).join(' ');
|
|
|
|
const ytCommand = 'yt-dlp ' + args + ' -o video.mp4';
|
2024-09-27 15:30:14 -03:00
|
|
|
ctx.reply(Strings.downloading);
|
2024-09-26 17:08:30 -03:00
|
|
|
await DownloadFromYoutube(ytCommand);
|
2024-09-26 21:56:50 -03:00
|
|
|
try {
|
2024-09-27 15:30:14 -03:00
|
|
|
ctx.reply(Strings.uploading);
|
2024-09-26 21:56:50 -03:00
|
|
|
await ctx.replyWithVideo({ source: 'video.mp4' });
|
|
|
|
} catch (error) {
|
2024-09-27 15:30:14 -03:00
|
|
|
ctx.reply('Error!')
|
2024-09-26 21:56:50 -03:00
|
|
|
}
|
2024-09-27 15:30:14 -03:00
|
|
|
fs.unlinkSync('video.mp4');
|
|
|
|
})
|
2024-09-26 17:08:30 -03:00
|
|
|
}
|