File size: 2,504 Bytes
a2b2aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//import { Axios, Cheerio } from "../Utils.js";
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
}