101 lines
3.3 KiB
JavaScript
101 lines
3.3 KiB
JavaScript
'use strict';
|
|
|
|
const util = require('util');
|
|
|
|
const argv = require('./argv');
|
|
const initServer = require('./web/server');
|
|
|
|
const knex = require('./knex');
|
|
const fetchUpdates = require('./updates');
|
|
const { fetchScenes, fetchMovies } = require('./deep');
|
|
const { storeScenes, storeMovies, updateReleasesSearch, associateMovieScenes } = require('./store-releases');
|
|
const { scrapeActors, flushActors, flushProfiles, interpolateProfiles } = require('./actors');
|
|
const { flushEntities } = require('./entities');
|
|
const { deleteScenes, deleteMovies, flushScenes, flushBatches } = require('./releases');
|
|
const { flushOrphanedMedia } = require('./media');
|
|
const getFileEntries = require('./utils/file-entries');
|
|
|
|
async function init() {
|
|
if (argv.server) {
|
|
await initServer();
|
|
return;
|
|
}
|
|
|
|
if (argv.updateSearch) {
|
|
await updateReleasesSearch();
|
|
}
|
|
|
|
if (argv.interpolateProfiles) {
|
|
await interpolateProfiles(argv.interpolateProfiles.length > 0 ? argv.interpolateProfiles : null);
|
|
}
|
|
|
|
if (argv.flushActors) {
|
|
await flushActors(argv.flushActors);
|
|
}
|
|
|
|
if (argv.flushProfiles) {
|
|
await flushProfiles(argv.flushProfiles.length > 0 ? argv.flushProfiles : null);
|
|
}
|
|
|
|
if (argv.flushNetworks || argv.flushChannels) {
|
|
await flushEntities(argv.flushNetworks, argv.flushChannels);
|
|
}
|
|
|
|
if (argv.flushBatches) {
|
|
await flushBatches(argv.flushBatches);
|
|
}
|
|
|
|
if (argv.flushScenes) {
|
|
await flushScenes();
|
|
}
|
|
|
|
if (argv.deleteScenes) {
|
|
await deleteScenes(argv.deleteScenes);
|
|
}
|
|
|
|
if (argv.deleteMovies) {
|
|
await deleteMovies(argv.deleteMovies);
|
|
}
|
|
|
|
if (argv.flushOrphanedMedia) {
|
|
await flushOrphanedMedia();
|
|
}
|
|
|
|
const actorsFromFile = argv.actorsFile && await getFileEntries(argv.actorsFile);
|
|
const actorNames = (argv.actors || []).concat(actorsFromFile || []);
|
|
|
|
const actors = (argv.actors || argv.actorsUpdate || argv.actorsFile) && await scrapeActors(actorNames);
|
|
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.scenes).flat().filter(Boolean);
|
|
|
|
const updateBaseScenes = (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) && await fetchUpdates();
|
|
|
|
const scenesFromFile = argv.scenesFile && await getFileEntries(argv.scenesFile);
|
|
const sceneUrls = (argv.scene || []).concat(scenesFromFile || []);
|
|
|
|
const deepScenes = argv.deep
|
|
? await fetchScenes([...(sceneUrls), ...(updateBaseScenes || []), ...(actorBaseScenes || [])])
|
|
: [...(updateBaseScenes || []), ...(actorBaseScenes || [])];
|
|
|
|
const sceneMovies = deepScenes ? deepScenes.map(scene => ({ ...scene.movie, entity: scene.entity })).filter(Boolean) : [];
|
|
const deepMovies = argv.sceneMovies || argv.movie ? await fetchMovies([...(argv.movie || []), ...(sceneMovies || [])]) : sceneMovies;
|
|
|
|
const movieScenes = argv.movieScenes ? deepMovies.map(movie => movie.scenes?.map(scene => ({ ...scene, movie, entity: movie.entity }))).flat().filter(Boolean) : [];
|
|
const deepMovieScenes = argv.deep ? await fetchScenes(movieScenes) : movieScenes;
|
|
|
|
if (argv.report) {
|
|
console.log(util.inspect(deepScenes, { depth: Infinity, colors: true }));
|
|
console.log(util.inspect(deepMovies, { depth: Infinity, colors: true }));
|
|
}
|
|
|
|
if (argv.save) {
|
|
const storedMovies = await storeMovies(deepMovies);
|
|
const storedScenes = await storeScenes([...(deepScenes || []), ...(deepMovieScenes || [])]);
|
|
|
|
await associateMovieScenes(storedMovies, storedScenes);
|
|
}
|
|
|
|
knex.destroy();
|
|
}
|
|
|
|
module.exports = init;
|