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-03-29 02:00:46 +00:00
|
|
|
const { storeReleases, updateReleasesSearch } = require('./store-releases');
|
2020-05-14 02:26:05 +00:00
|
|
|
const { scrapeActors } = require('./actors');
|
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-05-20 01:03:42 +00:00
|
|
|
const actors = argv.actors && await scrapeActors(argv.actors);
|
|
|
|
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.releases).flat().filter(Boolean);
|
2020-03-19 00:54:25 +00:00
|
|
|
|
2020-06-27 00:57:30 +00:00
|
|
|
const updateBaseScenes = (argv.scrape || argv.channels || argv.networks) && await fetchUpdates();
|
2020-03-28 00:40:02 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const deepScenes = argv.deep
|
2020-05-20 01:03:42 +00:00
|
|
|
? await fetchScenes([...(argv.scenes || []), ...(updateBaseScenes || []), ...(actorBaseScenes || [])])
|
2020-05-14 02:26:05 +00:00
|
|
|
: updateBaseScenes;
|
2020-03-16 03:10:52 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const sceneMovies = deepScenes && argv.sceneMovies && deepScenes.map(scene => scene.movie).filter(Boolean);
|
|
|
|
const deepMovies = await fetchMovies([...(argv.movies || []), ...(sceneMovies || [])]);
|
2020-03-16 03:10:52 +00:00
|
|
|
|
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) {
|
|
|
|
await storeReleases([
|
|
|
|
...(deepScenes || []),
|
|
|
|
...(deepMovies || []),
|
|
|
|
]);
|
|
|
|
}
|
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;
|