bifm/extractors/mboost.js
2022-06-26 23:12:27 -04:00

54 lines
1.7 KiB
JavaScript

const axios = require("axios");
const cheerio = require("cheerio");
const lib = require("../lib");
module.exports = {
hostnames: ["mboost.me"],
requiresCaptcha: false,
get: async function(url, opt) {
try {
if (lib.config().debug == true) console.log("[mboost] Requesting page...");
let h = lib.config().defaults?.axios.headers;
if (opt.referer) {
h.Referer = opt.referer;
}
let proxy;
if (lib.config().defaults?.axios.proxy) {
if (lib.config().defaults?.axios.proxy?.type == "socks5") {
const agent = require("socks-proxy-agent");
let prox = `socks5://${lib.config().defaults?.axios.proxy?.host}:${lib.config().defaults?.axios.proxy?.port}`;
proxy = {httpsAgent: (new agent.SocksProxyAgent(prox))};
} else {
proxy = {};
}
}
let resp = await axios({
method: "GET",
url: url,
headers: h,
...proxy
});
let $ = cheerio.load(resp.data);
if (lib.config().debug == true) console.log("[mboost] Got page. Parsing page...");
if ($("#__NEXT_DATA__")) {
if (lib.config().debug == true) console.log(`[mboost] Parsed page. Parsing JSON "__NEXT_DATA__" information...`);
let d = $("#__NEXT_DATA__")[0]?.children[0]?.data;
d = JSON.parse(d);
if (lib.config().debug == true) console.log("[mboost] Parsed JSON. Retrieving URL...");
if (lib.isUrl(d.props?.initialProps?.pageProps?.data?.targeturl)) {
return d.props?.initialProps?.pageProps?.data?.targeturl;
}
throw "Redirect not found.";
} else {
throw "Redirect not found.";
}
} catch(err) {
throw err;
}
}
}