45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const axios = require("axios");
|
|
const cheerio = require("cheerio");
|
|
const scp = require("set-cookie-parser");
|
|
const decryptDlc = require("decrypt-dlc");
|
|
const lib = require("./lib");
|
|
|
|
module.exports = {
|
|
get: get
|
|
}
|
|
|
|
async function get(url, options) {
|
|
lib.log("filecrypt", "Fetching page...", [], true, options);
|
|
|
|
let resp = await axios({
|
|
url: url,
|
|
headers: lib.defaultHeaders
|
|
});
|
|
|
|
lib.log("filecrypt", "Parsing page...");
|
|
let $ = cheerio.load(resp.data);
|
|
let cookies = lib.cookieToString(scp.parse(resp.headers["set-cookies"]));
|
|
let dlcBaseLink = `https://${new URL(url).hostname}/DLC/`;
|
|
|
|
let dlcLink = $(".dlcdownload")?.[0]?.attribs?.onclick;
|
|
if (dlcLink) {
|
|
dlcLink = dlcLink.split(`'`)[1].split(`'`)[0];
|
|
dlcLink = `${dlcBaseLink}${dlcLink}.dlc`;
|
|
|
|
lib.log("filecrypt", "Fetching DLC file...", [], true, options);
|
|
let headers = lib.defaultHeaders;
|
|
headers["Cookie"] = cookies;
|
|
headers["Referer"] = url;
|
|
|
|
let resp = await axios({
|
|
url: dlcLink,
|
|
headers: headers
|
|
});
|
|
|
|
lib.log("filecrypt", "Decrypting DLC file...");
|
|
let dlcContent = await decryptDlc.paste(resp.data);
|
|
lib.log("filecrypt", `Found ${dlcContent.length} links.`);
|
|
|
|
return dlcContent;
|
|
} else throw new Error("CAPTCHAs cannot be solved at the moment.");
|
|
} |