Path: blob/master/node_modules/@bochilteam/scraper/lib/cjs/social-media/facebook.js
1126 views
"use strict";1var __importDefault = (this && this.__importDefault) || function (mod) {2return (mod && mod.__esModule) ? mod : { "default": mod };3};4Object.defineProperty(exports, "__esModule", { value: true });5exports.facebookdlv3 = exports.facebookdlv2 = exports.facebookdl = void 0;6const cheerio_1 = __importDefault(require("cheerio"));7const got_1 = __importDefault(require("got"));8const crypto_js_1 = require("../encryptions/crypto.js");9const utils_js_1 = require("../utils.js");10// only support download video yet11async function facebookdl(url) {12/* eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"] */13const { data: { id, thumbnail, duration, a, av, v } } = await (0, got_1.default)('https://youtube4kdownloader.com/ajax/getLinks.php', {14headers: {15'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'16},17searchParams: {18video: url,19rand: (0, crypto_js_1.randomBytes)(13)20}21}).json();22const result = (a || [])23.concat(av)24.concat(v)25.map(({ size, ext, url, quality, vcodec, fid }) => {26const isVideo = ext === 'mp4';27const isWebm = ext === 'webm';28return {29size,30ext,31url,32quality,33vcodec,34fid,35isVideo: isVideo || isWebm,36isAudio: /audio/i.test(quality || '') || (isVideo && !isWebm)37};38// ext webm video without audio39});40if (!result.length)41throw new utils_js_1.ScraperError(`Can't download!\n${JSON.stringify({ id, thumbnail, duration, a, av, v }, null, 2)}`);42return {43id,44thumbnail,45duration,46result47};48}49exports.facebookdl = facebookdl;50async function facebookdlv2(url) {51var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;52const params = {53url: encodeURI(url)54};55const res = await got_1.default56.post('https://snapsave.app/action.php', {57headers: {58accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',59'accept-encoding': 'gzip, deflate, br',60'accept-language': 'en-US,en;q=0.9',61'content-type': 'application/x-www-form-urlencoded',62origin: 'https://snapsave.app',63referer: 'https://snapsave.app/',64'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/96.0.4664.110 Safari/537.36'65},66form: params67}).text();68const decodeParams = (_b = (_a = res.split('))</script>')[0]69.split('decodeURIComponent(escape(r))}(')[1]) === null || _a === void 0 ? void 0 : _a.split(',')) === null || _b === void 0 ? void 0 : _b.map(v => v.replace(/^"/, '')70.replace(/"$/, '').trim());71let html;72if (!Array.isArray(decodeParams) || decodeParams.length !== 6)73html = (_c = (typeof res === 'string' ? JSON.parse(res) : res)) === null || _c === void 0 ? void 0 : _c.data;74else {75const decode = (0, utils_js_1.decodeSnapApp)(...decodeParams);76html = (_j = (_h = (_g = (_f = (_e = (_d = decode === null || decode === void 0 ? void 0 : decode.split('("download-section").innerHTML = "')[1]) === null || _d === void 0 ? void 0 : _d.split('; parent.document.getElementById("inputData").remove();')[0]) === null || _e === void 0 ? void 0 : _e.split('</style><section class=')[1].split('"> ')) === null || _f === void 0 ? void 0 : _f.slice(1)) === null || _g === void 0 ? void 0 : _g.map(v => (v + '">').trim()).join()) === null || _h === void 0 ? void 0 : _h.split('</section><div class=')[0]) === null || _j === void 0 ? void 0 : _j.replace(/\\(\\)?/g, '');77}78if (!html)79throw new utils_js_1.ScraperError(`Can't parse encode params!\n${res}`);80const result = [];81const $ = cheerio_1.default.load(html);82$('table.table > tbody > tr').each(function () {83var _a, _b;84const el = $(this).find('td');85if (/tidak|no/i.test(el.eq(1).text())) {86const quality = (_b = (_a = el.eq(0).text().split('(')) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.trim();87const url = el.eq(2).find('a[href]').attr('href');88if (url)89result.push({ quality, url });90}91});92if (!result.length)93throw new utils_js_1.ScraperError(`Can't download!\n${$.html()}`);94return {95id: ((_l = (_k = $('div.media-content > div.content > p > strong')96.text()97.split('#')) === null || _k === void 0 ? void 0 : _k[1]) === null || _l === void 0 ? void 0 : _l.trim()) || '',98title: $('div.media-content > div.content > p > strong').text(),99description: $('div.media-content > div.content > p > span.video-des').text(),100thumbnail: $('figure > p.image > img[src]').attr('src'),101result102};103}104exports.facebookdlv2 = facebookdlv2;105async function facebookdlv3(url) {106var _a;107const payload = {108url109};110const text = await (0, got_1.default)('https://www.getfvid.com/downloader', {111method: 'POST',112headers: {113accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',114'accept-encoding': 'gzip, deflate, br',115'accept-language': 'en-US,en;q=0.9',116'content-type': 'application/x-www-form-urlencoded',117cookie: '_ga=GA1.2.887753826.1642391325; _gid=GA1.2.2022692773.1642391325; __gads=ID=4ea88e3817c8d71b-22332defffcf0045:T=1642391326:RT=1642391326:S=ALNI_MY3oJyiEG_b8KXZBJ7RqvN2Mn8wbw; XSRF-TOKEN=eyJpdiI6ImdNUElWWU83S01jOTdZeitCUWdkWXc9PSIsInZhbHVlIjoiTGxnaE9oRVJTKzA5NDBncUtBa0xEdCtqNHBJXC9ZMVFPR1U2RnBSYUFzZHltWElZS2VtVUltUTJ2TjB5V3pEeTYzRUNMcENjMURGSkhBXC9OUitpcjMrZz09IiwibWFjIjoiMTViZTNjZDI3ZTZmOTk2ZWRjOWM1NTA5MTU2NDFhYWFlMjIxNTQxZTJlYjliMjJiMzE3YzlkNGMxODc2NjhmMCJ9; laravel_session=eyJpdiI6IjhZbElIRmpLSkVqZGZpQXJoK2MzVHc9PSIsInZhbHVlIjoianBSSFhPb2t0RFY4Q1wvYkk1S3pxMUNxXC82b0U1NHZROTVpS1Z4dGhES3ZTYTNsenJUSXpwcWNMVDkwWFk4OUY1TitGNmlDK1RXbTVyREVzcHVoRnRidz09IiwibWFjIjoiY2U1YzI2ODZlYWI2NzFkZDU1NTQ5Zjk0M2NmMDc2MTZhY2M3ODQxYjljZGUzMDQwMTYxZGQwZGYxMDM3NDMyZSJ9; __cf_bm=ephRNXRqwgrTB4SmHlsudy886EfsR2Ns2KtXVBnph4I-1642392732-0-AXtTUW5HRNQUeUcTJPhJTOPlMcjBFmMyoLKYOnxrDZ6Fa06XaJ4pMNW9arLg4zco/ef+ji00IV8NZb0nGOAKgfg=; _gat=1; __atuvc=6%7C3; __atuvs=61e4e71d2b803588005; __atssc=google%3B3',118origin: 'https://www.getfvid.com',119referer: 'https://www.getfvid.com/',120'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'121},122form: payload123}).text();124const $ = cheerio_1.default.load(text);125const row = $('div.card > div.row > div');126const thumbnail = (_a = /background-image: url\((.*?)\);/i.exec(row.eq(0).find('a[href]').attr('style'))) === null || _a === void 0 ? void 0 : _a[1];127const result = [];128row.find('.btns-download > p > a[href]').each(function () {129var _a;130const el = $(this);131const url = el.attr('href');132const info = el.text().trim();133const isAudio = /audio/i.test(info);134const quality = isAudio ? 'audio' : (_a = /Download in (\w+) Quality/i.exec(info)) === null || _a === void 0 ? void 0 : _a[1];135const isVideo = quality !== 'audio';136if (url) {137result.push({138url,139quality,140isAudio,141isVideo142});143}144});145if (!result.length)146throw new utils_js_1.ScraperError(`Can't download!\n${$.html()}`);147return {148title: $('#title_video').val(),149thumbnail,150result151};152}153exports.facebookdlv3 = facebookdlv3;154//# sourceMappingURL=facebook.js.map155156