diff --git a/seeds/01_networks.js b/seeds/01_networks.js index 8713bf91..126faea8 100755 --- a/seeds/01_networks.js +++ b/seeds/01_networks.js @@ -9,6 +9,9 @@ const grandParentNetworks = [ name: 'Gamma Entertainment', url: 'https://www.gammaentertainment.com', alias: ['gammaentertainment'], + options: { + preferNetwork: true, + }, }, { slug: 'hush', diff --git a/src/actors.js b/src/actors.js index 15615618..1011d2d7 100755 --- a/src/actors.js +++ b/src/actors.js @@ -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)) diff --git a/src/entities.js b/src/entities.js index 41a1398e..34cf522a 100755 --- a/src/entities.js +++ b/src/entities.js @@ -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, diff --git a/tests/profiles.js b/tests/profiles.js index 4fb5f3d3..e7a85870 100644 --- a/tests/profiles.js +++ b/tests/profiles.js @@ -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;