const axios = require("axios"); const fs = require("fs"); const baseApiUrl = async () => { const base = await axios.get("https://raw.githubusercontent.com/mahmudx7/exe/main/baseApiUrl.json"); return base.data.mahmud69; }; module.exports = { config: { name: "instagramdl", aliases: ["igdl", "instadl"], version: "1.7", author: "ajmaul", countDown: 10, role: 0, description: { bn: "ইনস্টাগ্রাম ভিডিও/রিলস ডাউনলোড করুন", en: "Download videos or Reels from Instagram" }, category: "media", guide: { bn: ' {pn} <লিংক>: ইনস্টাগ্রাম ভিডিও বা রিলসের লিংক দিন' + '\n অথবা ভিডিও লিংকে রিপ্লাই দিয়ে {pn} লিখুন' + '\n\nSupported Platforms:\n• Instagram / Reels', en: ' {pn} : Provide the Instagram video/Reels link' + '\n Or reply to a link with {pn}' + '\n\nSupported Platforms:\n• Instagram / Reels' } }, langs: { bn: { noLink: "× বেবি, একটি সঠিক ইনস্টাগ্রাম ভিডিও লিংক দাও অথবা লিংকে রিপ্লাই করো!", error: "× ভিডিও ডাউনলোড করতে সমস্যা হয়েছে: %1। প্রয়োজনে Contact Aizen।\n•WhatsApp: 01836298139" }, en: { noLink: "× Baby, please provide a valid Instagram video link or reply to one!", error: "× Download error: %1. Contact Aizen for help.\n•WhatsApp: 01836298139" } }, onStart: async function ({ api, message, args, event, getLang }) { const mahmud = args[0] || event.messageReply?.body; if (!mahmud || !mahmud.startsWith("http")) { return message.reply(getLang("noLink")); } if (!mahmud.includes("instagram.com")) { return message.reply(getLang("noLink")); } if (!fs.existsSync(__dirname + "/cache")) fs.mkdirSync(__dirname + "/cache"); const path = __dirname + `/cache/igdl_${Date.now()}.mp4`; try { api.setMessageReaction("🐤", event.messageID, () => {}, true); const base = await baseApiUrl(); const apiUrl = `${base}/api/download?url=${encodeURIComponent(mahmud)}`; const apiRes = await axios.get(apiUrl); if (!apiRes.data || !apiRes.data.result) { throw new Error("Failed to fetch video URL from API"); } const videoUrl = apiRes.data.result; const caption = apiRes.data.cp || "Downloaded Video"; const response = await axios({ method: 'get', url: videoUrl, responseType: 'arraybuffer' }); fs.writeFileSync(path, Buffer.from(response.data, "binary")); api.setMessageReaction("🪽", event.messageID, () => {}, true); return message.reply( { body: caption, attachment: fs.createReadStream(path) }, () => fs.unlinkSync(path) ); } catch (err) { console.error("Error in instagramdl command:", err); api.setMessageReaction("❎", event.messageID, () => {}, true); if (fs.existsSync(path)) fs.unlinkSync(path); return message.reply(getLang("error", err.message)); } } };