2019-03-03 03:18:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-05-20 00:23:45 +00:00
|
|
|
const util = require('util');
|
|
|
|
|
2019-03-18 03:46:53 +00:00
|
|
|
const argv = require('./argv');
|
2019-05-06 00:01:57 +00:00
|
|
|
const initServer = require('./web/server');
|
2019-03-23 21:48:39 +00:00
|
|
|
|
2020-03-14 01:56:28 +00:00
|
|
|
const knex = require('./knex');
|
2020-03-16 03:10:52 +00:00
|
|
|
const fetchUpdates = require('./updates');
|
2020-03-21 01:48:24 +00:00
|
|
|
const { fetchScenes, fetchMovies } = require('./deep');
|
2020-08-08 16:10:59 +00:00
|
|
|
const { storeScenes, storeMovies, updateReleasesSearch } = require('./store-releases');
|
2020-12-29 23:16:05 +00:00
|
|
|
const { scrapeActors, interpolateProfiles } = require('./actors');
|
2020-10-19 00:02:21 +00:00
|
|
|
const { flushEntities } = require('./entities');
|
2020-10-24 22:52:40 +00:00
|
|
|
const { deleteScenes, deleteMovies, flushBatches } = require('./releases');
|
|
|
|
const { flushOrphanedMedia } = require('./media');
|
2020-07-15 01:24:47 +00:00
|
|
|
const getFileEntries = require('./utils/file-entries');
|
2020-03-14 01:56:28 +00:00
|
|
|
|
|
|
|
async function init() {
|
2020-05-14 02:26:05 +00:00
|
|
|
if (argv.server) {
|
|
|
|
await initServer();
|
|
|
|
return;
|
|
|
|
}
|
2020-03-14 01:56:28 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (argv.updateSearch) {
|
|
|
|
await updateReleasesSearch();
|
|
|
|
}
|
2020-03-28 00:40:02 +00:00
|
|
|
|
2020-12-29 23:16:05 +00:00
|
|
|
if (argv.interpolateProfiles) {
|
|
|
|
await interpolateProfiles(argv.interpolateProfiles);
|
|
|
|
}
|
|
|
|
|
2020-10-19 00:02:21 +00:00
|
|
|
if (argv.flushNetworks || argv.flushChannels) {
|
|
|
|
await flushEntities(argv.flushNetworks, argv.flushChannels);
|
|
|
|
}
|
|
|
|
|
2020-10-24 22:52:40 +00:00
|
|
|
if (argv.flushBatches) {
|
|
|
|
await flushBatches(argv.flushBatches);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.deleteScenes) {
|
|
|
|
await deleteScenes(argv.deleteScenes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.deleteMovies) {
|
|
|
|
await deleteMovies(argv.deleteMovies);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.flushOrphanedMedia) {
|
|
|
|
await flushOrphanedMedia();
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:24:47 +00:00
|
|
|
const actorsFromFile = argv.actorsFile && await getFileEntries(argv.actorsFile);
|
|
|
|
const actorNames = (argv.actors || []).concat(actorsFromFile || []);
|
|
|
|
|
2020-08-12 19:04:38 +00:00
|
|
|
const actors = (argv.actors || argv.actorsUpdate || argv.actorsFile) && await scrapeActors(actorNames);
|
2020-11-29 02:59:47 +00:00
|
|
|
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.scenes).flat().filter(Boolean);
|
2020-03-19 00:54:25 +00:00
|
|
|
|
2020-08-13 14:10:58 +00:00
|
|
|
const updateBaseScenes = (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) && await fetchUpdates();
|
2020-03-28 00:40:02 +00:00
|
|
|
|
2020-07-15 01:24:47 +00:00
|
|
|
const scenesFromFile = argv.scenesFile && await getFileEntries(argv.scenesFile);
|
2020-08-01 13:11:07 +00:00
|
|
|
const sceneUrls = (argv.scene || []).concat(scenesFromFile || []);
|
2020-07-15 01:24:47 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const deepScenes = argv.deep
|
2020-07-15 01:24:47 +00:00
|
|
|
? await fetchScenes([...(sceneUrls), ...(updateBaseScenes || []), ...(actorBaseScenes || [])])
|
2020-07-09 00:00:54 +00:00
|
|
|
: [...(updateBaseScenes || []), ...(actorBaseScenes || [])];
|
2020-03-16 03:10:52 +00:00
|
|
|
|
2020-08-08 16:10:59 +00:00
|
|
|
const sceneMovies = deepScenes && deepScenes.map(scene => scene.movie).filter(Boolean);
|
2020-08-21 01:55:51 +00:00
|
|
|
const deepMovies = argv.sceneMovies && await fetchMovies([...(argv.movie || []), ...(sceneMovies || [])]);
|
2020-03-16 03:10:52 +00:00
|
|
|
|
2020-09-10 21:49:24 +00:00
|
|
|
const movieScenes = argv.movieScenes ? deepMovies.map(movie => movie.scenes?.map(scene => ({ ...scene, entity: movie.entity }))).flat().filter(Boolean) : [];
|
|
|
|
const deepMovieScenes = argv.deep ? await fetchScenes(movieScenes) : movieScenes;
|
2020-08-08 16:10:59 +00:00
|
|
|
|
2020-12-02 20:26:55 +00:00
|
|
|
if (argv.report) {
|
2020-12-01 22:00:14 +00:00
|
|
|
console.log(util.inspect(deepScenes, { depth: Infinity, colors: true }));
|
|
|
|
console.log(util.inspect(deepMovies, { depth: Infinity, colors: true }));
|
2020-05-20 00:23:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (argv.save) {
|
2020-08-01 13:11:07 +00:00
|
|
|
if (deepMovies.length > 0) {
|
2020-08-10 19:39:55 +00:00
|
|
|
const storedMovieScenes = await storeScenes(deepMovieScenes);
|
|
|
|
|
2020-08-21 01:55:51 +00:00
|
|
|
await storeMovies(deepMovies, storedMovieScenes || []);
|
2020-08-01 13:11:07 +00:00
|
|
|
}
|
2020-08-12 01:30:20 +00:00
|
|
|
|
|
|
|
if (deepScenes.length > 0 || deepMovieScenes.length > 0) {
|
|
|
|
await storeScenes(deepScenes || []);
|
|
|
|
}
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
2020-03-16 03:10:52 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
knex.destroy();
|
2020-03-14 01:56:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
module.exports = init;
|