Skip to content

Commit

Permalink
Update descargas-play_v2.js
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoSobrino authored May 1, 2024
1 parent 692613e commit 9db7944
Showing 1 changed file with 136 additions and 13 deletions.
149 changes: 136 additions & 13 deletions plugins/descargas-play_v2.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
import fetch from 'node-fetch';
/*
- Agradecimiento a la comunidad de "WSApp β€’ Developers"
* https://chat.whatsapp.com/FaQunmlp9BmDRk6lEEc9FJ
- Agradecimiento especial a Carlos (PT) por los codigos de interactiveMessage (botones)
- Agradecimiento a Darlyn1234 por la estructura de uso en este codigo y quoted
* https://github.com/darlyn1234
- Adaptacion de imagen en tipo lista, codigo y funcionamiento por BrunoSobrino
* https://github.com/BrunoSobrino
*/
import fetch from 'node-fetch';
import { prepareWAMessageMedia, generateWAMessageFromContent, getDevice } from '@whiskeysockets/baileys';

let data;
let buff;
let mimeType;
let fileName;
let apiUrl;
let enviando = false;
let device;
const handler = async (m, { command, usedPrefix, conn, text }) => {
const datas = global
const idioma = datas.db.data.users[m.sender].language
const _translate = JSON.parse(fs.readFileSync(`./language/${idioma}.json`))
const tradutor = _translate.plugins.descargas_play_v2

device = await getDevice(m.key.id);

if (!text) throw `${tradutor.texto1[0]} _${usedPrefix + command} ${tradutor.texto1[1]} _${usedPrefix + command} https://youtu.be/JLWRZ8eWyZo?si=EmeS9fJvS_OkDk7p_`;
if (enviando) return;
enviando = true
if (command === 'playyt' && device == 'desktop' || command === 'playyt' && device == 'web') throw `*[❗] Los mensajes de botones aun no estan disponibles en WhatsApp web, acceda a su celular para poder ver y usar los mensajes con botones.*`
if (enviando) return;
enviando = true
try {

const apiUrls = [
`https://api.cafirexos.com/api/ytplay?text=${text}`,
`https://api-brunosobrino.onrender.com/api/ytplay?text=${text}`
`https://api-brunosobrino.onrender.com/api/ytplay?text=${text}`,
`https://api-for-canvas-brunosobrino.koyeb.app/api/ytplay?text=${text}`,
];

for (const url of apiUrls) {
Expand All @@ -35,41 +51,147 @@ if (enviando) return;
if (!data.resultado || !data.resultado.url) {
enviando = false;
throw `${tradutor.texto2}`;
} else {
}

if (command === 'playyt') {

const dataMessagee = `${tradutor.texto4[0]} ${data.resultado.title}\n${tradutor.texto4[1]} ${data.resultado.publicDate}\n${tradutor.texto4[2]} ${data.resultado.channel}\n${tradutor.texto4[3]} ${data.resultado.url}`.trim();
var messa = await prepareWAMessageMedia({ image: {url: data.resultado.image}}, { upload: conn.waUploadToServer })
let msg = generateWAMessageFromContent(m.chat, {
viewOnceMessage: {
message: {
interactiveMessage: {
body: { text: dataMessagee },
footer: { text: `${global.wm}`.trim() },
header: {
hasMediaAttachment: true,
imageMessage: messa.imageMessage,
},
nativeFlowMessage: {
buttons: [
{
name: 'quick_reply',
buttonParamsJson: JSON.stringify({
display_text: 'AUDIO',
id: `${usedPrefix}play.1 ${data.resultado.url} SN@`
})
},
{
name: 'quick_reply',
buttonParamsJson: JSON.stringify({
display_text: 'VIDEO',
id: `${usedPrefix}play.2 ${data.resultado.url} SN@`
})
},
/*{
// URL Redirect
name: 'cta_url',
buttonParamsJson: JSON.stringify({
display_text: 'IR A YOUTUBE',
url: `${data.resultado.url}`,
merchant_url: `${data.resultado.url}`,
id: `${data.resultado.url}`
})
},*/
],
messageParamsJson: "",
},
},
},
}
}, { userJid: conn.user.jid, quoted: m})
conn.relayMessage(m.chat, msg.message, { messageId: msg.key.id});
enviando = false;
return;
}

try {
if (command === 'play.1') { // play.1 con CFROS API v1 ytmp3
if (command === 'play.1') {
apiUrl = `https://api.cafirexos.com/api/v1/ytmp3?url=${data.resultado.url}`;
mimeType = 'audio/mpeg';
fileName = 'error.mp3';
buff = await conn.getFile(apiUrl);
} else if (command === 'play.2') { // play.2 con CFROS API v1 ytmp4
} else if (command === 'play.2') {
apiUrl = `https://api.cafirexos.com/api/v1/ytmp4?url=${data.resultado.url}`;
mimeType = 'video/mp4';
fileName = 'error.mp4';
buff = await conn.getFile(apiUrl);
}
} catch {
try {
if (command === 'play.1') { // play.1 con CFROS API v2 ytmp3
if (command === 'play.1') {
apiUrl = `https://api.cafirexos.com/api/v2/ytmp3?url=${data.resultado.url}`;
mimeType = 'audio/mpeg';
fileName = 'error.mp3';
buff = await conn.getFile(apiUrl);
} else if (command === 'play.2') { // play.2 con CFROS API v2 ytmp4
} else if (command === 'play.2') {
apiUrl = `https://api.cafirexos.com/api/v2/ytmp4?url=${data.resultado.url}`;
mimeType = 'video/mp4';
fileName = 'error.mp4';
buff = await conn.getFile(apiUrl);
}
} catch {
try {
if (command === 'play.1') {
apiUrl = `https://api-brunosobrino.onrender.com/api/v1/ytmp3?url=${data.resultado.url}`;
mimeType = 'audio/mpeg';
fileName = 'error.mp3';
buff = await conn.getFile(apiUrl);
} else if (command === 'play.2') {
apiUrl = `https://api-brunosobrino.onrender.com/api/v1/ytmp4?url=${data.resultado.url}`;
mimeType = 'video/mp4';
fileName = 'error.mp4';
buff = await conn.getFile(apiUrl);
}
} catch {
try {
if (command === 'play.1') {
apiUrl = `https://api-brunosobrino.onrender.com/api/v2/ytmp3?url=${data.resultado.url}`;
mimeType = 'audio/mpeg';
fileName = 'error.mp3';
buff = await conn.getFile(apiUrl);
} else if (command === 'play.2') {
apiUrl = `https://api-brunosobrino.onrender.com/api/v2/ytmp4?url=${data.resultado.url}`;
mimeType = 'video/mp4';
fileName = 'error.mp4';
buff = await conn.getFile(apiUrl);
}
} catch {
try {
if (command === 'play.1') {
apiUrl = `https://api-for-canvas-brunosobrino.koyeb.app/api/v1/ytmp3?url=${data.resultado.url}`;
mimeType = 'audio/mpeg';
fileName = 'error.mp3';
buff = await conn.getFile(apiUrl);
} else if (command === 'play.2') {
apiUrl = `https://api-for-canvas-brunosobrino.koyeb.app/api/v1/ytmp4?url=${data.resultado.url}`;
mimeType = 'video/mp4';
fileName = 'error.mp4';
buff = await conn.getFile(apiUrl);
}
} catch {
try {
if (command === 'play.1') {
apiUrl = `https://api-for-canvas-brunosobrino.koyeb.app/api/v2/ytmp3?url=${data.resultado.url}`;
mimeType = 'audio/mpeg';
fileName = 'error.mp3';
buff = await conn.getFile(apiUrl);
} else if (command === 'play.2') {
apiUrl = `https://api-for-canvas-brunosobrino.koyeb.app/api/v2/ytmp4?url=${data.resultado.url}`;
mimeType = 'video/mp4';
fileName = 'error.mp4';
buff = await conn.getFile(apiUrl);
}
} catch {
enviando = false;
throw `${tradutor.texto3}`;
}
}
}
}}
}}

const dataMessage = `${tradutor.texto4[0]} ${data.resultado.title}\n${tradutor.texto4[1]} ${data.resultado.publicDate}\n${tradutor.texto4[2]} ${data.resultado.channel}\n${tradutor.texto4[3]} ${data.resultado.url}`;
await conn.sendMessage(m.chat, { text: dataMessage }, { quoted: m });
if (!text.includes('SN@')) await conn.sendMessage(m.chat, { text: dataMessage }, { quoted: m });

if (buff) {
await conn.sendMessage(m.chat, {[mimeType.startsWith('audio') ? 'audio' : 'video']: buff.data, mimetype: mimeType, fileName: fileName}, {quoted: m});
Expand All @@ -79,11 +201,12 @@ if (enviando) return;
throw `${tradutor.texto5}`;
}
} catch (error) {
console.log(error)
enviando = false;
throw tradutor.texto6;
}
};
handler.command = ['play.1', 'play.2'];
handler.command = /^(play.1|play.2|playyt)$/i;
export default handler;

///////////////////////////////////////
Expand Down

0 comments on commit 9db7944

Please sign in to comment.