Facebook
From Mesbah, 2 Months ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 219
  1. const axios = require("axios");
  2. const cheerio = require("cheerio");
  3. const dipto = require("tinyurl")
  4. module.exports = {
  5.   config: {
  6.     name: "fb",
  7.     version: "1.2",
  8.     author: "NTKhang",
  9.     countDown: 5,
  10.     role: 0,
  11.     shortDescription: {
  12.       vi: "Tải video từ facebook",
  13.       en: "Download video from facebook"
  14.     },
  15.     longDescription: {
  16.       vi: "Tải video/story từ facebook (công khai)",
  17.       en: "Download video/story from facebook (public)"
  18.     },
  19.     category: "?????",
  20.     guide: {
  21.       en: "   {pn} <url video/story>: tải video từ facebook"
  22.     }
  23.   },
  24.  
  25.   langs: {
  26.     vi: {
  27.       missingUrl: "Vui lòng nhập url video/story facebook (công khai) bạn muốn tải về",
  28.       error: "Đã xảy ra lỗi khi tải video",
  29.       downloading: "Đang tiến hành tải video cho bạn",
  30.       tooLarge: "Rất tiếc không thể tải video cho bạn vì dung lượng lớn hơn 83MB"
  31.     },
  32.     en: {
  33.       missingUrl: "⚠ Please enter the facebook video/story (public) url you want to download",
  34.       error: "❌ An error occurred while downloading the video",
  35.       downloading: "? Downloading video for you",
  36.       tooLarge: "? Sorry, we can't download the video for you because the size is larger than 83MB"
  37.     }
  38.   },
  39.  
  40.   onStart: async function ({ args, message, getLang }) {
  41.     if (!args[0])
  42.       return message.reply(getLang("missingUrl"));
  43.     const response = await fbDownloader(args[0]);
  44.     if (response.success === false)
  45.       return message.reply(getLang("error"));
  46.  
  47.     let success = false;
  48.     const msgSend = message.reply(getLang("downloading"));
  49.  
  50.     for (const item of response.download) {
  51.       const res = await axios({
  52.         url: item.url,
  53.         responseType: 'stream'
  54.       });
  55.       if (res.headers['content-length'] > 87031808)
  56.         continue;
  57.       res.data.path = global.utils.randomString(10) + '.mp4';
  58.       const dip = await dipto.shorten(item.url);
  59.       message.reply({
  60.         body: `=== [ ${item.quality} ] ===nnDownload Link:n${dip}`,
  61.         attachment: res.data
  62.       }, async () => message.unsend((await msgSend).messageID));
  63.       success = true;
  64.       break;
  65.     }
  66.  
  67.     if (!success) {
  68.       message.unsend((await msgSend).messageID);
  69.       return message.reply(getLang("tooLarge"));
  70.     }
  71.   }
  72. };
  73.  
  74.  
  75. async function fbDownloader(url) {
  76.   try {
  77.     const response1 = await axios({
  78.       method: 'POST',
  79.       url: 'https://snapsave.app/action.php?lang=en',
  80.       headers: {
  81.         "accept": "*/*",
  82.         "accept-language": "vi,en-US;q=0.9,en;q=0.8",
  83.         "content-type": "multipart/form-data",
  84.         "sec-ch-ua": ""Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"",
  85.         "sec-ch-ua-mobile": "?0",
  86.         "sec-ch-ua-platform": ""Windows"",
  87.         "sec-fetch-dest": "empty",
  88.         "sec-fetch-mode": "cors",
  89.         "sec-fetch-site": "same-origin",
  90.         "Referer": "https://snapsave.app/vn",
  91.         "Referrer-Policy": "strict-origin-when-cross-origin"
  92.       },
  93.       data: {
  94.         url
  95.       }
  96.     });
  97.  
  98.     let html;
  99.     const evalCode = response1.data.replace('return decodeURIComponent', 'html = decodeURIComponent');
  100.     eval(evalCode);
  101.     html = html.split('innerHTML = "')[1].split('";n')[0].replace(/\"/g, '"');
  102.  
  103.     const $ = cheerio.load(html);
  104.     const download = [];
  105.  
  106.     const tbody = $('table').find('tbody');
  107.     const trs = tbody.find('tr');
  108.  
  109.     trs.each(function (i, elem) {
  110.       const trElement = $(elem);
  111.       const tds = trElement.children();
  112.       const quality = $(tds[0]).text().trim();
  113.       const url = $(tds[2]).children('a').attr('href');
  114.       if (url != undefined) {
  115.         download.push({
  116.           quality,
  117.           url
  118.         });
  119.       }
  120.     });
  121.  
  122.     return {
  123.       success: true,
  124.       video_length: $("div.clearfix > p").text().trim(),
  125.       download
  126.     };
  127.   }
  128.   catch (err) {
  129.     return {
  130.       success: false
  131.     };
  132.   }
  133. }