yuzzoffc / PLAY V1 (NEW]
Play menggunakan YouTube Search berbasis node.js / javascript & Plugin ESM [@yuzzoffc]
APIJavaScript
37 views
Play menggunakan YouTube Search berbasis node.js / javascript & Plugin ESM [@yuzzoffc]
import axios from "axios";
const BASE_API = "https://api.youz.my.id";
const handler = async (m, { sock, text, usedPrefix, command }) => {
if (!text) return m.reply(`Contoh: ${usedPrefix}${command} Taylor Swift`);
await m.reply("🔍 Mencari audio...");
try {
const searchApi = `${BASE_API}/api/s/youtube?query=${encodeURIComponent(text)}`;
const { data: searchData } = await axios.get(searchApi, { timeout: 15000 });
if (!searchData?.status || !searchData?.result?.length) {
return m.reply("❌ Lagu tidak ditemukan!");
}
const video = searchData.result[0];
const videoUrl = video.url || video.link;
const title = video.title || "No title";
const thumbnail = video.thumbnail || video.image || null;
const audioApi = `${BASE_API}/api/downloader/ytmp3?url=${encodeURIComponent(videoUrl)}`;
const { data: audioData } = await axios.get(audioApi, { timeout: 30000 });
const audioUrl = audioData?.result?.url || audioData?.url;
if (!audioUrl) {
return m.reply("❌ Gagal mendapatkan link audio.");
}
const audioRes = await axios.get(audioUrl, { responseType: "arraybuffer", timeout: 60000 });
const buffer = Buffer.from(audioRes.data);
await sock.sendMessage(m.chat, {
audio: buffer,
mimetype: "audio/mpeg",
ptt: false,
contextInfo: {
externalAdReply: {
title: title,
body: `YouTube Play`,
thumbnailUrl: thumbnail,
mediaType: 1,
renderLargerThumbnail: true,
sourceUrl: videoUrl
}
}
}, { quoted: m });
} catch (error) {
console.error(error);
m.reply(`❌ Error: ${error.response?.data?.error || error.message}`);
}
};
handler.command = ["ytplay", "play", "ytaudio"];
export default handler;