// code from goatstore // api: https://store.agi.bd const fs = require("fs-extra"); const path = require("path"); const ytSearch = require("yt-search"); const ytdl = require("@distube/ytdl-core"); module.exports = { config: { name: "sing2", version: "1.0", author: "Shakib", countDown: 10, role: 0, description: { en: "Search a song and send it as audio" }, category: "media", guide: { en: "{pn} " } }, onStart: async function ({ message, args }) { const query = args.join(" "); if (!query) return message.reply("Gaan er naam likho. Example: sing2 tum hi ho"); const dir = path.join(__dirname, "cache"); const file = path.join(dir, Date.now() + ".mp3"); try { const res = await ytSearch(query); const video = res.videos[0]; if (!video) return message.reply("Kono gaan pawa jayni."); if (video.seconds > 600) return message.reply("Gaan ta 10 minute er beshi lomba."); fs.ensureDirSync(dir); await new Promise((resolve, reject) => { const stream = ytdl(video.url, { filter: "audioonly", quality: "lowestaudio" }); const out = fs.createWriteStream(file); stream.on("error", reject); out.on("error", reject); out.on("finish", resolve); stream.pipe(out); }); await message.reply({ body: "🎵 " + video.title, attachment: fs.createReadStream(file) }); fs.removeSync(file); } catch (err) { console.error(err); fs.removeSync(file); return message.reply("Gaan ta pathate parlam na, abar chesta koro."); } } };