Added entity resolution prefer to entity options.

This commit is contained in:
DebaucheryLibrarian
2026-02-24 02:12:16 +01:00
parent d4e6082d2e
commit ba366df7a5
4 changed files with 14 additions and 7 deletions

View File

@@ -9,6 +9,9 @@ const grandParentNetworks = [
name: 'Gamma Entertainment',
url: 'https://www.gammaentertainment.com',
alias: ['gammaentertainment'],
options: {
preferNetwork: true,
},
},
{
slug: 'hush',

View File

@@ -836,7 +836,7 @@ async function scrapeActors(argNames) {
const entitySlugs = sources.flat();
const [entitiesBySlug, existingActorEntries] = await Promise.all([
fetchEntitiesBySlug(entitySlugs, { types: ['channel', 'network', 'info'], prefer: argv.prefer || 'channel' }),
fetchEntitiesBySlug(entitySlugs, { types: ['channel', 'network', 'info'], prefer: argv.prefer || 'options' }),
knex('actors')
.select(knex.raw('actors.id, actors.name, actors.slug, actors.entry_id, actors.entity_id, row_to_json(entities) as entity'))
.whereIn('actors.slug', baseActors.map((baseActor) => baseActor.slug))

View File

@@ -9,6 +9,7 @@ const knex = require('./knex');
const { deleteScenes, deleteMovies, deleteSeries } = require('./releases');
const { flushOrphanedMedia } = require('./media');
const { resolveScraper, resolveLayoutScraper } = require('./scrapers/resolve');
const getRecursiveParameters = require('./utils/get-recursive-parameters');
function getRecursiveParent(entity) {
if (!entity) {
@@ -257,13 +258,18 @@ async function fetchEntitiesBySlug(entitySlugs, options = { prefer: 'channel', a
entitySlugs: entitySlugs.filter((slug) => !slug.includes('.')),
entityHosts: entitySlugs.filter((slug) => slug.includes('.')).map((hostname) => `%${hostname}`),
entityTypes: options.types || ['channel', 'network'],
sort: knex.raw(options.prefer === 'channel' ? 'asc' : 'desc'),
sort: knex.raw(options.prefer === 'channel' || options.prefer === 'options' ? 'asc' : 'desc'),
});
// channel entity will overwrite network entity
// by default channel entity will overwrite network entity
const entitiesBySlug = entities.rows.reduce((accEntities, { entity }) => {
const host = urlToHostname(entity.url);
const curatedEntity = accEntities[entity.slug] || accEntities[host] || curateEntity(entity, true);
const entityOptions = getRecursiveParameters(entity, 'options');
const accEntity = accEntities[entity.slug] || accEntities[host];
const curatedEntity = !accEntity || (options.prefer === 'options' && entity.type === 'network' && entityOptions.preferNetwork)
? curateEntity(entity, true)
: accEntity;
return {
...accEntities,

View File

@@ -329,8 +329,7 @@ const validators = {
// profiler in this context is shorthand for profile scraper
async function init() {
// Pride Studios needs prefer network, probably works bests for most Gamma sites. Establish which scrapers need channel and why.
const entitiesBySlug = await fetchEntitiesBySlug(Object.keys(actorScrapers), { types: ['channel', 'network', 'info'], prefer: 'network' });
const entitiesBySlug = await fetchEntitiesBySlug(Object.keys(actorScrapers), { types: ['channel', 'network', 'info'], prefer: 'options' });
await Object.entries(actorScrapers).reduce(async (chain, [entitySlug, scraper]) => {
await chain;
@@ -340,7 +339,6 @@ async function init() {
const tests = actors.filter((actor) => actor.entity === entitySlug);
// TODO: remove when all tests are written
if (tests.length === 0) {
console.log('TODO', entitySlug);
return;