| |
| import axios from "axios"; |
| import cheerio from "cheerio"; |
| function CreateInstance(headers, config) { |
| return axios.create({ |
| headers: { |
| "User-Agent": "Frieren-Scraper (0.0.1x)", |
| ...headers, |
| }, |
| ...config, |
| }); |
| } |
| const Axios = CreateInstance(); |
| function Cheerio(data) { |
| return cheerio.load(data); |
| } |
| const FacebookDownloadBaseUrls = { |
| v1: "https://getmyfb.com", |
| }; |
| async function fb(url) { |
| try { |
| const { data } = await Axios.request({ |
| url: FacebookDownloadBaseUrls.v1 + "/process", |
| method: "POST", |
| headers: { |
| ["accept"]: "*/*", |
| ["accept-language"]: "en-GB,en-US;q=0.9,en;q=0.8", |
| ["cache-control"]: "no-cache", |
| ["content-type"]: "application/x-www-form-urlencoded; charset=UTF-8", |
| ["hx-current-url"]: FacebookDownloadBaseUrls.v1 + "/", |
| ["hx-request"]: "true", |
| ["hx-target"]: "target", |
| ["hx-trigger"]: "form", |
| ["pragma"]: "no-cache", |
| ["Referer"]: FacebookDownloadBaseUrls.v1 + "/", |
| ["Referrer-Policy"]: "strict-origin-when-cross-origin", |
| }, |
| data: new URLSearchParams({ |
| id: decodeURIComponent(url), |
| locale: "en", |
| }), |
| }).catch((e) => e?.response); |
| const $ = Cheerio(data); |
| const title = $(".results-item-text") |
| .text() |
| .replace(/\s{2,}/g, "") |
| .replace(/[\t\n]/g, ""); |
| const _temp = []; |
| $(".results-download > ul > li").each((i, e) => { |
| const _rawType = $(e).find("a").attr("download"); |
| const _url = $(e).find("a").attr("href"); |
| if (/sd/i.test(_rawType)) { |
| _temp.push({ sd: _url }); |
| } |
| if (/hd/i.test(_rawType)) { |
| _temp.push({ hd: _url }); |
| } |
| }); |
| if (Array.isArray(_temp) && _temp.length) { |
| let isHdAvailable = false; |
| _temp.forEach((v) => { |
| if (v.hd) { |
| isHdAvailable = true; |
| } |
| }); |
| return { title, isHdAvailable, urls: _temp }; |
| } |
| else { |
| throw new Error("Empty video urls source!"); |
| } |
| } |
| catch (e) { |
| return { error: true, message: String(e) }; |
| } |
| } |
|
|
| export { |
| fb |
| } |