Removed type property from scenes API.

This commit is contained in:
DebaucheryLibrarian 2020-08-13 16:10:58 +02:00
parent f8c9b69f4b
commit 59e2124407
5 changed files with 86 additions and 16 deletions

View File

@ -11,12 +11,18 @@ module.exports = {
sfwHost: '0.0.0.0', sfwHost: '0.0.0.0',
sfwPort: 5001, sfwPort: 5001,
}, },
// include: [], include: {
networks: [
'xempire',
'julesjordan',
],
channels: [],
},
exclude: { exclude: {
networks: [ networks: [
'gamma', 'hardx',
'pornpros',
'mindgeek', 'mindgeek',
'julesjordan',
], ],
channels: [ channels: [
// 21sextreme, no longer updated // 21sextreme, no longer updated

View File

@ -28,7 +28,7 @@ async function init() {
const actors = (argv.actors || argv.actorsUpdate || argv.actorsFile) && await scrapeActors(actorNames); const actors = (argv.actors || argv.actorsUpdate || argv.actorsFile) && await scrapeActors(actorNames);
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.releases).flat().filter(Boolean); const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.releases).flat().filter(Boolean);
const updateBaseScenes = (argv.all || argv.channels || argv.networks || argv.movies) && await fetchUpdates(); const updateBaseScenes = (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) && await fetchUpdates();
const scenesFromFile = argv.scenesFile && await getFileEntries(argv.scenesFile); const scenesFromFile = argv.scenesFile && await getFileEntries(argv.scenesFile);
const sceneUrls = (argv.scene || []).concat(scenesFromFile || []); const sceneUrls = (argv.scene || []).concat(scenesFromFile || []);

View File

@ -61,13 +61,12 @@ const { argv } = yargs
.option('actors-scenes', { .option('actors-scenes', {
describe: 'Fetch all scenes for an actor', describe: 'Fetch all scenes for an actor',
type: 'boolean', type: 'boolean',
alias: 'actor-scenes',
default: false, default: false,
}) })
.option('actors-sources', { .option('actors-sources', {
describe: 'Use these scrapers for actor data', describe: 'Use these scrapers for actor data',
type: 'array', type: 'array',
alias: 'actor-source', alias: 'source',
}) })
.option('movie-scenes', { .option('movie-scenes', {
describe: 'Fetch all scenes for a movie', describe: 'Fetch all scenes for a movie',
@ -83,7 +82,6 @@ const { argv } = yargs
.option('scene-actors', { .option('scene-actors', {
describe: 'Scrape profiles for new actors after fetching scenes', describe: 'Scrape profiles for new actors after fetching scenes',
type: 'boolean', type: 'boolean',
alias: 'with-profiles',
default: false, default: false,
}) })
.option('scene', { .option('scene', {

View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
const util = require('util');
const config = require('config'); const config = require('config');
const logger = require('./logger')(__filename); const logger = require('./logger')(__filename);
@ -85,6 +86,9 @@ async function fetchChannelsFromArgv() {
} }
async function fetchChannelsFromConfig() { async function fetchChannelsFromConfig() {
console.log(config.include);
/*
const rawNetworks = await knex.raw(` const rawNetworks = await knex.raw(`
WITH RECURSIVE children AS ( WITH RECURSIVE children AS (
SELECT SELECT
@ -125,8 +129,71 @@ async function fetchChannelsFromConfig() {
config.include.networks, config.include.networks,
config.exclude.networks, config.exclude.networks,
]); ]);
*/
console.log(rawNetworks.rows); const rawNetworks = await knex.raw(`
/* select channels associated to configured networks */
WITH RECURSIVE channels AS (
/* select configured networks */
SELECT
id, parent_id, name, type, slug
FROM
entities
WHERE
(slug = ANY(:includeNetworks)
AND NOT entities.slug = ANY(:excludedNetworks))
AND entities.type = 'network'
UNION ALL
/* select recursive children of configured networks */
SELECT
entities.id, entities.parent_id, entities.name, entities.type, entities.slug
FROM
entities
INNER JOIN
channels ON channels.id = entities.parent_id
WHERE
NOT (
(entities.slug = ANY(:excludedNetworks) AND entities.type = 'network')
OR (entities.slug = ANY(:excludedChannels) AND entities.type = 'channel')
)
)
/* select recursive channels as children of networks */
SELECT
entities.*, json_agg(channels) as children
FROM
channels
LEFT JOIN
entities ON entities.id = channels.parent_id
WHERE
channels.type = 'channel'
GROUP BY
entities.id
UNION ALL
/* select configured channels as children of networks */
SELECT
entities.*, json_agg(children) as children
FROM
entities AS children
LEFT JOIN
entities ON entities.id = children.parent_id
WHERE
children.slug = ANY(:includedChannels)
AND
children.type = 'channel'
GROUP BY
entities.id
`, {
includedNetworks: config.include.networks,
includedChannels: config.include.channels,
excludedNetworks: config.exclude.networks,
excludedChannels: config.exclude.channels,
});
console.log(util.inspect(rawNetworks.rows, null, null));
/* /*
const curatedSites = await curateEntities(rawChannels, true); const curatedSites = await curateEntities(rawChannels, true);

View File

@ -61,7 +61,7 @@ function curateRelease(release, withMedia = false) {
}; };
} }
function withRelations(queryBuilder, withMedia = false, type = 'scene') { function withRelations(queryBuilder, withMedia = false) {
queryBuilder queryBuilder
.select(knex.raw(` .select(knex.raw(`
releases.id, releases.entry_id, releases.shoot_id, releases.title, releases.url, releases.date, releases.description, releases.duration, releases.created_at, releases.id, releases.entry_id, releases.shoot_id, releases.title, releases.url, releases.date, releases.description, releases.duration, releases.created_at,
@ -70,7 +70,6 @@ function withRelations(queryBuilder, withMedia = false, type = 'scene') {
COALESCE(json_agg(DISTINCT actors) FILTER (WHERE actors.id IS NOT NULL), '[]') as actors, COALESCE(json_agg(DISTINCT actors) FILTER (WHERE actors.id IS NOT NULL), '[]') as actors,
COALESCE(json_agg(DISTINCT tags) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags COALESCE(json_agg(DISTINCT tags) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags
`)) `))
.where('releases.type', type)
.leftJoin('entities', 'entities.id', 'releases.entity_id') .leftJoin('entities', 'entities.id', 'releases.entity_id')
.leftJoin('entities as parents', 'parents.id', 'entities.parent_id') .leftJoin('entities as parents', 'parents.id', 'entities.parent_id')
.leftJoin('releases_actors', 'releases_actors.release_id', 'releases.id') .leftJoin('releases_actors', 'releases_actors.release_id', 'releases.id')
@ -96,27 +95,27 @@ function withRelations(queryBuilder, withMedia = false, type = 'scene') {
} }
} }
async function fetchRelease(releaseId, type = 'scene') { async function fetchRelease(releaseId) {
const release = await knex('releases') const release = await knex('releases')
.where('releases.id', releaseId) .where('releases.id', releaseId)
.modify(withRelations, true, type) .modify(withRelations, true)
.first(); .first();
return curateRelease(release, true); return curateRelease(release, true);
} }
async function fetchReleases(limit = 100, type = 'scene') { async function fetchReleases(limit = 100) {
const releases = await knex('releases') const releases = await knex('releases')
.modify(withRelations, false, type) .modify(withRelations, false)
.limit(Math.min(limit, 1000)); .limit(Math.min(limit, 1000));
return releases.map(release => curateRelease(release)); return releases.map(release => curateRelease(release));
} }
async function searchReleases(query, limit = 100, type = 'scene') { async function searchReleases(query, limit = 100) {
const releases = await knex const releases = await knex
.from(knex.raw('search_releases(?) as releases', [query])) .from(knex.raw('search_releases(?) as releases', [query]))
.modify(withRelations, false, type) .modify(withRelations, false)
.limit(Math.min(limit, 1000)); .limit(Math.min(limit, 1000));
return releases.map(release => curateRelease(release)); return releases.map(release => curateRelease(release));