Added avatars. Added PornHub and LegalPorno actor profile scrapers.

This commit is contained in:
2019-11-20 04:53:36 +01:00
parent a13d92b84e
commit 9fcc40dd17
13 changed files with 475 additions and 63 deletions

View File

@@ -1,14 +1,18 @@
'use strict';
const Promise = require('bluebird');
const knex = require('./knex');
const argv = require('./argv');
const scrapers = require('./scrapers/scrapers');
const whereOr = require('./utils/where-or');
const { createActorMediaDirectory, storeAvatars } = require('./media');
async function curateActor(actor) {
const aliases = await knex('actors')
.where({ alias_for: actor.id });
const [aliases, avatars] = await Promise.all([
knex('actors').where({ alias_for: actor.id }),
knex('media').where({ domain: 'actors', target_id: actor.id }),
]);
return {
id: actor.id,
@@ -37,6 +41,7 @@ async function curateActor(actor) {
boobsNatural: actor.boobs_natural,
aliases: aliases.map(({ name }) => name),
slug: actor.slug,
avatars,
};
}
@@ -60,10 +65,10 @@ function curateActorEntry(actor, scraped, scrapeSuccess) {
residence_country_alpha2: actor.residenceCountry,
birth_place: actor.birthPlace,
residence_place: actor.residencePlace,
active: actor.active,
boobs_size: actor.boobs && actor.boobs.size,
boobs_natural: actor.boobs && actor.boobs.natural,
height: actor.height,
weight: actor.weight,
hair: actor.hair,
eyes: actor.eyes,
tattoos: actor.tattoos,
@@ -116,11 +121,11 @@ async function storeActor(actor, scraped = false, scrapeSuccess = false) {
return null;
}
async function updateActor(actorEntry, actor, scraped = false, scrapeSuccess = false) {
async function updateActor(actor, scraped = false, scrapeSuccess = false) {
const curatedActor = curateActorEntry(actor, scraped, scrapeSuccess);
const actorEntries = await knex('actors')
.where({ id: actorEntry.id })
.where({ id: actor.id })
.update(curatedActor)
.returning('*');
@@ -129,23 +134,74 @@ async function updateActor(actorEntry, actor, scraped = false, scrapeSuccess = f
return actorEntries[0];
}
function mergeProfiles(profiles, actor) {
return profiles.reduce((prevProfile, profile) => {
if (profile === null) {
return prevProfile;
}
return {
id: actor.id,
name: actor.name,
gender: prevProfile.gender || profile.gender,
birthdate: prevProfile.birthdate || profile.birthdate,
residenceCountry: prevProfile.residenceCountry || profile.residenceCountry,
birthPlace: prevProfile.birthPlace || profile.birthPlace,
ethnicity: prevProfile.ethnicity || profile.ethnicity,
boobs: profile.boobs
? {
size: prevProfile.boobs.size || profile.boobs.size,
natural: prevProfile.boobs.natural || profile.boobs.natural,
}
: {},
height: prevProfile.height || profile.height,
weight: prevProfile.weight || profile.weight,
hair: prevProfile.hair || profile.hair,
eyes: prevProfile.eyes || profile.eyes,
piercings: prevProfile.piercings || profile.piercings,
tattoos: prevProfile.tattoos || profile.tattoos,
social: prevProfile.social.concat(profile.social || []),
avatars: prevProfile.avatars.concat(profile.avatar || []),
};
}, {
boobs: {},
social: [],
avatars: [],
...actor,
});
}
async function scrapeActors(actorNames) {
await Promise.map(actorNames || argv.actors, async (actorName) => {
const actorSlug = actorName.toLowerCase().replace(/\s+/g, '-');
const [actorEntry] = await fetchActors({ slug: actorSlug });
const profiles = await Promise.all(Object.values(scrapers.actors).map(scraper => scraper.fetchActor(actorEntry ? actorEntry.name : actorName)));
const actorEntry = await knex('actors').where({ slug: actorSlug }).first();
const profiles = await Promise.all(Object.values(scrapers.actors).map(scraper => scraper.fetchProfile(actorEntry ? actorEntry.name : actorName)));
const profile = mergeProfiles(profiles, actorEntry);
if (profiles[0] === null) {
if (profile === null) {
console.log(`Could not find profile for actor '${actorName}'`);
return updateActor(actorEntry, actorEntry, true, false);
await updateActor(profile, true, false);
return;
}
if (actorEntry && profiles[0]) {
return updateActor(actorEntry, profiles[0], true, true);
if (actorEntry && profile) {
await createActorMediaDirectory(profile, actorEntry);
await Promise.all([
updateActor(profile, true, true),
storeAvatars(profile, actorEntry),
]);
return;
}
return storeActor(profiles[0], true, true);
const newActorEntry = await storeActor(profile, true, true);
await createActorMediaDirectory(profile, newActorEntry);
await storeAvatars(profile, newActorEntry);
}, {
concurrency: 1,
});