mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-05-09 12:05:00 +00:00
feat: add checking and logging for valid yt url
This commit is contained in:
parent
ac7119dee5
commit
19ce5295b1
@ -9,6 +9,7 @@
|
|||||||
"node-html-parser": "^7.0.1",
|
"node-html-parser": "^7.0.1",
|
||||||
"nodemon": "^3.1.10",
|
"nodemon": "^3.1.10",
|
||||||
"telegraf": "^4.16.3",
|
"telegraf": "^4.16.3",
|
||||||
"winston": "^3.17.0"
|
"winston": "^3.17.0",
|
||||||
|
"youtube-url": "^0.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import { execFile } from 'child_process';
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import * as ytUrl from 'youtube-url';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
@ -66,15 +67,19 @@ export default (bot) => {
|
|||||||
bot.command(['yt', 'ytdl', 'sdl', 'video', 'dl'], spamwatchMiddleware, async (ctx) => {
|
bot.command(['yt', 'ytdl', 'sdl', 'video', 'dl'], spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const ytDlpPath = getYtDlpPath();
|
const ytDlpPath = getYtDlpPath();
|
||||||
const userId = ctx.from.id;
|
const userId: number = ctx.from.id;
|
||||||
const videoUrl = ctx.message.text.split(' ').slice(1).join(' ');
|
const videoUrl: string = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
const mp4File = `tmp/${userId}.mp4`;
|
const videoUrlSafe: boolean = ytUrl.valid(videoUrl);
|
||||||
const tempMp4File = `tmp/${userId}.f137.mp4`;
|
const randId: string = Math.random().toString(36).substring(2, 15);
|
||||||
const tempWebmFile = `tmp/${userId}.f251.webm`;
|
const mp4File: string = `tmp/${userId}-${randId}.mp4`;
|
||||||
let cmdArgs = "";
|
const tempMp4File: string = `tmp/${userId}-${randId}.f137.mp4`;
|
||||||
const dlpCommand = ytDlpPath;
|
const tempWebmFile: string = `tmp/${userId}-${randId}.f251.webm`;
|
||||||
const ffmpegPath = getFfmpegPath();
|
let cmdArgs: string = "";
|
||||||
const ffmpegArgs = ['-i', tempMp4File, '-i', tempWebmFile, '-c:v copy -c:a copy -strict -2', mp4File];
|
const dlpCommand: string = ytDlpPath;
|
||||||
|
const ffmpegPath: string = getFfmpegPath();
|
||||||
|
const ffmpegArgs: string[] = ['-i', tempMp4File, '-i', tempWebmFile, '-c:v copy -c:a copy -strict -2', mp4File];
|
||||||
|
|
||||||
|
console.log(`DOWNLOADING: ${videoUrl}\nSAFE: ${videoUrlSafe}\n`)
|
||||||
|
|
||||||
if (!videoUrl) {
|
if (!videoUrl) {
|
||||||
return ctx.reply(Strings.ytDownload.noLink, {
|
return ctx.reply(Strings.ytDownload.noLink, {
|
||||||
@ -82,7 +87,13 @@ export default (bot) => {
|
|||||||
disable_web_page_preview: true,
|
disable_web_page_preview: true,
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
};
|
} else if (!videoUrlSafe) {
|
||||||
|
return ctx.reply(Strings.ytDownload.notYtLink, {
|
||||||
|
parse_mode: "Markdown",
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.existsSync(path.resolve(__dirname, "../props/cookies.txt"))) {
|
if (fs.existsSync(path.resolve(__dirname, "../props/cookies.txt"))) {
|
||||||
cmdArgs = "--max-filesize 2G --no-playlist --cookies src/props/cookies.txt --merge-output-format mp4 -o";
|
cmdArgs = "--max-filesize 2G --no-playlist --cookies src/props/cookies.txt --merge-output-format mp4 -o";
|
||||||
|
@ -75,7 +75,8 @@
|
|||||||
"uploadErr": "Error uploading file. Please try again later.\n\n{error}",
|
"uploadErr": "Error uploading file. Please try again later.\n\n{error}",
|
||||||
"uploadLimit": "*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.*",
|
"uploadLimit": "*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.*",
|
||||||
"sizeLimitWarn": "*This video had its quality reduced because it exceeded the 50MB limit for uploads imposed by Telegram.*",
|
"sizeLimitWarn": "*This video had its quality reduced because it exceeded the 50MB limit for uploads imposed by Telegram.*",
|
||||||
"noLink": "Please provide a link to a video to download."
|
"noLink": "Please provide a link to a video to download.",
|
||||||
|
"notYtLink": "Please provide a valid YouTube link to download."
|
||||||
},
|
},
|
||||||
"botUpdated": "Bot updated with success.\n\n```{result}```",
|
"botUpdated": "Bot updated with success.\n\n```{result}```",
|
||||||
"errorUpdatingBot": "Error updating bot\n\n{error}",
|
"errorUpdatingBot": "Error updating bot\n\n{error}",
|
||||||
|
@ -75,7 +75,8 @@
|
|||||||
"uploadErr": "Erro ao enviar o arquivo. Tente novamente mais tarde.\n\n{error}",
|
"uploadErr": "Erro ao enviar o arquivo. Tente novamente mais tarde.\n\n{error}",
|
||||||
"uploadLimit": "*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.*",
|
"uploadLimit": "*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.*",
|
||||||
"sizeLimitWarn": "*Esse vídeo teve a qualidade reduzida por estar excedendo o limite de 50MB para uploads imposto pelo Telegram.*",
|
"sizeLimitWarn": "*Esse vídeo teve a qualidade reduzida por estar excedendo o limite de 50MB para uploads imposto pelo Telegram.*",
|
||||||
"noLink": "*Por favor, forneça um link de um vídeo para download.*"
|
"noLink": "*Por favor, forneça um link de um vídeo para download.*",
|
||||||
|
"notYtLink": "*Forneça um link válido do YouTube para fazer o download.*"
|
||||||
},
|
},
|
||||||
"botUpdated": "Bot atualizado com sucesso.\n\n```{result}```",
|
"botUpdated": "Bot atualizado com sucesso.\n\n```{result}```",
|
||||||
"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