selfdebrid/extractors/hexupload.js
2022-08-16 20:16:33 -04:00

61 lines
1.6 KiB
JavaScript

const axios = require("axios");
const cheerio = require("cheerio");
const lib = require("../lib");
module.exports = {
get: get,
hostnames: ["hexupload.net"],
tests: []
}
async function get(url, options) {
lib.log(`hexupload`, `Setting up headers...`);
let id = new URL(url).pathname.substring(1).split("/")[0].split("?")[0];
let headers = lib.defaultHeaders;
headers["Origin"] = "https://hexupload.net"
headers["Referer"] = url;
headers["Content-Type"] = "application/x-www-form-urlencoded";
lib.log(`hexupload`, `Got headers:`, [headers]);
lib.log(`hexupload`, `Setting up request body...`);
let body = `op=download2&id=${id}&rand=&method_free=Free+Download&method_premium=&adblock_detected=0`;
lib.log(`hexupload`, `Got request body:`, [body]);
lib.log(`hexupload`, `Fetching page...`, [], true, options);
let resp = await axios({
method: `POST`,
data: body,
url: url
});
lib.log(`hexupload`, `Parsing response...`);
let $ = cheerio.load(resp.data);
let dlName = $(".file_slot > tbody > tr > td > nobr > b").text();
let dlLink = $("#direct_link > a").attr("href");
if (
typeof dlName !== "string" ||
typeof dlLink !== "string"
) throw new Error("Could not get metadata properly. Check if the link is alive.");
let dlHeaders = lib.defaultHeaders;
dlHeaders["Referer"] = "https://hexupload.net/";
dlHeaders["Sec-Fetch-Site"] = "cross-site";
delete dlHeaders["Content-Type"];
delete dlHeaders["Origin"];
dlHeaders = JSON.parse(JSON.stringify(dlHeaders));
return {
axiosData: {
headers: dlHeaders,
url: dlLink
},
metadata: {
fileName: dlName
}
}
}