Adding scraper config by scraper slug to current 'includes' parameter.

This commit is contained in:
DebaucheryLibrarian 2020-10-28 01:36:13 +01:00
parent 1869877178
commit bf9b334b73
4 changed files with 37 additions and 13 deletions

View File

@ -175,6 +175,11 @@ module.exports = {
'pornhub', 'pornhub',
'freeones', 'freeones',
], ],
options: {
traxxx: {
// source: 'http://nsfw.unknown.name/random',
},
},
proxy: { proxy: {
enable: false, enable: false,
host: '', host: '',

View File

@ -78,7 +78,7 @@ const boobpedia = require('./boobpedia');
const freeones = require('./freeones'); const freeones = require('./freeones');
// const freeoneslegacy = require('./freeones_legacy'); // const freeoneslegacy = require('./freeones_legacy');
module.exports = { const scrapers = {
releases: { releases: {
'21naturals': naturals, '21naturals': naturals,
'21sextreme': sextreme, '21sextreme': sextreme,
@ -269,3 +269,9 @@ module.exports = {
xempire, xempire,
}, },
}; };
module.exports = {
// add slug for easy internal reference
releases: Object.entries(scrapers.releases).reduce((acc, [slug, scraper]) => ({ ...acc, [slug]: { ...scraper, slug } })),
actors: Object.entries(scrapers.actors).reduce((acc, [slug, scraper]) => ({ ...acc, [slug]: { ...scraper, slug } })),
};

View File

@ -97,7 +97,7 @@ function maleNoun() {
return random([ return random([
'guy', 'guy',
'stud', 'stud',
'man', 'lad',
'boyfriend', 'boyfriend',
'stranger', 'stranger',
'stepbrother', 'stepbrother',
@ -227,13 +227,19 @@ function actors(release) {
})); }));
} }
async function fetchLatest(entity) { async function fetchLatest(entity, page, options) {
return Promise.all(Array.from({ length: 100 }, async (value, index) => { return Promise.all(Array.from({ length: 100 }, async (value, index) => {
const release = {}; const release = {};
release.entryId = nanoid(); release.entryId = nanoid();
release.date = moment().subtract(Math.floor(Math.random() * index), 'days').toDate(); release.date = moment().subtract(Math.floor(Math.random() * index), 'days').toDate();
if (options.source) {
// select from configured random image source
release.poster = `${options.source}?id=${nanoid()}`; // ensure source is unique
release.photos = Array.from({ length: Math.floor(Math.random() * 10) + 1 }, () => `${options.source}?id=${nanoid()}`); // ensure source is unique
} else {
// select from local SFW database
const [poster, ...photos] = await knex('media') const [poster, ...photos] = await knex('media')
.select('path') .select('path')
.where('is_sfw', true) .where('is_sfw', true)
@ -243,6 +249,7 @@ async function fetchLatest(entity) {
release.poster = `http://${config.web.host}:${config.web.port}/img/${poster}?id=${nanoid()}`; // ensure source is unique release.poster = `http://${config.web.host}:${config.web.port}/img/${poster}?id=${nanoid()}`; // ensure source is unique
release.photos = photos.map(photo => `http://${config.web.host}:${config.web.port}/img/${photo}?id=${nanoid()}`); release.photos = photos.map(photo => `http://${config.web.host}:${config.web.port}/img/${photo}?id=${nanoid()}`);
}
release.tags = await knex('tags') release.tags = await knex('tags')
.select('name') .select('name')

View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
const config = require('config');
const Promise = require('bluebird'); const Promise = require('bluebird');
const moment = require('moment'); const moment = require('moment');
@ -93,9 +94,14 @@ function needNextPage(pageReleases, accReleases, isUpcoming) {
async function scrapeReleases(scraper, entity, preData, isUpcoming) { async function scrapeReleases(scraper, entity, preData, isUpcoming) {
async function scrapeReleasesPage(page, accReleases) { async function scrapeReleasesPage(page, accReleases) {
const options = {
...config.options[scraper.slug],
...include,
};
const pageReleases = isUpcoming const pageReleases = isUpcoming
? await scraper.fetchUpcoming(entity, page, include, preData) ? await scraper.fetchUpcoming(entity, page, options, preData)
: await scraper.fetchLatest(entity, page, include, preData); : await scraper.fetchLatest(entity, page, options, preData);
if (!Array.isArray(pageReleases)) { if (!Array.isArray(pageReleases)) {
// scraper is unable to fetch the releases and returned a HTTP code or null // scraper is unable to fetch the releases and returned a HTTP code or null