| const axios = require("axios"); |
| const yts = require("yt-search"); |
| const fs = require("fs"); |
|
|
| let handler = async (m, { conn, usedPrefix, command, text }) => { |
| |
| if (!text) { |
| throw `*• Contoh :* ${usedPrefix + command} *<query>*`; |
| } |
|
|
| m.reply("Tunggu sebentar..."); |
|
|
| let videoUrl; |
|
|
| |
| let result = await yts(text); |
| videoUrl = result.videos[0]?.url; |
| if (!videoUrl) { |
| return m.reply("Tidak ada video ditemukan dengan pencarian tersebut."); |
| } |
|
|
| |
| const encodedUrl = encodeURIComponent(videoUrl); |
| const apiUrl = `https://Ikygantengbangetanjay-api.hf.space/yt?query=${encodedUrl}`; |
|
|
| try { |
| console.log(`Mengirim permintaan ke API: ${apiUrl}`); |
| let response = await axios.get(apiUrl); |
| console.log(`Respons dari API:`, response.data); |
|
|
| let data = response.data; |
|
|
| |
| if (!data.success || !data.result) { |
| return m.reply("Tidak ada hasil ditemukan."); |
| } |
|
|
| let videoData = data.result; |
| let cap = `*乂 Y T M P 3 - P L A Y*\n\n` + |
| `◦ Judul : ${videoData.title}\n` + |
| `◦ Link Video : ${videoData.url}\n` + |
| `◦ Durasi : ${videoData.timestamp}\n` + |
| `◦ Penulis : ${videoData.author.name}\n` + |
| `◦ Views : ${videoData.views}\n` + |
| `◦ Diunggah : ${videoData.ago}`; |
|
|
| await conn.sendMessage(m.chat, { text: cap }, { quoted: m }); |
|
|
| |
| const audioResponse = await axios.get(videoData.download.audio, { responseType: 'arraybuffer' }); |
| const audioBuffer = Buffer.from(audioResponse.data, 'binary'); |
|
|
| |
| const thumbnailResponse = await axios.get(videoData.thumbnail, { responseType: 'arraybuffer' }); |
| const thumbnailBuffer = Buffer.from(thumbnailResponse.data, 'binary'); |
|
|
| |
| await conn.sendMessage(m.chat, { |
| document: audioBuffer, |
| mimetype: 'audio/mpeg', |
| fileName: `${videoData.title}.mp3`, |
| caption: cap, |
| contextInfo: { |
| externalAdReply: { |
| title: "乂 Y T M P 3 - P L A Y", |
| body: videoData.title, |
| mediaType: 2, |
| sourceUrl: videoData.url, |
| mediaUrl: videoData.url, |
| thumbnailUrl: videoData.thumbnail || "", |
| renderLargerThumbnail: true |
| } |
| } |
| }, { quoted: m }); |
|
|
| } catch (error) { |
| console.error("Terjadi kesalahan:", error); |
| m.reply("Terjadi kesalahan saat mengunduh audio. Silakan periksa log untuk detail."); |
| } |
| } |
|
|
| handler.help = ["ytmp3", "yta", "play"].map(a => a + " *[query]*"); |
| handler.tags = ["downloader"]; |
| handler.command = ["ytmp3", "yta", "play"]; |
| handler.premium = 50 |
| module.exports = handler; |