@xct007/frieren-scraper
Version:
50 lines (49 loc) • 1.55 kB
JavaScript
import https from "https";
import { Axios, Cheerio } from "../Utils.js";
function isValidUrl(url) {
return /(https?:\/\/(.+?\.)?zippyshare\.com(\/[A-Za-z0-9\-\._~:\/\?#\[\]@!$&'\(\)\*\+,;\=]*)?)/gm.test(url);
}
async function download(url) {
if (!isValidUrl(url)) {
return {
error: true,
message: "Invalid URL!",
};
}
try {
const { data } = await Axios.get(url, {
httpsAgent: new https.Agent({ keepAlive: true }),
}).catch((e) => e?.response);
const $ = Cheerio(data);
const splitUrl = url.split("/");
const Regex = new RegExp(`(?<=dlbutton)(.*)(?=;)`, "gm");
const _match = data.match(Regex)[0].replace("').href = ", "");
const finalUrl = `${splitUrl[0]}//${splitUrl[2]}${eval(_match)}`;
const _temp = [];
$("div#lrbox > div.center > div > font").each((i, e) => {
const _rawText = $(e).text();
if (_rawText !== "You have requested the file:") {
_temp.push(_rawText.replace(/:/, ""));
}
});
let metadata = {};
_temp.forEach((e, i) => {
if (i % 2 === 0) {
Object.assign(metadata, {
[e.toLowerCase().trim()]: _temp[i + 1],
});
}
});
return {
...metadata,
["url"]: finalUrl,
};
}
catch (e) {
return {
error: true,
message: String(e),
};
}
}
export { download };