forked from DebaucheryLibrarian/traxxx
Added basic filename copy. Added HTTP helper to q. Fetching all actor release pages from Naughty America. Added various high res network logos.
This commit is contained in:
@@ -5,7 +5,6 @@ const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
const argv = require('../argv');
|
||||
|
||||
const knex = require('../knex');
|
||||
|
||||
async function init() {
|
||||
@@ -26,6 +25,8 @@ async function init() {
|
||||
|
||||
return file;
|
||||
}));
|
||||
|
||||
knex.destroy();
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const { JSDOM } = require('jsdom');
|
||||
const moment = require('moment');
|
||||
const bhttp = require('bhttp');
|
||||
|
||||
function prefixProtocol(url, protocol = 'https') {
|
||||
if (protocol && /^\/\//.test(url)) {
|
||||
@@ -22,7 +23,7 @@ function q(context, selector, attrArg, trim = true) {
|
||||
return trim ? value?.trim() : value;
|
||||
}
|
||||
|
||||
return context.querySelector(selector);
|
||||
return selector ? context.querySelector(selector) : context;
|
||||
}
|
||||
|
||||
function qall(context, selector, attrArg, trim = true) {
|
||||
@@ -36,7 +37,7 @@ function qall(context, selector, attrArg, trim = true) {
|
||||
}
|
||||
|
||||
function qtext(context, selector, trim = true) {
|
||||
const el = q(context, selector, false, trim);
|
||||
const el = q(context, selector, null, trim);
|
||||
if (!el) return null;
|
||||
|
||||
const text = Array.from(el.childNodes)
|
||||
@@ -147,7 +148,7 @@ const funcs = {
|
||||
qus: qurls,
|
||||
};
|
||||
|
||||
function ctx(element, window) {
|
||||
function init(element, window) {
|
||||
if (!element) return null;
|
||||
|
||||
const contextFuncs = Object.entries(funcs) // dynamically attach methods with context
|
||||
@@ -166,30 +167,58 @@ function ctx(element, window) {
|
||||
};
|
||||
}
|
||||
|
||||
function ctxa(context, selector, window) {
|
||||
return Array.from(context.querySelectorAll(selector)).map(element => ctx(element, window));
|
||||
function initAll(context, selector, window) {
|
||||
return Array.from(context.querySelectorAll(selector))
|
||||
.map(element => init(element, window));
|
||||
}
|
||||
|
||||
function ex(html, selector) {
|
||||
function extract(html, selector) {
|
||||
const { window } = new JSDOM(html);
|
||||
|
||||
if (selector) {
|
||||
return ctx(window.document.querySelector(selector), window);
|
||||
return init(window.document.querySelector(selector), window);
|
||||
}
|
||||
|
||||
return ctx(window.document, window);
|
||||
return init(window.document, window);
|
||||
}
|
||||
|
||||
function exa(html, selector) {
|
||||
function extractAll(html, selector) {
|
||||
const { window } = new JSDOM(html);
|
||||
|
||||
return ctxa(window.document, selector, window);
|
||||
return initAll(window.document, selector, window);
|
||||
}
|
||||
|
||||
async function get(url, selector, headers, all = false) {
|
||||
const res = await bhttp.get(url, {
|
||||
headers,
|
||||
});
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
return all
|
||||
? extractAll(res.body.toString(), selector)
|
||||
: extract(res.body.toString(), selector);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getAll(url, selector, headers) {
|
||||
return get(url, selector, headers, true);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ex,
|
||||
exa,
|
||||
ctx,
|
||||
ctxa,
|
||||
extract,
|
||||
extractAll,
|
||||
init,
|
||||
initAll,
|
||||
get,
|
||||
getAll,
|
||||
context: init,
|
||||
contextAll: initAll,
|
||||
ex: extract,
|
||||
exa: extractAll,
|
||||
ctx: init,
|
||||
ctxa: initAll,
|
||||
geta: getAll,
|
||||
...funcs,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user