const axios = require("axios"); const fs = require("fs"); const path = require("path"); const FormData = require("form-data"); module.exports = { config: { name: "album", aliases: ["al"], version: "5.1.0", author: "Azadx69x", countDown: 2, role: 0, shortDescription: "š€š„š›š®š¦ š•š¢ššžšØ Random", longDescription: "Random album videos", category: "media" }, albumSystem: new Map(), albumBaseUrl: null, videoQueue: new Map(), async loadAlbumBaseUrl() { if (this.albumBaseUrl) return; try { const res = await axios.get( "https://raw.githubusercontent.com/ncazad/Azad69x/refs/heads/main/baseApiUrl.json" ); this.albumBaseUrl = res.data.album.replace(/\/$/, ""); console.log("Album API base URL loaded:", this.albumBaseUrl); } catch (e) { console.error("Failed to load album base URL:", e.message); this.albumBaseUrl = null; } }, async fetchAlbumVideo(category) { await this.loadAlbumBaseUrl(); if (!this.albumBaseUrl) return null; if (!this.videoQueue.has(category) || this.videoQueue.get(category).length === 0) { try { const res = await axios.get(`${this.albumBaseUrl}/api/album?category=${encodeURIComponent(category)}`); let videos = []; if (res.data?.url) videos.push(res.data.url); if (res.data?.videos?.length) videos = videos.concat(res.data.videos); if (!videos.length) return null; videos = this.shuffleArray(videos); this.videoQueue.set(category, videos); } catch (e) { console.error(`Failed to fetch video for ${category}:`, e.message); return null; } } const queue = this.videoQueue.get(category); const videoUrl = queue.shift(); this.videoQueue.set(category, queue); return videoUrl; }, shuffleArray(arr) { for (let i = arr.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [arr[i], arr[j]] = [arr[j], arr[i]]; } return arr; }, async uploadToCatbox(videoPath) { const form = new FormData(); form.append("reqtype", "fileupload"); form.append("fileToUpload", fs.createReadStream(videoPath)); const res = await axios.post("https://catbox.moe/user/api.php", form, { headers: form.getHeaders() }); fs.unlinkSync(videoPath); return res.data.trim(); }, onStart: async function ({ message, event, args }) { const displayNames = [ "š€š™š€šƒš—69š—š…š… 🐼","š€š§š¢š¦šž šŸ’«","š€šØš“ ⚔","š€š­š­š¢š­š®ššž 😼", "šššš›š² šŸ‘¶","š‚ššš­ 🐈","š‚šØš®š©š„šž šŸ’‘","šƒš«ššš šØš§šššš„š„ šŸ‰", "š…š„šØš°šžš« 🌺","š…šØšØš­š›ššš„š„ ⚽","š…š«šžšžš…š¢š«šž šŸ”„","š…š«š¢šžš§šš¬ šŸ«‚", "š…š®š§š§š² 🤣","š‡šØš«š§š² šŸ’¦","š‡šØš­ 🄵","šˆš¬š„ššš¦š¢šœ 😊", "š‹šØš…šˆ šŸŽ¶","š‹šØšÆšž šŸ’","š‹š²š«š¢šœš¬ šŸŽµ","š’ššš 😿" ]; const realCategories = [ "Azadx69xff","anime","aot","attitude","baby","cat","couple","dragonball", "flower","football","freefire","friends","funny","horny","hot","islamic", "lofi","love","lyrics","sad" ]; if (args[0] && args[0].toLowerCase() === "add" && args[1]) { const cat = args[1].toLowerCase(); if (!realCategories.includes(cat)) return message.reply("āŒ Invalid category name."); if (!this.albumSystem.has(event.senderID)) this.albumSystem.set(event.senderID, []); this.albumSystem.get(event.senderID).push(cat); return message.reply(`āœ… Album category "${cat}" added to your list.`); } const itemsPerPage = 10; const page = parseInt(args[0]) || 1; const totalPages = Math.ceil(displayNames.length / itemsPerPage); if (page < 1 || page > totalPages) return message.reply("āŒ Invalid page"); const startIndex = (page - 1) * itemsPerPage; const categoriesToShow = displayNames.slice(startIndex, startIndex + itemsPerPage); let text = "ā•­ā”€āš€š‹šš”šŒ š•šˆšƒš„šŽ š‹šˆš’š“āā”€ā•®\n\n"; categoriesToShow.forEach((cat, i) => text += `✦ ${i + 1}. ${cat}\n`); text += `\nā•°ā”€ā šššš šž : ${page}/${totalPages} āā”€ā•Æ\n`; text += "šŸ’¬ š‘šžš©š„š² šš š§š®š¦š›šžš« š­šØ š šžš­ šš šÆš¢ššžšØ 🐱"; const sent = await message.reply(text); global.GoatBot.onReply.set(sent.messageID, { commandName: "album", author: event.senderID, pageCategories: categoriesToShow.map((_, i) => realCategories[startIndex + i]), pageDisplayNames: categoriesToShow, messageID: sent.messageID }); }, onReply: async function ({ message, event, Reply }) { if (event.senderID !== Reply.author) return; const num = parseInt(event.body); if (isNaN(num)) return; const index = num - 1; const category = Reply.pageCategories[index]; const displayName = Reply.pageDisplayNames[index]; if (!category) return message.reply("āŒ Invalid number"); const videoUrl = await this.fetchAlbumVideo(category); if (!videoUrl) return message.reply(`āŒ No videos found for ${displayName}`); try { await message.unsend(Reply.messageID); } catch(e){} await message.reply({ body: `✨ š€š‹šš”šŒ š•šˆšƒš„šŽ 🌸\n\nšŸ“ š‚ššš­šžš šØš«š² : ${displayName}\n\n🐸 š„š§š£šØš² š˜šØš®š« š•š¢ššžšØ šŸ–¤`, attachment: await global.utils.getStreamFromURL(videoUrl) }); } };