selfdebrid/extractors/letsupload.js

55 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: ["letsupload.io"],
tests: []
};
async function get(url, options) {
lib.log(`letsupload`, `Fetching page...`, [], true, options);
let resp = await axios({
url: url,
headers: lib.defaultHeaders
});
lib.log(`letsupload`, `Parsing page...`);
let $ = cheerio.load(resp.data);
let fileName = $(".download-page-file-info .text-block .h3").text();
let dlButton = $(".download-page-file-info .row > .col-md-4 > button")?.[0];
if (dlButton?.attribs?.onclick) {
let cookie = lib.cookieToString(scp.parse(resp.headers["set-cookie"]));
let dlPageLink = dlButton?.attribs?.onclick?.split(`window.location = '`)[1].split(`';`)[0];
lib.log(`letsupload`, `Got cookies:`, [cookie]);
lib.log(`letsupload`, `Got download page URL:`, [dlPageLink]);
lib.log(`letsupload`, `Fetching download page...`, [], true, options);
let headers = lib.defaultHeaders;
headers["Cookie"] = cookie;
headers["Referer"] = url;
resp = await axios({
url: dlPageLink,
headers: headers
});
lib.log(`letsupload`, `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://letsupload.io/account/direct_download/${numericId}`
},
metadata: {
fileName: fileName
}
};
} else throw new Error("Download button not found. Check to see the link is still alive.");
}