fix: Try to make ffmpeg work on getvideo command

This commit is contained in:
GiovaniFZ 2024-10-19 15:12:33 -03:00
parent 34ff8d4e3f
commit 94630ac0f0
No known key found for this signature in database
GPG key ID: 63DD92181B575322

View file

@ -1,6 +1,19 @@
const { exec } = require('child_process');
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
const path = require('path');
const os = require('os');
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
const { getStrings } = require('../plugins/checklang.js');
const ffmpegPaths = {
linux: '/usr/bin/ffmpeg',
win32: path.resolve(__dirname, '../plugins/ffmpeg/ffmpeg.exe'),
};
const getFfmpegPath = () => {
const platform = os.platform();
return ffmpegPaths[platform] || ffmpegPaths.linux;
};
function getVideo(command) {
return new Promise((resolve, reject) => {
@ -15,13 +28,17 @@ function getVideo(command) {
}
module.exports = (bot) => {
const ffmpegPath = getFfmpegPath();
bot.command('getvideo', spamwatchMiddleware, async (ctx) => {
const strings = getStrings(ctx.from.language_code);
const userId = ctx.from.id;
const mp4File = userId + '.f137.mp4';
const webmFile = userId + '.f251.webm';
const ffmpegCommand = 'cd tmp && ffmpeg -i ' + mp4File + ' -i ' + webmFile + ' -c:v copy -c:a copy -strict -2 output.mp4';
const ffmpegCommand = 'cd tmp && ' + ffmpegPath + ' -i ' + mp4File + ' -i ' + webmFile + ' -c:v copy -c:a copy -strict -2 output.mp4';
getVideo(ffmpegCommand);
ctx.telegram.reply('Sending...');
const message = strings.ytUploadDesc
.replace("{userId}", userId)
.replace("{userName}", ctx.from.first_name);
try {
await ctx.replyWithVideo({
source: 'tmp/output.mp4',
@ -29,7 +46,7 @@ module.exports = (bot) => {
parse_mode: 'Markdown',
});
} catch (error) {
ctx.reply(errorMessage.replace('{error}', error.message), {
ctx.reply(error, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});