Skip to content

Commit

Permalink
πšπ™΄π™Όπ™²π™·π™°π™Ό π™±πšˆ π™Άπ™°π™±πšπ™Έπ™΄π™»-π™Ήπšƒπš‡πš‚
Browse files Browse the repository at this point in the history
  • Loading branch information
davidprospero123 authored Jul 22, 2024
1 parent 4ca1427 commit d3b282e
Showing 1 changed file with 39 additions and 88 deletions.
127 changes: 39 additions & 88 deletions plugins/dl-ytmp4.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,46 @@
import fetch from 'node-fetch';
import fs from 'fs';
import { pipeline } from 'stream';
import { promisify } from 'util';
import os from 'os';

const streamPipeline = promisify(pipeline);

const handler = async (m, { conn, command, text, usedPrefix }) => {
if (!text) return conn.reply(m.chat, 'πš’πš—πšπš›πšŽπšœπšŠ πš’πš— πš•πš’πš—πš” 𝚍𝚎 πš’πš˜πšžπšπšžπš‡', m);

const videoUrl = text.trim();
const apiUrl = `https://youtube-api-thepapusteam.koyeb.app/api/video?url=${videoUrl}`;

try {
console.log(`Solicitando informaciΓ³n del video desde: ${apiUrl}`);
const response = await fetch(apiUrl);
const data = await response.json();

if (!data.status) {
throw new Error('Error al obtener informaciΓ³n del video');
}

console.log('InformaciΓ³n del video recibida:', data);

const { title, thumbnails, author } = data.data;
const thumbnail = thumbnails[0].url;
const videoUrlMp4 = data.downloads.mp4.url;

const tmpDir = os.tmpdir();
const filePath = `${tmpDir}/${title}.mp4`;
const writableStream = fs.createWriteStream(filePath);

console.log('Descargando video desde:', videoUrlMp4);
const videoResponse = await fetch(videoUrlMp4);
if (!videoResponse.ok) {
throw new Error('Error al descargar el video');
}

await streamPipeline(videoResponse.body, writableStream);
console.log('Descarga de video completada');

await m.react('πŸ•“');
import fs from 'fs'
import os from 'os'
import fetch from 'node-fetch'

let limit = 500
let handler = async (m, { conn, args, isPrems, isOwner, usedPrefix, command }) => {
let chat = global.db.data.chats[m.chat]
if (!args || !args[0]) throw `✳️ 𝙴𝙹𝙴𝙼𝙿𝙻𝙾:\n${usedPrefix + command} https://www.youtube.com/watch?v=k6ltpkNnNPY`
if (!args[0].match(/youtu/gi)) throw ` πš…π™΄πšπ™Έπ™΅π™Έπ™²π™° πš€πš„π™΄ πš‚πš„ 𝙴𝙽𝙻𝙰𝙲𝙴 πš‚π™΄π™° πš…π™°π™»π™Έπ™³π™Ύ`

var ggapi = `https://youtube-api-thepapusteam.koyeb.app/api/video?url=${encodeURIComponent(args[0])}`

const response = await fetch(ggapi)
if (!response.ok) {
console.log('Error al obtener los detalles del video:', response.statusText)
throw 'Error al obtener los detalles del video'
}
const data = await response.json()

const txt = `> Β» Titulo: ${title}\n` +
`> Β» Autor: ${author.name}\n` +
`> Β» Canal: ${author.url}\n\n`;
if (!data.status) throw 'Error al procesar el video'

await conn.reply(m.chat, txt, m);
const caption = `\`β‹†ο½‘Λšκ’°ΰ¦Œ πšˆπ™Ύπš„πšƒπš„π™±π™΄ - πš…π™Έπ™³π™΄π™Ύ ΰ»’κ’±Λšο½‘β‹†\`
κ¨„οΈŽ \`πšƒπš’πšπšžπš•πš˜\`: ${data.data.title}
κ¨„οΈŽ \`π™°πšžπšπš˜πš›\`: ${data.data.author.name}
κ¨„οΈŽ \`π™²πšŠπš—πšŠπš•\`: ${data.data.author.url}
κ¨„οΈŽ \`π™΄πš—πš•πšŠπšŒπšŽ\`: ${data.data.src_url}
κ¨„οΈŽ \`π™Όπš’πš—πš’πšŠπšπšžπš›πšŠ\` ${data.data.picture}
βŠ±β”€β”β”€β”βŠ±ΰΌ»Λ—ΛΛ‹ β™‘ ΛŽΛŠΛ—ΰΌΊβŠ°β”β”β”€β”€βŠ°
`

await conn.sendMessage(m.chat, {
video: { url: filePath },
mimetype: "video/mp4",
fileName: `${title}.mp4`,
quoted: m,
contextInfo: {
'forwardingScore': 200,
'isForwarded': true,
externalAdReply: {
showAdAttribution: true,
title: title,
body: author.name,
mediaType: 2,
sourceUrl: global.canal,
thumbnail: await (await conn.getFile(thumbnail)).data,
mediaType: 1,
showAdAttribution: true,
renderLargerThumbnail: true,
}
}
}, { quoted: m });
let vres = data.downloads.mp4.url

await m.react('βœ…');
let vid = await fetch(vres)
const vidBuffer = await vid.buffer()

fs.unlink(filePath, (err) => {
if (err) {
console.error(`OcurriΓ³ un error al borrar el archivo de video: ${err}`);
m.react('❌');
} else {
console.log(`Borrando archivo de video: ${filePath}`);
m.react('βœ…');
}
});
} catch (error) {
console.error('Error en el proceso:', error);
await conn.reply(m.chat, 'OcurriΓ³ un error al procesar tu solicitud', m);
await m.react('❌');
}
};
conn.sendFile(m.chat, vidBuffer, 'video.mp4', caption, m, false, { asDocument: false })
}

handler.help = ["ytmp4"].map((v) => v + " <link>");
handler.tags = ['dl'];
handler.command = /^(ytmp4|ytvideo)$/i;
handler.help = ['ytmp4 <yt-link>']
handler.tags = ['descargador']
handler.command = ['ytmp4', 'video', 'ytv']
handler.diamond = false

export default handler;
export default handler

0 comments on commit d3b282e

Please sign in to comment.