From e9edab15ddb784b2818cf0a33bfd515335181d6c Mon Sep 17 00:00:00 2001 From: BrunoSobrino <90165013+BrunoSobrino@users.noreply.github.com> Date: Sat, 27 Apr 2024 11:47:14 -0600 Subject: [PATCH] Update buscador-yts.js --- plugins/buscador-yts.js | 92 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/plugins/buscador-yts.js b/plugins/buscador-yts.js index afbcd39a84..5768d08382 100644 --- a/plugins/buscador-yts.js +++ b/plugins/buscador-yts.js @@ -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: `**\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 ']; +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 @@ -25,4 +115,4 @@ const handler = async (m, {conn, text}) => { handler.help = ['ytsearch **']; handler.tags = ['search']; handler.command = ['ytsearch', 'yts']; -export default handler; +export default handler;*/