// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs-extra"); const path = require("path"); const baseApiUrl = async () => { const res = await axios.get( "https://raw.githubusercontent.com/mahmudx7/HINATA/main/baseApiUrl.json" ); return res.data.mahmud; }; module.exports = { config: { name: "video", aliases: ["v"], version: "2.8", author: "๐Œ๐™ดสœ๐„แด…๐ˆ", countDown: 10, role: 0, description: { en: "Download video from YouTube by name or link" }, category: "media", guide: { en: "{pn} " } }, langs: { en: { noInput: "ร— Baby, please provide a video name or link!", noResult: "ร— No results found.", success: "๐Ÿคก ๐‡๐ž๐ซ๐ž ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐๐ž๐ ๐•๐ข๐๐ž๐จ\n" + "๐“†ฉโ™ก๐“†ช ๐„๐ง๐ฃ๐จ๐ฒ ๐–๐š๐ญ๐œ๐ก๐ข๐ง๐  ๐“†ฉโ™ก๐“†ช\n" + "๐Ÿ‘‘ ๐Ž๐ฐ๐ง๐ž๐ซ โ™ก๐Œ๐™ดสœ๐„แด…๐ˆโ™ก", error: "ร— API error: %1" } }, onStart: async function ({ api, event, args, message, getLang }) { const input = args.join(" ").trim(); if (!input) { return message.reply(getLang("noInput")); } let filePath; try { api.setMessageReaction( "๐Ÿค", event.messageID, () => {}, true ); const apiUrl = await baseApiUrl(); const checkurl = /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=|shorts\/))((\w|-){11})(?:\S+)?$/; let videoID; if (checkurl.test(input)) { videoID = input.match(checkurl)[1]; } else { const searchRes = await axios.get( `${apiUrl}/api/ytb/search?q=${encodeURIComponent(input)}` ); const results = searchRes.data?.results; if (!results || results.length === 0) { api.setMessageReaction( "๐Ÿฅน", event.messageID, () => {}, true ); return message.reply(getLang("noResult")); } videoID = results[0].id; } const cacheDir = path.join(__dirname, "cache"); await fs.ensureDir(cacheDir); filePath = path.join( cacheDir, `video_${Date.now()}.mp4` ); const res = await axios.get( `${apiUrl}/api/ytb/get?id=${encodeURIComponent(videoID)}&type=video` ); const downloadLink = res.data?.data?.downloadLink; if (!downloadLink) { throw new Error("Download link not found"); } const response = await axios.get(downloadLink, { responseType: "stream" }); await new Promise((resolve, reject) => { const writer = fs.createWriteStream(filePath); response.data.pipe(writer); writer.on("finish", resolve); writer.on("error", reject); response.data.on("error", reject); }); await new Promise((resolve, reject) => { message.reply( { body: getLang("success"), attachment: fs.createReadStream(filePath) }, err => { if (err) reject(err); else resolve(); } ); }); api.setMessageReaction( "โœ…", event.messageID, () => {}, true ); } catch (err) { console.error("Video command error:", err); api.setMessageReaction( "โŒ", event.messageID, () => {}, true ); return message.reply( getLang("error", err.message || "Download failed") ); } finally { if (filePath && await fs.pathExists(filePath)) { await fs.remove(filePath).catch(() => {}); } } } };