From 13d02a44e5d727bd9404db43b598ed0940b4010a Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sun, 2 Jul 2023 23:59:49 +0200 Subject: [PATCH] Fixed failed hash duplicate source breaking media association. --- src/media.js | 4 +--- src/scrapers/traxxx.js | 29 ++++++++++++++++---------- src/tools/names.js | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 src/tools/names.js diff --git a/src/media.js b/src/media.js index 43a22099..65b70881 100755 --- a/src/media.js +++ b/src/media.js @@ -353,8 +353,6 @@ async function extractSource(baseSource, { existingExtractMediaByUrl }) { if (typeof baseSource.defer === 'function') { const src = await baseSource.defer(); - console.log('DEFERED', src); - return { ...baseSource, ...toBaseSource(src), @@ -909,7 +907,7 @@ async function associateReleaseMedia(releases, type = 'release') { .reduce((acc, [releaseId, releaseBaseMedias]) => { releaseBaseMedias.forEach((baseMedia) => { const media = storedMediasById[baseMedia.id]; - const mediaId = media?.use || media?.entry?.id; + const mediaId = (storedMediasById[media?.use] && media?.use) || media?.entry?.id; if (mediaId) { acc.push({ diff --git a/src/scrapers/traxxx.js b/src/scrapers/traxxx.js index b9e32d69..4c0a5a17 100755 --- a/src/scrapers/traxxx.js +++ b/src/scrapers/traxxx.js @@ -217,7 +217,7 @@ function gender() { ]); } -function actors(release) { +function generateActors(release) { const length = release.tags.some((tag) => ['dp', 'dap', 'gangbang'].includes(tag)) ? Math.floor(Math.random() * 6) + 3 : Math.floor(Math.random() * 3) + 2; @@ -233,13 +233,20 @@ function actors(release) { } async function beforeFetchLatest() { - const tags = await knex('tags') - .select('name') - .where('priority', '>', 7) - .orderByRaw('random()') - .pluck('name'); + const [actors, tags] = await Promise.all([ + knex('actors') + .select('name') + .orderByRaw('random()') + .limit(1000) + .pluck('name'), + knex('tags') + .select('name') + .where('priority', '>', 7) + .orderByRaw('random()') + .pluck('name'), + ]); - return { tags }; + return { actors, tags }; } async function fetchLatest(entity, page, options) { @@ -269,13 +276,13 @@ async function fetchLatest(entity, page, options) { release.photos = photos.map((photo) => `http://${config.web.host}:${config.web.port}/img/${photo}?id=${nanoid()}`); } - release.tags = shuffle(options.beforeFetchLatest.tags).slice(faker.datatype.number({ min: 3, max: 20 })); + release.tags = shuffle(options.beforeFetchLatest.tags).slice(0, faker.datatype.number({ min: 3, max: 20 })); + + // release.actors = [...generateActors(release), null]; // include empty actor to ensure proper handling + release.actors = shuffle(options.beforeFetchLatest.actors).slice(0, faker.datatype.number(release.tags.some((tag) => ['dp', 'dap', 'gangbang'].includes(tag)) ? { min: 3, max: 6 } : { min: 2, max: 3 })); - release.actors = [...actors(release), null]; // include empty actor to ensure proper handling release.title = title(release); - console.log(release.entryId); - return release; })); } diff --git a/src/tools/names.js b/src/tools/names.js new file mode 100644 index 00000000..e3658bf4 --- /dev/null +++ b/src/tools/names.js @@ -0,0 +1,47 @@ +'use strict'; + +const pickRandom = require('../utils/pick-random'); + +const firstMale = [ + 'John', + 'James', + 'Biggus', + 'Mick', +]; + +const lastMale = [ + 'Dickus', + 'Strong', + 'Slayer', + 'Gun', + 'Pistol', +]; + +const firstFemale = [ + 'Kimmy', + 'Summer', + 'Jessica', + 'Rose', + 'Sky', + 'Skye', +]; + +const lastFemale = [ + 'Olsen', + 'Flower', + 'Star', + 'Dior', +]; + +const lastGeneric = [ + 'Steele', + 'White', +]; + +function init() { + const names = Array.from({ length: 1000 }, () => `${pickRandom([...firstMale, ...firstFemale])} ${pickRandom([...lastMale, ...lastFemale, ...lastGeneric])}`); + + console.log(names); +} + +init();