selfdebrid/extractors/bowfile.js
2022-08-21 20:03:32 -04:00

56 lines
1.7 KiB
JavaScript

const axios = require("axios");
const cheerio = require("cheerio");
const scp = require("set-cookie-parser");
const lib = require("../lib");
module.exports = {
get: get,
hostnames: ["bowfile.com"],
tests: []
};
async function get(url, options) {
lib.log(`bowfile`, `Fetching page...`, [], true, options);
let resp = await axios({
url: url,
headers: lib.defaultHeaders
});
lib.log(`bowfile`, `Parsing page...`);
let $ = cheerio.load(resp.data);
let dlScript = $("body > script:not([src]):not([type])").text();
let fileName = $(".download-page > div.text-center > h2").text().split(`\n`).join(``).split(`\t`).join(``);
let dlPage = dlScript?.split(`let next = "`)?.[1]?.split(`";`)?.[0];
let cookie = lib.cookieToString(scp.parse(resp.headers["set-cookie"]));
if (dlPage) {
lib.log(`bowfile`, `Waiting 20 seconds to navigate to the download page (yes, this is required)...`, [], true, options);
await lib.countdown((20 * 1000), options);
lib.log(`bowfile`, `Fetching download page...`, [], true, options);
let headers = lib.defaultHeaders;
headers["Cookie"] = cookie;
headers["Referer"] = url;
resp = await axios({
url: dlPage,
headers: headers
});
lib.log(`bowfile`, `Parsing download page...`);
let numericId = resp.data.split(`showFileInformation(`)?.[1]?.split(`)`)?.[0];
if (!numericId) throw new Error("Failed to get numeric ID for downloading.");
return {
axiosData: {
headers: headers,
url: `https://bowfile.com/account/direct_download/${numericId}`
},
metadata: {
fileName: fileName
}
};
} else throw new Error("Could not find download page URL.");
}