Added showcased migration. Added Love Her Films scraper.
This commit is contained in:
0
src/utils/argv-include.js
Normal file → Executable file
0
src/utils/argv-include.js
Normal file → Executable file
0
src/utils/buffer.js
Normal file → Executable file
0
src/utils/buffer.js
Normal file → Executable file
0
src/utils/bulk-insert.js
Normal file → Executable file
0
src/utils/bulk-insert.js
Normal file → Executable file
0
src/utils/capitalize.js
Normal file → Executable file
0
src/utils/capitalize.js
Normal file → Executable file
0
src/utils/cf.js
Normal file → Executable file
0
src/utils/cf.js
Normal file → Executable file
0
src/utils/chunk.js
Normal file → Executable file
0
src/utils/chunk.js
Normal file → Executable file
14
src/utils/convert.js
Normal file → Executable file
14
src/utils/convert.js
Normal file → Executable file
@@ -86,6 +86,18 @@ function convertApi(input, fromOrTo, to) {
|
||||
}
|
||||
}
|
||||
|
||||
function maleFeetUsToEu(input) {
|
||||
const size = Number(input.toString().match(/\d+(\.\d+)?/)?.[0]);
|
||||
|
||||
return Math.round((1.27 * size + 29.94) / 0.5) * 0.5; // round to nearest half
|
||||
}
|
||||
|
||||
function femaleFeetUsToEu(input) {
|
||||
const size = Number(input.toString().match(/\d+(\.\d+)?/)?.[0]);
|
||||
|
||||
return Math.round((1.27 * size + 28.67) / 0.5) * 0.5; // round to nearest half
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cmToFeetInches,
|
||||
cmToInches,
|
||||
@@ -94,5 +106,7 @@ module.exports = {
|
||||
inchesToCm,
|
||||
lbsToKg,
|
||||
kgToLbs,
|
||||
maleFeetUsToEu,
|
||||
femaleFeetUsToEu,
|
||||
convert: convertApi,
|
||||
};
|
||||
|
||||
0
src/utils/escape-html.js
Normal file → Executable file
0
src/utils/escape-html.js
Normal file → Executable file
0
src/utils/file-entries.js
Normal file → Executable file
0
src/utils/file-entries.js
Normal file → Executable file
0
src/utils/get-recursive-parameters.js
Normal file → Executable file
0
src/utils/get-recursive-parameters.js
Normal file → Executable file
0
src/utils/http-windows.js
Normal file → Executable file
0
src/utils/http-windows.js
Normal file → Executable file
71
src/utils/http.js
Normal file → Executable file
71
src/utils/http.js
Normal file → Executable file
@@ -9,6 +9,7 @@ const stream = require('stream');
|
||||
const tunnel = require('tunnel');
|
||||
const Bottleneck = require('bottleneck');
|
||||
const { JSDOM, toughCookie } = require('jsdom');
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
const windows = require('./http-windows');
|
||||
|
||||
@@ -28,6 +29,9 @@ const limiters = {
|
||||
|
||||
const bypassSessions = new Map();
|
||||
|
||||
let browser = null;
|
||||
const browserSessions = new Map();
|
||||
|
||||
Promise.config({
|
||||
cancellation: true,
|
||||
});
|
||||
@@ -58,6 +62,24 @@ function useProxy(url) {
|
||||
return config.proxy.hostnames.includes(hostname);
|
||||
}
|
||||
|
||||
function useBrowserBypass(url, options) {
|
||||
if (!config.bypass.browser.enable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { hostname } = new URL(url);
|
||||
|
||||
if (options.bypassBrowser === 'shared') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (config.bypass.browser.hostnames.includes(hostname)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function useCloudflareBypass(url, options) {
|
||||
if (!config.bypass.cloudflare.enable) {
|
||||
return null;
|
||||
@@ -134,6 +156,42 @@ function extractJson(solution) {
|
||||
return solution.response;
|
||||
}
|
||||
|
||||
async function getBrowserSession(hostname) {
|
||||
console.log(browserSessions);
|
||||
|
||||
if (browserSessions.has(hostname)) {
|
||||
return browserSessions.get(hostname);
|
||||
}
|
||||
|
||||
if (!browser) {
|
||||
browser = await puppeteer.launch({ headless: false });
|
||||
}
|
||||
|
||||
const page = await browser.newPage();
|
||||
|
||||
browserSessions.set(hostname, page);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
async function bypassBrowserRequest(url, _options) {
|
||||
const page = await limiters.bypass.schedule(async () => getBrowserSession(new URL(url).hostname));
|
||||
|
||||
const res = await page.goto(url);
|
||||
const body = await page.content();
|
||||
|
||||
console.log(res);
|
||||
console.log(res.status());
|
||||
|
||||
return {
|
||||
body,
|
||||
/*
|
||||
statusCode: res.body.solution.status,
|
||||
headers: res.body.solution.headers,
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
async function getBypassSession(url, hostname) {
|
||||
if (bypassSessions.has(hostname)) {
|
||||
return bypassSessions.get(hostname);
|
||||
@@ -236,13 +294,22 @@ async function request(method = 'get', url, body, requestOptions = {}, limiter)
|
||||
};
|
||||
|
||||
const withProxy = useProxy(url);
|
||||
const withBrowserBypass = useBrowserBypass(url, options);
|
||||
const withCloudflareBypass = useCloudflareBypass(url, options);
|
||||
|
||||
if (withProxy) {
|
||||
options.agent = proxyAgent;
|
||||
}
|
||||
|
||||
logger.debug(`${method.toUpperCase()} (${limiter._store.storeOptions.minTime}ms/${limiter._store.storeOptions.maxConcurrent}p${withProxy ? ' proxy' : ''}${withCloudflareBypass ? ' bypass' : ''}) ${url}`);
|
||||
logger.debug(`${method.toUpperCase()} (${limiter._store.storeOptions.minTime}ms/${limiter._store.storeOptions.maxConcurrent}p${withProxy ? ' proxy' : ''}${withBrowserBypass || withCloudflareBypass ? ' bypass' : ''}) ${url}`);
|
||||
|
||||
if (withBrowserBypass) {
|
||||
if (method !== 'get') {
|
||||
throw new Error('Browser bypass only supports GET');
|
||||
}
|
||||
|
||||
return bypassBrowserRequest(url, options);
|
||||
}
|
||||
|
||||
if (withCloudflareBypass) {
|
||||
return bypassCloudflareRequest(url, method, body, withCloudflareBypass, options);
|
||||
@@ -385,6 +452,8 @@ module.exports = {
|
||||
patch,
|
||||
session: getSession,
|
||||
cookieJar: getCookieJar,
|
||||
getBrowserSession,
|
||||
getBypassSession,
|
||||
getSession,
|
||||
getCookieJar,
|
||||
destroyBypassSessions,
|
||||
|
||||
0
src/utils/img.js
Normal file → Executable file
0
src/utils/img.js
Normal file → Executable file
0
src/utils/jsdom-perf.js
Normal file → Executable file
0
src/utils/jsdom-perf.js
Normal file → Executable file
0
src/utils/jsdom-url.js
Normal file → Executable file
0
src/utils/jsdom-url.js
Normal file → Executable file
0
src/utils/list.js
Normal file → Executable file
0
src/utils/list.js
Normal file → Executable file
0
src/utils/media.js
Normal file → Executable file
0
src/utils/media.js
Normal file → Executable file
0
src/utils/mofos.js
Normal file → Executable file
0
src/utils/mofos.js
Normal file → Executable file
0
src/utils/pick-random.js
Normal file → Executable file
0
src/utils/pick-random.js
Normal file → Executable file
0
src/utils/posters.js
Normal file → Executable file
0
src/utils/posters.js
Normal file → Executable file
0
src/utils/q.js
Normal file → Executable file
0
src/utils/q.js
Normal file → Executable file
0
src/utils/qu.js
Normal file → Executable file
0
src/utils/qu.js
Normal file → Executable file
0
src/utils/resolve-place.js
Normal file → Executable file
0
src/utils/resolve-place.js
Normal file → Executable file
0
src/utils/s3.js
Normal file → Executable file
0
src/utils/s3.js
Normal file → Executable file
0
src/utils/scorelogos.js
Normal file → Executable file
0
src/utils/scorelogos.js
Normal file → Executable file
0
src/utils/shuffle.js
Normal file → Executable file
0
src/utils/shuffle.js
Normal file → Executable file
0
src/utils/slugify.js
Normal file → Executable file
0
src/utils/slugify.js
Normal file → Executable file
0
src/utils/stream.js
Normal file → Executable file
0
src/utils/stream.js
Normal file → Executable file
0
src/utils/tcc.js
Normal file → Executable file
0
src/utils/tcc.js
Normal file → Executable file
0
src/utils/timeout.js
Normal file → Executable file
0
src/utils/timeout.js
Normal file → Executable file
0
src/utils/titles.js
Normal file → Executable file
0
src/utils/titles.js
Normal file → Executable file
0
src/utils/update.js
Normal file → Executable file
0
src/utils/update.js
Normal file → Executable file
0
src/utils/upsert.js
Normal file → Executable file
0
src/utils/upsert.js
Normal file → Executable file
0
src/utils/virtual-console.js
Normal file → Executable file
0
src/utils/virtual-console.js
Normal file → Executable file
0
src/utils/where-or.js
Normal file → Executable file
0
src/utils/where-or.js
Normal file → Executable file
Reference in New Issue
Block a user