(sock, message, args, context)
| 13 | description: 'Download Facebook videos', |
| 14 | usage: '.fb <facebook video link>', |
| 15 | async handler(sock, message, args, context) { |
| 16 | const chatId = context.chatId || message.key.remoteJid; |
| 17 | const url = args.join(' ') || |
| 18 | message.message?.conversation || |
| 19 | message.message?.extendedTextMessage?.text; |
| 20 | try { |
| 21 | if (!url) { |
| 22 | return await sock.sendMessage(chatId, { text: '📘 *Facebook Downloader*\n\nUsage:\n.fb <facebook video link>' }, { quoted: message }); |
| 23 | } |
| 24 | if (!/facebook\.com|fb\.watch/i.test(url)) { |
| 25 | return await sock.sendMessage(chatId, { text: '❌ Invalid Facebook link.\nPlease send a valid Facebook video URL.' }, { quoted: message }); |
| 26 | } |
| 27 | await sock.sendMessage(chatId, { |
| 28 | react: { text: '🔄', key: message.key } |
| 29 | }); |
| 30 | const apiUrl = `https://gtech-api-xtp1.onrender.com/api/download/fb?url=${encodeURIComponent(url)}&apikey=APIKEY`; |
| 31 | const res = await axios.get(apiUrl, AXIOS_DEFAULTS); |
| 32 | const videos = res?.data?.data?.data; |
| 33 | if (!res?.data?.status || !Array.isArray(videos) || !videos.length) { |
| 34 | throw new Error('No downloadable video found'); |
| 35 | } |
| 36 | const sorted = videos.sort((a, b) => { |
| 37 | const qa = parseInt(a.resolution, 10) || 0; |
| 38 | const qb = parseInt(b.resolution, 10) || 0; |
| 39 | return qb - qa; |
| 40 | }); |
| 41 | const selected = sorted[0]; |
| 42 | const videoUrl = selected.url.startsWith('http') |
| 43 | ? selected.url |
| 44 | : `https://gtech-api-xtp1.onrender.com${selected.url}`; |
| 45 | const caption = `📘 *Facebook Downloader* |
| 46 | 🎞 Quality: *${selected.resolution || 'Unknown'}* |
| 47 | |
| 48 | > *_Downloaded by MEGA-MD_*`; |
| 49 | await sock.sendMessage(chatId, { video: { url: videoUrl }, mimetype: 'video/mp4', caption }, { quoted: message }); |
| 50 | } |
| 51 | catch (err) { |
| 52 | console.error('Facebook downloader error:', err); |
| 53 | await sock.sendMessage(chatId, { text: '❌ Failed to download Facebook video. Please try again later.' }, { quoted: message }); |
| 54 | } |
| 55 | } |
| 56 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected