ShahriarAbidbd/SmartifyXBotPublic · Bot Template

Do Tasks Smartly with SmartifyX 😎

Utilitydownloaderyoutubeinstagramfacebookspoilercontent-protection
ProfileTelegram
25 commands2 envUpdated 1d agoCreated Jul 28, 2026
Back to folder

commands/Downloader/_fb.js

javascript · 141 lines

Raw
1/**#command2name: /fb3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12function cleanFBTitle(rawTitle) {13  if (!rawTitle) return {};14 15  let parts = rawTitle.split("|").map(p => p.trim());16  let stats = parts[0] || "";17  let title = parts[1] || rawTitle;18 19  let views = stats.match(/([\d.,]+)\s*(M|K)?\s*views/i)?.[0] || null;20  let reactions = stats.match(/([\d.,]+)\s*(M|K)?\s*reactions/i)?.[0] || null;21 22  return {23    title,24    views,25    reactions26  };27}28 29async function getFBVideo(link) {30 31  let a = await Bot.sendMessage("⏳ Downloading")32  let mid = a.result.message_id33 34  await Api.editMessageText({35    chat_id: chat.id,36    message_id: mid,37    text: "⏳ Downloading."38  })39 40 41  if (42    link.indexOf("facebook.com") === -1 &&43    link.indexOf("fb.watch") === -1 &&44    link.indexOf("fb.com") === -145  ) {46    Api.editMessageText({47      chat_id: chat.id,48      message_id: mid,49      text: "❗ Only Facebook URLs are supported."50    })51    return52  }53 54  let headers = {55    "Accept": "application/json",56    "Content-Type": "application/json",57    "Origin": "https://ytdownload.in",58    "Referer": "https://ytdownload.in/",59    "User-Agent": "Mozilla/5.0 (Android)"60  }61 62 63 64 65  let res = await HTTP.post({66    url: Bot.get("downloader_api"),67    headers: headers,68    body: {69      url: link,70      format: "mp4",71      quality: "1080p"72    }73  })74 75  await Api.editMessageText({76    chat_id: chat.id,77    message_id: mid,78    text: "⏳ Downloading.."79  })80 81  if (!res.ok || !res.data?.responseFinal) {82    Api.editMessageText({83      chat_id: chat.id,84      message_id: mid,85      text: "❌ Video not found or private."86    })87    return88  }89 90  await Api.editMessageText({91    chat_id: chat.id,92    message_id: mid,93    text: "⏳ Downloading..."94  })95 96  let r = res.data.responseFinal97 98 99  let video =100    r.videoUrl ||101    r.formats?.find(v => v.qualityLabel?.includes("HD"))?.url ||102    r.formats?.[0]?.url103 104  if (!video) {105    Api.editMessageText({106      chat_id: chat.id,107      message_id: mid,108      text: "❌ HD video not available."109    })110    return111  }112 113  let info = cleanFBTitle(r.title)114 115  let caption =116    "<b>" + (info.title || "Facebook Video") + "</b>\n\n" +117    (info.views ? "👁️ " + info.views + "\n" : "") +118    (info.reactions ? "❤️ " + info.reactions + "\n" : "")119 120  let name = user.first_name + (user.last_name ? " " + user.last_name : "")121 122  await Api.editMessageMedia({123    chat_id: chat.id,124    message_id: mid,125    media: {126      type: "video",127      media: video,128      caption: caption +129        `\n<blockquote><b>Downloaded by:</b> <a href="tg://user?id=${user.id}">${name}</a></blockquote>`,130      parse_mode: "HTML"131    }132  })133}134 135if (request.reply_to_message && request.reply_to_message.text) {136  getFBVideo(request.reply_to_message.text)137} else if (params) {138  getFBVideo(params)139} else {140  msg.reply("❗ Please provide a Facebook video link.")141}