2021-09-05 12:55:57 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
const esprima = require('esprima');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
let url = null;
|
|
|
|
|
|
|
|
for(let i=0; i<process.argv.length; i++) {
|
|
|
|
const arg = process.argv[i];
|
|
|
|
if(arg.startsWith("http://") || arg.startsWith("https://")) {
|
|
|
|
url = arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(url !== null) {
|
2021-09-07 13:01:17 +00:00
|
|
|
const search = new URLSearchParams();
|
|
|
|
search.set("dl", "1");
|
|
|
|
const direct = new URL(url);
|
|
|
|
direct.search = search.toString();
|
2021-09-05 12:55:57 +00:00
|
|
|
axios.get(url).then((resp) => {
|
|
|
|
const dom = cheerio.load(resp.data, {xmlMode: false});
|
|
|
|
const tags = dom('script').get();
|
|
|
|
const data = {};
|
|
|
|
let props = [];
|
|
|
|
for(let i=0; i<tags.length; i++) {
|
|
|
|
const children = tags[i].children;
|
|
|
|
for(let j=0; j<children.length; j++) {
|
|
|
|
let tdata = {};
|
|
|
|
let assign = true;
|
|
|
|
try {
|
|
|
|
tdata = children[j].data;
|
|
|
|
} catch(err) {
|
|
|
|
assign = false;
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
if(assign) {
|
|
|
|
const script = esprima.parseScript(tdata);
|
|
|
|
for(let k=0; k<script.body.length; k++) {
|
|
|
|
const prop = script.body[k].expression.right.properties;
|
|
|
|
for(let l=0; l<prop.length; l++) {
|
|
|
|
props = [...props, ...(prop[l].value.properties)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(let i=0; i<props.length; i++) {
|
|
|
|
const prop = props[i];
|
2021-09-06 07:02:36 +00:00
|
|
|
if((prop.key.type === "Identifier") && (prop.value.type === "Literal")) {
|
|
|
|
data[prop.key.name] = prop.value.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(let i=0; i<props.length; i++) {
|
|
|
|
const prop = props[i];
|
|
|
|
const valid = (new Boolean(prop.value.value)).valueOf();
|
|
|
|
if((prop.key.type === "Identifier") && (prop.value.type === "Literal") && valid) {
|
2021-09-05 12:55:57 +00:00
|
|
|
data[prop.key.name] = prop.value.value;
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 13:01:17 +00:00
|
|
|
data["rawPath"] = direct.href;
|
2021-09-05 12:55:57 +00:00
|
|
|
console.log(JSON.stringify(data));
|
2021-09-07 13:01:17 +00:00
|
|
|
});
|
2021-09-05 12:55:57 +00:00
|
|
|
}
|