Skip to content

Commit

Permalink
Update buscador-yts.js
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoSobrino authored Apr 27, 2024
1 parent 1ee933a commit e9edab1
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion plugins/buscador-yts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,96 @@
/*
- Agradecimiento a la comunidad de "WSApp β€’ Developers"
- Agradecimiento especial a Carlos (PT) por los codigos de interactiveMessage (botones)
- Agradecimiento a Darlyn por la estructura de uso en este codigo
- Adaptacion y funcionamiento por BrunoSobrino
*/
import { getDevice } from '@whiskeysockets/baileys'
import yts from 'yt-search';
import fs from 'fs';

const handler = async (m, { conn, text, usedPrefix: prefijo }) => {
const datas = global;
const idioma = datas.db.data.users[m.sender].language;
const _translate = JSON.parse(fs.readFileSync(`./language/${idioma}.json`));
const traductor = _translate.plugins.buscador_yts;
const device = await getDevice(m.key.id);

if (!text) throw `⚠️ *${traductor.texto1}*`;

if (device !== 'desktop') {

const results = await yts(text);
const videos = results.videos.slice(0, 20);
const randomIndex = Math.floor(Math.random() * videos.length);
const randomVideo = videos[randomIndex];

const interactiveMessage = {
header: { title: `*</ YouTube Search >*\n` },
body: { text: `*β€”β—‰ Resultados obtenidos:* ${results.videos.length}\n*β€”β—‰ Video aleatorio:*\n*-β€Ί Title:* ${randomVideo.title}\n*-β€Ί Author:* ${randomVideo.author.name}\n*-β€Ί Views:* ${randomVideo.views}\n*-β€Ί Url:* ${randomVideo.url}\n*-β€Ί Imagen:* ${randomVideo.thumbnail}` },
nativeFlowMessage: {
buttons: [
{
name: 'single_select',
buttonParamsJson: JSON.stringify({
title: 'OPCIONES DISPONIBLES',
sections: videos.map((video) => ({
title: video.title,
rows: [
{
header: video.title,
title: video.author.name,
description: 'Descargar MP3',
id: `${prefijo}play.1 ${video.url}`
},
{
header: video.title,
title: video.author.name,
description: 'Descargar MP4',
id: `${prefijo}play.2 ${video.url}`
}
]
}))
})
}
],
messageParamsJson: ''
}
};

const message = {interactiveMessage: interactiveMessage};

conn.relayMessage(m.chat, { viewOnceMessage: { message } }, {});

} else {
const datas = global;
const idioma = datas.db.data.users[m.sender].language;
const _translate = JSON.parse(fs.readFileSync(`./language/${idioma}.json`));
const traductor = _translate.plugins.buscador_yts;
const results = await yts(text);
const tes = results.all;
const teks = results.all.map((v) => {
switch (v.type) {
case 'video': return `
Β° *_${v.title}_*
↳ 🫐 *_${traductor.texto2[0]}_* ${v.url}
↳ πŸ•’ *_${traductor.texto2[1]}_* ${v.timestamp}
↳ πŸ“₯ *_${traductor.texto2[2]}_* ${v.ago}
↳ πŸ‘ *_${traductor.texto2[3]}_* ${v.views}`;
}
}).filter((v) => v).join('\n\nβ—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦\n\n');
conn.sendFile(m.chat, tes[0].thumbnail, 'yts.jpeg', teks, m);
}
};
handler.help = ['ytsearch <texto>'];
handler.tags = ['search'];
handler.command = /^(ytsearch|yts|searchyt|buscaryt|videosearch)$/i;
export default handler;

/*import yts from 'yt-search';
import fs from 'fs';
const handler = async (m, {conn, text}) => {
const datas = global
const idioma = datas.db.data.users[m.sender].language
Expand All @@ -25,4 +115,4 @@ const handler = async (m, {conn, text}) => {
handler.help = ['ytsearch *<texto>*'];
handler.tags = ['search'];
handler.command = ['ytsearch', 'yts'];
export default handler;
export default handler;*/

0 comments on commit e9edab1

Please sign in to comment.