Fixed countries seed file. Updated MOFOS scraper. Improved Reality Kings scraper. Limiting photos for XEmpire scraper.

This commit is contained in:
2019-11-27 04:58:38 +01:00
parent de36ed97e4
commit d113123778
61 changed files with 2182 additions and 2005 deletions

View File

@@ -9,11 +9,13 @@ const whereOr = require('./utils/where-or');
const { createActorMediaDirectory, storeAvatars } = require('./media');
async function curateActor(actor) {
const [aliases, avatars] = await Promise.all([
const [aliases, avatars, social] = await Promise.all([
knex('actors').where({ alias_for: actor.id }),
knex('media')
.where({ domain: 'actors', target_id: actor.id })
.orderBy('index'),
knex('social')
.where({ domain: 'actors', target_id: actor.id }),
]);
return {
@@ -46,6 +48,7 @@ async function curateActor(actor) {
aliases: aliases.map(({ name }) => name),
slug: actor.slug,
avatars,
social,
};
}
@@ -94,6 +97,35 @@ function curateActorEntry(actor, scraped, scrapeSuccess) {
return curatedActor;
}
function curateSocialEntry(url, actor) {
const { hostname, origin, pathname } = new URL(url);
const platform = ['twitter', 'instagram', 'snapchat', 'modelhub', 'youtube'].find(platformName => hostname.match(platformName));
return {
url: `${origin}${pathname}`,
platform,
domain: 'actors',
target_id: actor.id,
};
}
function curateSocialEntries(urls, actor) {
if (!urls) {
return [];
}
return urls.reduce((acc, url) => {
const socialEntry = curateSocialEntry(url, actor);
if (acc.some(entry => socialEntry.url === entry.url)) {
// prevent duplicates
return acc;
}
return [...acc, socialEntry];
}, []);
}
async function fetchActors(queryObject) {
const releases = await knex('actors')
.select(
@@ -112,34 +144,30 @@ async function fetchActors(queryObject) {
async function storeActor(actor, scraped = false, scrapeSuccess = false) {
const curatedActor = curateActorEntry(actor, scraped, scrapeSuccess);
const actorEntries = await knex('actors')
const [actorEntry] = await knex('actors')
.insert(curatedActor)
.returning('*');
if (actorEntries.length) {
const actorEntry = actorEntries[0];
await knex('social').insert(curateSocialEntries(actor.social, actor));
console.log(`Added new entry for actor '${actor.name}'`);
console.log(`Added new entry for actor '${actor.name}'`);
return actorEntry;
}
console.error(`Unable to save profile for '${actor.name}'`);
return null;
return actorEntry;
}
async function updateActor(actor, scraped = false, scrapeSuccess = false) {
const curatedActor = curateActorEntry(actor, scraped, scrapeSuccess);
const actorEntries = await knex('actors')
const [actorEntry] = await knex('actors')
.where({ id: actor.id })
.update(curatedActor)
.returning('*');
await knex('social').insert(curateSocialEntries(actor.social, actor));
console.log(`Updated entry for actor '${actor.name}'`);
return actorEntries[0];
return actorEntry;
}
function mergeProfiles(profiles, actor) {
@@ -177,7 +205,6 @@ function mergeProfiles(profiles, actor) {
}, {
social: [],
avatars: [],
...actor,
});
}