60 lines
1.4 KiB
JavaScript
60 lines
1.4 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: ["multiup.org"],
|
|
tests: []
|
|
}
|
|
|
|
async function get(url, options) {
|
|
let mirror = [];
|
|
|
|
lib.log(`multiup`, `Got URL:`, [url]);
|
|
lib.log(`multiup`, `Sending CSRF request...`, [], true, options);
|
|
let resp = await axios({
|
|
url,
|
|
headers: lib.defaultHeaders
|
|
});
|
|
|
|
let $ = cheerio.load(resp.data);
|
|
let csrf = $("[name='_csrf_token']").val();
|
|
lib.log(`multiup`, `Got CSRF:`, [csrf]);
|
|
let cookie = scp.parse(resp.headers);
|
|
|
|
|
|
lib.log(`multiup`, `Sending page request...`, [], true, options);
|
|
resp = await axios({
|
|
url: url.replace(`/download/`, `/en/mirror/`),
|
|
headers: lib.defaultHeaders,
|
|
data: `_csrf_token=${csrf}`
|
|
});
|
|
|
|
lib.log(`multiup`, `Parsing request...`);
|
|
$ = cheerio.load(resp.data);
|
|
let dlName;
|
|
|
|
for (let i in $(".col-md-4")) {
|
|
let url = $(".col-md-4 footer form input[name='link']")?.[i]?.attribs?.value;
|
|
if (!dlName) dlName = $(".col-md-4 footer form input[name='filename']")?.[i]?.attribs?.value;
|
|
|
|
|
|
if (url) {
|
|
let host = new URL(url).hostname;
|
|
if (host.split(`.`).length > 1) host = host.split(`.`).slice(host.split(`.`).length - 2).join(`.`);
|
|
|
|
mirror.push({
|
|
link: url,
|
|
host
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
type: "mirrorlist",
|
|
mirror,
|
|
dlName
|
|
}
|
|
} |