UNPKG

@xct007/frieren-scraper

Version:
63 lines (62 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.v1 = void 0; const Utils_1 = require("../Utils"); const Constant_1 = require("../Constant"); async function v1(url) { try { const { data } = await Utils_1.Axios.request({ url: Constant_1.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"]: Constant_1.FacebookDownloadBaseUrls.v1 + "/", ["hx-request"]: "true", ["hx-target"]: "target", ["hx-trigger"]: "form", ["pragma"]: "no-cache", ["Referer"]: Constant_1.FacebookDownloadBaseUrls.v1 + "/", ["Referrer-Policy"]: "strict-origin-when-cross-origin", }, data: new URLSearchParams({ id: decodeURIComponent(url), locale: "en", }), }).catch((e) => e?.response); const $ = (0, Utils_1.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) }; } } exports.v1 = v1;