diff --git a/commands/getvideo.js b/commands/getvideo.js index dec2a37..3c19af1 100644 --- a/commands/getvideo.js +++ b/commands/getvideo.js @@ -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 });