mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
Workaround for 50MB+ video (pt. 2)
This commit is contained in:
parent
26b6d3fdc4
commit
3aa22a6b90
@ -59,9 +59,7 @@ module.exports = (bot) => {
|
|||||||
|
|
||||||
const mp4File = `tmp/${userId}.mp4`;
|
const mp4File = `tmp/${userId}.mp4`;
|
||||||
const cmdArgs = "--max-filesize 2G --no-playlist --merge-output-format mp4 -o";
|
const cmdArgs = "--max-filesize 2G --no-playlist --merge-output-format mp4 -o";
|
||||||
const videoFormat = "-f bestvideo+bestaudio";
|
|
||||||
const dlpCommand = ytDlpPath;
|
const dlpCommand = ytDlpPath;
|
||||||
const dlpArgs = [videoUrl, videoFormat, ...cmdArgs.split(' '), mp4File];
|
|
||||||
|
|
||||||
const downloadingMessage = await ctx.reply(strings.ytDownloading, {
|
const downloadingMessage = await ctx.reply(strings.ytDownloading, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
@ -70,51 +68,67 @@ module.exports = (bot) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const approxSizeInMB = await getApproxSize(ytDlpPath, videoUrl);
|
const approxSizeInMB = await getApproxSize(ytDlpPath, videoUrl);
|
||||||
|
let videoFormat = "";
|
||||||
|
|
||||||
if (approxSizeInMB >= 50) {
|
if (approxSizeInMB >= 50) {
|
||||||
await ctx.telegram.editMessageText(
|
videoFormat = `-f best`;
|
||||||
ctx.chat.id,
|
|
||||||
downloadingMessage.message_id,
|
|
||||||
null,
|
|
||||||
strings.ytUploadLimit, {
|
|
||||||
parse_mode: 'Markdown',
|
|
||||||
reply_to_message_id: ctx.message.message_id,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
await downloadFromYoutube(dlpCommand, dlpArgs);
|
videoFormat = "-f bestvideo+bestaudio";
|
||||||
|
}
|
||||||
|
|
||||||
await ctx.telegram.editMessageText(
|
const dlpArgs = [videoUrl, videoFormat, ...cmdArgs.split(' '), mp4File];
|
||||||
ctx.chat.id,
|
await downloadFromYoutube(dlpCommand, dlpArgs);
|
||||||
downloadingMessage.message_id,
|
|
||||||
null,
|
|
||||||
strings.ytUploading, {
|
|
||||||
parse_mode: 'Markdown',
|
|
||||||
reply_to_message_id: ctx.message.message_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (fs.existsSync(mp4File)) {
|
await ctx.telegram.editMessageText(
|
||||||
const message = strings.ytUploadDesc
|
ctx.chat.id,
|
||||||
.replace("{userId}", userId)
|
downloadingMessage.message_id,
|
||||||
.replace("{userName}", ctx.from.first_name);
|
null,
|
||||||
|
strings.ytUploading, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
if (fs.existsSync(mp4File)) {
|
||||||
await ctx.replyWithVideo({
|
const message = strings.ytUploadDesc
|
||||||
source: mp4File,
|
.replace("{userId}", userId)
|
||||||
caption: `${message}`,
|
.replace("{userName}", ctx.from.first_name);
|
||||||
parse_mode: 'Markdown',
|
|
||||||
});
|
try {
|
||||||
} catch (error) {
|
await ctx.replyWithVideo({
|
||||||
await ctx.reply(`\`${error}\``, {
|
source: mp4File,
|
||||||
parse_mode: 'Markdown',
|
caption: `${message}`,
|
||||||
reply_to_message_id: ctx.message.message_id,
|
parse_mode: 'Markdown',
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
await ctx.telegram.editMessageText(
|
||||||
|
ctx.chat.id,
|
||||||
|
downloadingMessage.message_id,
|
||||||
|
null,
|
||||||
|
strings.ytUploadLimit2, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.unlinkSync(mp4File);
|
||||||
|
} catch (error) {
|
||||||
|
await ctx.reply(`\`${error}\``, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_to_message_id: ctx.message.message_id,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (downloadError) {
|
} catch (error) {
|
||||||
fs.unlinkSync(mp4File);
|
fs.unlinkSync(mp4File);
|
||||||
|
let errStatus = "";
|
||||||
|
|
||||||
|
if (error == "Error: 413: Request Entity Too Large") {
|
||||||
|
errStatus = Strings.ytUploadLimit;
|
||||||
|
} else {
|
||||||
|
errStatus = error.error ? error.error.message : 'Unknown error';
|
||||||
|
}
|
||||||
|
|
||||||
const message = strings.ytDownloadErr
|
const message = strings.ytDownloadErr
|
||||||
.replace("{err}", downloadError.error ? downloadError.error.message : 'Unknown error')
|
.replace("{err}", errStatus)
|
||||||
.replace("{userName}", ctx.from.first_name);
|
.replace("{userName}", ctx.from.first_name);
|
||||||
|
|
||||||
await ctx.reply(message, {
|
await ctx.reply(message, {
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
"ytUploadDesc": "*[{userName}](tg://user?id={userId}), there is your downloaded video.*",
|
"ytUploadDesc": "*[{userName}](tg://user?id={userId}), there is your downloaded video.*",
|
||||||
"ytDownloadErr": "*Error during YT video download:*\n\n`{err}`",
|
"ytDownloadErr": "*Error during YT video download:*\n\n`{err}`",
|
||||||
"ytUploadLimit": "*This video exceeds the 50 MB upload limit imposed by Telegram on our bot. Please try another video. We're doing our best to increase this limit.*",
|
"ytUploadLimit": "*This video exceeds the 50 MB upload limit imposed by Telegram on our bot. Please try another video. We're doing our best to increase this limit.*",
|
||||||
|
"ytUploadLimit2": "*This video had its quality reduced because it exceeded the 50MB limit for uploads imposed by Telegram.*",
|
||||||
"fileError": "Error uploading file",
|
"fileError": "Error uploading file",
|
||||||
"botUpdated": "Bot updated with success.",
|
"botUpdated": "Bot updated with success.",
|
||||||
"errorUpdatingBot": "Error updating bot\n\n{error}"
|
"errorUpdatingBot": "Error updating bot\n\n{error}"
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
"ytUploadDesc": "*[{userName}](tg://user?id={userId}), aqui está o seu vídeo baixado.*",
|
"ytUploadDesc": "*[{userName}](tg://user?id={userId}), aqui está o seu vídeo baixado.*",
|
||||||
"ytDownloadErr": "*Erro durante o download do vídeo do YT:*\n\n`{err}`",
|
"ytDownloadErr": "*Erro durante o download do vídeo do YT:*\n\n`{err}`",
|
||||||
"ytUploadLimit": "*Este vídeo excede o limite de carregamento de 50 MB imposto pelo Telegram ao nosso bot. Por favor, tente outro vídeo. Estamos fazendo o possível para aumentar esse limite.*",
|
"ytUploadLimit": "*Este vídeo excede o limite de carregamento de 50 MB imposto pelo Telegram ao nosso bot. Por favor, tente outro vídeo. Estamos fazendo o possível para aumentar esse limite.*",
|
||||||
|
"ytUploadLimit2": "*Esse vídeo teve a qualidade reduzida por estar excedendo o limite de 50MB para uploads imposto pelo Telegram.*",
|
||||||
"fileError": "Erro ao enviar o arquivo",
|
"fileError": "Erro ao enviar o arquivo",
|
||||||
"botUpdated": "Bot atualizado com sucesso.",
|
"botUpdated": "Bot atualizado com sucesso.",
|
||||||
"errorUpdatingBot": "Erro ao atualizar o bot\n\n{error}"
|
"errorUpdatingBot": "Erro ao atualizar o bot\n\n{error}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user