From bf9b334b737ee6c49e4fec9bc248ba50bf14a97c Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 28 Oct 2020 01:36:13 +0100 Subject: [PATCH] Adding scraper config by scraper slug to current 'includes' parameter. --- config/default.js | 5 +++++ src/scrapers/scrapers.js | 8 +++++++- src/scrapers/traxxx.js | 27 +++++++++++++++++---------- src/updates.js | 10 ++++++++-- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/config/default.js b/config/default.js index cc39f449..a24006f1 100644 --- a/config/default.js +++ b/config/default.js @@ -175,6 +175,11 @@ module.exports = { 'pornhub', 'freeones', ], + options: { + traxxx: { + // source: 'http://nsfw.unknown.name/random', + }, + }, proxy: { enable: false, host: '', diff --git a/src/scrapers/scrapers.js b/src/scrapers/scrapers.js index de80e4bd..a026e3bd 100644 --- a/src/scrapers/scrapers.js +++ b/src/scrapers/scrapers.js @@ -78,7 +78,7 @@ const boobpedia = require('./boobpedia'); const freeones = require('./freeones'); // const freeoneslegacy = require('./freeones_legacy'); -module.exports = { +const scrapers = { releases: { '21naturals': naturals, '21sextreme': sextreme, @@ -269,3 +269,9 @@ module.exports = { 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 } })), +}; diff --git a/src/scrapers/traxxx.js b/src/scrapers/traxxx.js index c3ed905a..da0b481b 100644 --- a/src/scrapers/traxxx.js +++ b/src/scrapers/traxxx.js @@ -97,7 +97,7 @@ function maleNoun() { return random([ 'guy', 'stud', - 'man', + 'lad', 'boyfriend', 'stranger', 'stepbrother', @@ -227,22 +227,29 @@ function actors(release) { })); } -async function fetchLatest(entity) { +async function fetchLatest(entity, page, options) { return Promise.all(Array.from({ length: 100 }, async (value, index) => { const release = {}; release.entryId = nanoid(); release.date = moment().subtract(Math.floor(Math.random() * index), 'days').toDate(); - const [poster, ...photos] = await knex('media') - .select('path') - .where('is_sfw', true) - .pluck('path') - .orderByRaw('random()') - .limit(Math.floor(Math.random() * 10) + 1); + 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') + .select('path') + .where('is_sfw', true) + .pluck('path') + .orderByRaw('random()') + .limit(Math.floor(Math.random() * 10) + 1); - 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.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.tags = await knex('tags') .select('name') diff --git a/src/updates.js b/src/updates.js index fee808f6..c58303e7 100644 --- a/src/updates.js +++ b/src/updates.js @@ -1,5 +1,6 @@ 'use strict'; +const config = require('config'); const Promise = require('bluebird'); const moment = require('moment'); @@ -93,9 +94,14 @@ function needNextPage(pageReleases, accReleases, isUpcoming) { async function scrapeReleases(scraper, entity, preData, isUpcoming) { async function scrapeReleasesPage(page, accReleases) { + const options = { + ...config.options[scraper.slug], + ...include, + }; + const pageReleases = isUpcoming - ? await scraper.fetchUpcoming(entity, page, include, preData) - : await scraper.fetchLatest(entity, page, include, preData); + ? await scraper.fetchUpcoming(entity, page, options, preData) + : await scraper.fetchLatest(entity, page, options, preData); if (!Array.isArray(pageReleases)) { // scraper is unable to fetch the releases and returned a HTTP code or null