fix: yt: set cookies for check_size args #35

Merged
GiovaniFZ merged 2 commits from fix_ttk into main 2025-04-15 00:59:12 +00:00

View file

@ -41,7 +41,12 @@ const downloadFromYoutube = async (command, args) => {
}; };
const getApproxSize = async (command, videoUrl) => { const getApproxSize = async (command, videoUrl) => {
const args = [videoUrl, '--compat-opt', 'manifest-filesize-approx', '-O', 'filesize_approx']; let args = [];
if (fs.existsSync(path.resolve(__dirname, "../props/cookies.txt"))) {
args = [videoUrl, '--compat-opt', 'manifest-filesize-approx', '-O', 'filesize_approx', '--cookies', path.resolve(__dirname, "../props/cookies.txt")];
} else {
args = [videoUrl, '--compat-opt', 'manifest-filesize-approx', '-O', 'filesize_approx'];
}
try { try {
const { stdout } = await downloadFromYoutube(command, args); const { stdout } = await downloadFromYoutube(command, args);
const sizeInBytes = parseInt(stdout.trim(), 10); const sizeInBytes = parseInt(stdout.trim(), 10);
@ -131,7 +136,7 @@ module.exports = (bot) => {
}, },
); );
if(fs.existsSync(tempMp4File)){ if (fs.existsSync(tempMp4File)) {
await downloadFromYoutube(ffmpegPath, ffmpegArgs); await downloadFromYoutube(ffmpegPath, ffmpegArgs);
} }
@ -140,7 +145,8 @@ module.exports = (bot) => {
try { try {
await ctx.replyWithVideo({ await ctx.replyWithVideo({
source: mp4File }, { source: mp4File
}, {
caption: message, caption: message,
parse_mode: 'Markdown', parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id, reply_to_message_id: ctx.message.message_id,
@ -191,7 +197,6 @@ module.exports = (bot) => {
); );
} }
} catch (error) { } catch (error) {
console.error(error);
const errMsg = Strings.ytDownload.uploadErr.replace("{error}", error) const errMsg = Strings.ytDownload.uploadErr.replace("{error}", error)
await ctx.telegram.editMessageText( await ctx.telegram.editMessageText(
ctx.chat.id, ctx.chat.id,