const axios = require('axios'); async function getStreamFromURL(url) { const response = await axios.get(url, { responseType: 'stream' }); return response.data; } async function fetchCarEditVideos(query) { try { const response = await axios.get( `https://lyric-search-neon.vercel.app/kshitiz?keyword=${encodeURIComponent(query)}` ); return response.data; } catch (error) { console.error("❌ | API Fetch Error:", error.message); return null; } } module.exports = { config: { name: "car", aliases: ["cars", "caredit", "carvid"], author: "Alim", version: "1.4", role: 0, shortDescription: { en: "Get car edit videos only", }, longDescription: { en: "Fetches short car aesthetic/cinematic edit videos. If no match found, sends a random one under 1 minute.", }, category: "media", guide: { en: "{pn} [optional keyword]", }, }, onStart: async function ({ api, event, args }) { const query = args.join(" ") || "car edit"; api.setMessageReaction("🚗", event.messageID, () => {}, true); const videos = await fetchCarEditVideos(query); if (!videos || videos.length === 0) { return api.sendMessage(`❌ | Couldn't fetch videos. Try again later.`, event.threadID, event.messageID); } // Filter only car-related videos const isCarEdit = v => { const title = v.title?.toLowerCase() || ""; const desc = v.description?.toLowerCase() || ""; const match = /car\s*edit|supercar|civic|gtr|bmw|lamborghini|drift|aesthetic\s*car/i; return match.test(title) || match.test(desc); }; const short = v => v.duration && Number(v.duration) < 60; const filtered = videos.filter(v => isCarEdit(v) && short(v)); const finalList = filtered.length > 0 ? filtered : videos.filter(short); if (finalList.length === 0) { return api.sendMessage(`❌ | No suitable video found.`, event.threadID, event.messageID); } const selected = finalList[Math.floor(Math.random() * finalList.length)]; const videoUrl = selected.videoUrl; if (!videoUrl) { return api.sendMessage("⚠️ | Video URL missing.", event.threadID, event.messageID); } try { const stream = await getStreamFromURL(videoUrl); await api.sendMessage({ body: `• 𝐇𝐞𝐫𝐞 𝐢𝐬 𝐲𝐨𝐮𝐫 𝐂𝐚𝐫 𝐯𝐢𝐝𝐞𝐨 <😘`, attachment: stream, }, event.threadID, event.messageID); } catch (err) { console.error("❌ | Stream Error:", err.message); api.sendMessage("⚠️ | Failed to send video.", event.threadID, event.messageID); } }, };