// code from goatstore // api: https://store.agi.bd const a = require("axios"); const b = require("fs"); const c = require("path"); const d = require("yt-search"); const nix = "https://raw.githubusercontent.com/aryannix/stuffs/master/raw/apis.json"; module.exports = { config: { name: "play", aliases: ["song", "music", "sing"], version: "0.0.1", author: "Jihad Hasan", countDown: 5, role: 0, shortDescription: "Play song", longDescription: "Search and download music from YouTube", category: "MUSIC", guide: "/play " }, onStart: async function ({ api: e, event: f, args: g }) { if (!g.length) return e.sendMessage( "❌ Provide a song name or YouTube URL.", f.threadID, f.messageID ); let baseApi; const i = await e.sendMessage( "🎵 ᴘʟᴇᴀsᴇ ᴡᴀɪᴛ sɪʀ ...........", f.threadID, null, f.messageID ); try { const configRes = await a.get(nix); baseApi = configRes.data && configRes.data.api; if (!baseApi) throw new Error("Configuration Error: Missing API in GitHub JSON."); } catch (error) { e.unsendMessage(i.messageID); return e.sendMessage( "❌ Failed to fetch API configuration from GitHub.", f.threadID, f.messageID ); } const h = g.join(" "); try { let j; if (h.startsWith("http")) { j = h; } else { const k = await d(h); if (!k || !k.videos.length) throw new Error("No results found."); j = k.videos[0].url; } const l = `${baseApi}/play?url=${encodeURIComponent(j)}`; const m = await a.get(l); const n = m.data; if (!n.status || !n.downloadUrl) throw new Error("API failed to return download URL."); const o = `${n.title}.mp3`.replace(/[\\/:"*?<>|]/g, ""); const p = c.join(__dirname, o); const q = await a.get(n.downloadUrl, { responseType: "arraybuffer" }); b.writeFileSync(p, q.data); await e.sendMessage( { attachment: b.createReadStream(p), body: `ᴊɪʜᴀᴅ ʜᴀsᴀɴ🎀 ${n.title}` }, f.threadID, () => { if (b.existsSync(p)) b.unlinkSync(p); e.unsendMessage(i.messageID); }, f.messageID ); } catch (r) { console.error(r); e.sendMessage( `❌ Failed to download song: ${r.message}`, f.threadID, f.messageID ); e.unsendMessage(i.messageID); } } };