mmm / plugins /fb-dl.js
ravenbs1's picture
Upload 140 files
046b271 verified
const axios = require("axios");
const { cmd } = require("../command");
cmd({
pattern: "fbdl",
alias: ["facebook", "fb"],
react: 'โฐ',
desc: "Download videos from Facebook.",
category: "download",
use: ".fbdl <Facebook video URL>",
filename: __filename
}, async (conn, mek, m, { from, reply, args }) => {
try {
// Check if the user provided a Facebook video URL
const fbUrl = args[0];
if (!fbUrl || !fbUrl.includes("facebook.com")) {
return reply('*๐โ„“ั”ฮฑส‚ั” ๐ษผเนฮฝฮนษ–ั” ๐€ fbา‡ ๐•ฮนษ–ั”เน เนษผ ษผั”ั”โ„“ ๐”ษผโ„“..*');
}
// Add a reaction to indicate processing
await conn.sendMessage(from, { react: { text: 'โณ', key: m.key } });
// Prepare the API URL
const apiUrl = `https://apis.davidcyriltech.my.id/facebook2?url=${encodeURIComponent(fbUrl)}`;
// Call the API using GET
const response = await axios.get(apiUrl);
// Check if the API response is valid
if (!response.data || !response.data.status || !response.data.video) {
return reply('โŒ Unable to fetch the video. Please check the URL and try again.');
}
// Extract the video details
const { title, thumbnail, downloads } = response.data.video;
// Get the highest quality download link (HD or SD)
const downloadLink = downloads.find(d => d.quality === "HD")?.downloadUrl || downloads[0].downloadUrl;
// Inform the user that the video is being downloaded
// await reply('```Downloading video... Please wait.๐Ÿ“ฅ```');
// Download the video
const videoResponse = await axios.get(downloadLink, { responseType: 'arraybuffer' });
if (!videoResponse.data) {
return reply('โŒ Failed to download the video. Please try again later.');
}
// Prepare the video buffer
const videoBuffer = Buffer.from(videoResponse.data, 'binary');
// Send the video with details
await conn.sendMessage(from, {
video: videoBuffer,
caption: `*๐ŸซŸ๐€ษญฤซฤซ ๐ŒฦŠ ๐ƒ๐Ž๐–๐๐‹๐Ž๐€๐ƒ๐„๐ƒ*\n\n` +
`๐Ÿ”– *TITLE*: ${title}\n` +
`๐Ÿ“ *QUALITY*: ${downloads.find(d => d.quality === "HD") ? "HD" : "SD"}\n\n` +
`> *ยฉ แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด€สŸษช*`,
contextInfo: {
mentionedJid: [m.sender],
forwardingScore: 999,
isForwarded: true,
forwardedNewsletterMessageInfo: {
newsletterJid: '120363318387454868@newsletter',
newsletterName: 'ใ€Ž ๐€ษญฤซฤซ ๐ŒฦŠ ๐…๐ ๐ƒ๐‹ ใ€',
serverMessageId: 143
}
}
}, { quoted: mek });
// Add a reaction to indicate success
await conn.sendMessage(from, { react: { text: 'โœ…', key: m.key } });
} catch (error) {
console.error('Error downloading video:', error);
reply('โŒ Unable to download the video. Please try again later.');
// Add a reaction to indicate failure
await conn.sendMessage(from, { react: { text: 'โŒ', key: m.key } });
}
});