66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
const axios = require("axios");
|
|
const cheerio = require("cheerio");
|
|
const safeeval = require("safe-eval-2");
|
|
const lib = require("../lib");
|
|
|
|
module.exports = {
|
|
get: get,
|
|
hostnames: ["zippyshare.com"],
|
|
tests: ["https://www101.zippyshare.com/v/9r13YylA/file.html"]
|
|
}
|
|
|
|
async function get(url, options) {
|
|
lib.log(`zippyshare`, `Fetching page...`, [], true, options);
|
|
|
|
let headers = lib.defaultHeaders;
|
|
|
|
let resp = await axios({
|
|
url: url,
|
|
headers: headers
|
|
});
|
|
|
|
lib.log(`zippyshare`, `Parsing page...`);
|
|
let $ = cheerio.load(resp.data);
|
|
|
|
let dlButton = $("#lrbox #dlbutton")[0];
|
|
let dlScript = $("#lrbox script:not([src])").length;
|
|
|
|
if (dlButton && dlScript) {
|
|
|
|
for (let a in $("#lrbox script:not([src])")) {
|
|
let dlScript = $("#lrbox script:not([src])")?.[a]?.children?.[0]?.data;
|
|
dlScript = `(function () {var obj = {}; var etc = {}; \n${dlScript.split(`document.getElementById('dlbutton')`).join(`obj`).split(`document.getElementById('fimage')`).join(`etc`)}`;
|
|
dlScript = `${dlScript}\n if (somffunction) {somffunction()} return obj.href})();`;
|
|
|
|
if (!dlScript.includes(`somffunction = `)) continue;
|
|
|
|
if (dlScript.includes(`document`)) throw new Error("Zippyshare changed their download script, please update this script.");
|
|
|
|
lib.log(`zippyshare`, `Evaluating this script:`, [dlScript]);
|
|
|
|
try {
|
|
let downloadPath = await safeeval(dlScript);
|
|
if (downloadPath.startsWith(`/d/`) && downloadPath != "/d/123/asd.xml") {
|
|
let hostname = new URL(url).hostname;
|
|
|
|
let dlLink = `https://${hostname}${downloadPath}`;
|
|
console.log(dlLink);
|
|
let dlName = downloadPath.split(`/`)[downloadPath.split(`/`).length - 1];
|
|
|
|
return {
|
|
axiosData: {
|
|
headers: headers,
|
|
url: dlLink
|
|
},
|
|
metadata: {
|
|
fileName: decodeURIComponent(dlName)
|
|
}
|
|
};
|
|
}
|
|
} catch(err) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
} else throw new Error("Download button/script not found. Check to see the link is still alive.");
|
|
} |