File size: 1,877 Bytes
6c07b9a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | const axios = require("axios");
const { JSDOM } = require("jsdom");
const vm = require('node:vm');
async function savefrom(videoUrl) {
let body = new URLSearchParams({
"sf_url": encodeURI(videoUrl),
"sf_submit": "",
"new": 2,
"lang": "id",
"app": "",
"country": "id",
"os": "Windows",
"browser": "Chrome",
"channel": " main",
"sf-nomad": 1
});
try {
const { data } = await axios({
url: "https://worker.sf-tools.com/savefrom.php",
method: "POST",
data: body,
headers: {
"content-type": "application/x-www-form-urlencoded",
"origin": "https://id.savefrom.net",
"referer": "https://id.savefrom.net/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36"
}
});
const dom = new JSDOM(data);
const document = dom.window.document;
let exec = '[]["filter"]["constructor"](b).call(a);';
data = data.replace(exec, `\ntry {\ni++;\nif (i === 2) scriptResult = ${exec.split(".call")[0]}.toString();\nelse (\n${exec.replace(/;/, "")}\n);\n} catch {}`);
let context = {
"scriptResult": "",
"i": 0
};
vm.createContext(context);
new vm.Script(data).runInContext(context);
// Parsing the result using a more reliable method
const videoResultMatch = context.scriptResult.match(/window\.parent\.sf\.videoResult\.show\((.*?)\);/);
const videoInfo = videoResultMatch ? JSON.parse(videoResultMatch[1]) : null;
return videoInfo;
} catch (error) {
console.error('Error:', error.message);
throw error;
}
}
module.exports.savefrom = savefrom;
|