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-05-14 02:26:05 +00:00
|
|
|
const { scrapeActors } = require('./actors');
|
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-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-05-20 01:03:42 +00:00
|
|
|
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.releases).flat().filter(Boolean);
|
2020-03-19 00:54:25 +00:00
|
|
|
|
2020-07-17 02:33:05 +00:00
|
|
|
const updateBaseScenes = (argv.all || 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-01 13:11:07 +00:00
|
|
|
const deepMovies = await fetchMovies([...(argv.movie || []), ...(sceneMovies || [])]);
|
2020-03-16 03:10:52 +00:00
|
|
|
|
2020-08-08 16:10:59 +00:00
|
|
|
const movieScenes = deepMovies.map(movie => movie.scenes).flat().filter(Boolean);
|
|
|
|
const deepMovieScenes = await fetchScenes(movieScenes);
|
|
|
|
|
2020-05-20 00:23:45 +00:00
|
|
|
if (argv.inspect) {
|
|
|
|
console.log(util.inspect(deepScenes));
|
|
|
|
console.log(util.inspect(deepMovies));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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;
|