fix/feat: output real error in console only, add more yt logging, url validity checking
This commit is contained in:
parent
16f777ac63
commit
8153ac2f33
3 changed files with 30 additions and 7 deletions
|
@ -63,6 +63,15 @@ const getApproxSize = async (command: string, videoUrl: string): Promise<number>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isValidUrl = (url: string): boolean => {
|
||||||
|
try {
|
||||||
|
new URL(url);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default (bot) => {
|
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);
|
||||||
|
@ -79,8 +88,6 @@ export default (bot) => {
|
||||||
const ffmpegPath: string = getFfmpegPath();
|
const ffmpegPath: string = getFfmpegPath();
|
||||||
const ffmpegArgs: string[] = ['-i', tempMp4File, '-i', tempWebmFile, '-c:v copy -c:a copy -strict -2', mp4File];
|
const ffmpegArgs: string[] = ['-i', tempMp4File, '-i', tempWebmFile, '-c:v copy -c:a copy -strict -2', mp4File];
|
||||||
|
|
||||||
console.log(`DOWNLOADING: ${videoUrl}\nYOUTUBE: ${videoIsYoutube}\n`)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for now, no checking is done for the video url
|
for now, no checking is done for the video url
|
||||||
yt-dlp should handle the validation, though it supports too many sites to hard-code
|
yt-dlp should handle the validation, though it supports too many sites to hard-code
|
||||||
|
@ -93,6 +100,18 @@ export default (bot) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure its a valid url
|
||||||
|
if (!isValidUrl(videoUrl)) {
|
||||||
|
console.log("[!] Invalid URL:", videoUrl)
|
||||||
|
return ctx.reply(Strings.ytDownload.noLink, {
|
||||||
|
parse_mode: "Markdown",
|
||||||
|
disable_web_page_preview: true,
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`\nDownload Request:\nURL: ${videoUrl}\nYOUTUBE: ${videoIsYoutube}\n`)
|
||||||
|
|
||||||
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";
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,6 +130,7 @@ export default (bot) => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (approxSizeInMB > 50) {
|
if (approxSizeInMB > 50) {
|
||||||
|
console.log("[!] Video size exceeds 50MB:", approxSizeInMB)
|
||||||
await ctx.telegram.editMessageText(
|
await ctx.telegram.editMessageText(
|
||||||
ctx.chat.id,
|
ctx.chat.id,
|
||||||
downloadingMessage.message_id,
|
downloadingMessage.message_id,
|
||||||
|
@ -124,6 +144,7 @@ export default (bot) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[i] Downloading video...")
|
||||||
await ctx.telegram.editMessageText(
|
await ctx.telegram.editMessageText(
|
||||||
ctx.chat.id,
|
ctx.chat.id,
|
||||||
downloadingMessage.message_id,
|
downloadingMessage.message_id,
|
||||||
|
@ -137,6 +158,7 @@ export default (bot) => {
|
||||||
const dlpArgs = [videoUrl, ...cmdArgs.split(' '), mp4File];
|
const dlpArgs = [videoUrl, ...cmdArgs.split(' '), mp4File];
|
||||||
await downloadFromYoutube(dlpCommand, dlpArgs);
|
await downloadFromYoutube(dlpCommand, dlpArgs);
|
||||||
|
|
||||||
|
console.log("[i] Uploading video...")
|
||||||
await ctx.telegram.editMessageText(
|
await ctx.telegram.editMessageText(
|
||||||
ctx.chat.id,
|
ctx.chat.id,
|
||||||
downloadingMessage.message_id,
|
downloadingMessage.message_id,
|
||||||
|
@ -207,14 +229,15 @@ export default (bot) => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
console.log("[i] Request completed\n")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errMsg = Strings.ytDownload.uploadErr.replace("{error}", error)
|
console.log("[!]", error.stderr)
|
||||||
|
const errMsg = Strings.ytDownload.uploadErr
|
||||||
// will no longer edit the message as the message context is not outside the try block
|
// will no longer edit the message as the message context is not outside the try block
|
||||||
await ctx.reply(errMsg, {
|
await ctx.reply(errMsg, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id,
|
reply_to_message_id: ctx.message.message_id,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
|
@ -73,7 +73,7 @@
|
||||||
"uploadingVid": "*Uploading video...*",
|
"uploadingVid": "*Uploading video...*",
|
||||||
"msgDesc": "{userMention}*, there is your downloaded video.*",
|
"msgDesc": "{userMention}*, there is your downloaded video.*",
|
||||||
"downloadErr": "*Error during YT video download:*\n\n`{err}`",
|
"downloadErr": "*Error during YT video download:*\n\n`{err}`",
|
||||||
"uploadErr": "Error uploading file. Please try again later.\n\n{error}",
|
"uploadErr": "Error uploading file. Please try again later.",
|
||||||
"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."
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
"uploadingVid": "*Enviando vídeo...*",
|
"uploadingVid": "*Enviando vídeo...*",
|
||||||
"msgDesc": "{userMention}*, aqui está o seu vídeo baixado.*",
|
"msgDesc": "{userMention}*, aqui está o seu vídeo baixado.*",
|
||||||
"downloadErr": "*Erro durante o download do vídeo do YT:*\n\n`{err}`",
|
"downloadErr": "*Erro durante o download do vídeo do YT:*\n\n`{err}`",
|
||||||
"uploadErr": "Erro ao enviar o arquivo. Tente novamente mais tarde.\n\n{error}",
|
"uploadErr": "Erro ao enviar o arquivo. Tente novamente mais tarde.",
|
||||||
"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.*"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue