81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
const axios = require("axios");
|
|
const cheerio = require("cheerio");
|
|
const lib = require("../lib");
|
|
|
|
module.exports = {
|
|
get: get,
|
|
hostnames: ["1fichier.com"],
|
|
tests: []
|
|
};
|
|
|
|
async function get(url, options) {
|
|
lib.log(`1fichier`, `Fetching page...`, [], true, options);
|
|
|
|
let headers = lib.defaultHeaders;
|
|
if (options.cookieFile) headers["Cookie"] = lib.cookieToString(await lib.getCookies(options.cookieFile, "1fichier.com"));
|
|
|
|
let resp = await axios({
|
|
url: url,
|
|
headers: headers
|
|
});
|
|
|
|
lib.log(`1fichier`, `Parsing page...`);
|
|
|
|
let $ = cheerio.load(resp.data);
|
|
|
|
if ($("form > .ct_warn")?.[0]) {
|
|
let warnText = $("form > .ct_warn").text().split(`\n`).join(``).split(`\t`).join(``);
|
|
if (warnText.includes("must wait")) {
|
|
warnText = warnText.split(`Warning !`)?.[1]?.split(`must wait `)?.[2]?.split(`...`)?.[0];
|
|
lib.log(`1fichier`, `Waiting the required time to download the file...`, [], true, options);
|
|
if (warnText !== undefined) {
|
|
if (warnText.includes("minutes")) await lib.countdown(parseInt(warnText) * 60 * 1000);
|
|
} else throw new Error("Unable to parse time error.");
|
|
} else if (warnText.includes("one file at a time")) throw new Error("You can only download one file at a time, use a proxy to avoid this limit.");
|
|
}
|
|
|
|
let actionUrl = $("form").attr("action");
|
|
let adz = $("form > input[name=adz]").val();
|
|
|
|
lib.log(`1fichier`, `Got action URL:`, [actionUrl]);
|
|
lib.log(`1fichier`, `Got adz:`, [adz]);
|
|
|
|
let fileName = $("tbody > tr > td.normal:not(.titre)")?.[0]?.children?.[0]?.data;
|
|
|
|
if (!fileName || !actionUrl || !adz) throw new Error("File data could not be found.");
|
|
|
|
headers["Content-Type"] = `application/x-www-form-urlencoded`;
|
|
headers["Origin"] = `https://1fichier.com`;
|
|
headers["Referer"] = url;
|
|
|
|
let body = `adz=${adz}`;
|
|
|
|
resp = await axios({
|
|
method: `POST`,
|
|
data: body,
|
|
headers: headers,
|
|
url: actionUrl
|
|
});
|
|
|
|
$ = cheerio.load(resp.data);
|
|
let dlLink = $(".ok.btn-general.btn-orange")?.[0]?.attribs?.href;
|
|
|
|
if (!dlLink) throw new Error("Could not find direct download link.");
|
|
|
|
headers["Referer"] = actionUrl;
|
|
delete headers["Content-Type"];
|
|
delete headers["Origin"];
|
|
if (options.cookieFile) headers["Cookie"] = lib.cookieToString(await lib.getCookies(options.cookieFile, new URL(dlLink).hostname));
|
|
|
|
headers = JSON.parse(JSON.stringify(headers));
|
|
|
|
return {
|
|
axiosData: {
|
|
url: dlLink,
|
|
headers: headers
|
|
},
|
|
metadata: {
|
|
fileName: fileName
|
|
}
|
|
};
|
|
} |