selfdebrid/extractors/yodbox.js

47 lines
1.3 KiB
JavaScript

const axios = require("axios");
const cheerio = require("cheerio");
const lib = require("../lib");
module.exports = {
get: get,
hostnames: ["yodbox.com"],
tests: []
}
async function get(url, options) {
let id = new URL(url).pathname.substring(1).split(`/`)[0];
let headers = lib.defaultHeaders;
headers["Content-Type"] = `application/x-www-form-urlencoded`;
headers["Origin"] = `https://yodbox.com`
headers["Referer"] = url;
let body = `op=download2&id=${id}&rand=&referer=&method_free=&method_premium=&adblock_detected=0`;
lib.log(`yodbox`, `Fetching download request page...`, [], true, options);
let resp = await axios({
method: `POST`,
data: body,
headers: headers,
url: url
});
lib.log(`yodbox`, `Parsing download request page...`);
let $ = cheerio.load(resp.data);
let dlButton = $("#container > a:not([href='/premium'])")[0];
if (dlButton && dlButton?.attribs?.href) {
let dlLink = dlButton.attribs.href;
let dlName = decodeURIComponent(dlLink.split(`/`)[dlLink.split(`/`).length - 1]);
return {
axiosData: {
headers: headers,
url: dlLink
},
metadata: {
fileName: dlName
}
}
} else throw new Error("Could not get metadata properly. Check if the link is alive.")
}