2019-03-03 03:18:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-03-18 03:46:53 +00:00
|
|
|
const argv = require('./argv');
|
2019-11-16 02:33:36 +00:00
|
|
|
const knex = require('./knex');
|
2019-05-06 00:01:57 +00:00
|
|
|
const initServer = require('./web/server');
|
2019-03-23 21:48:39 +00:00
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const scrapeSites = require('./scrape-sites');
|
2020-03-09 04:06:37 +00:00
|
|
|
const { scrapeScenes, scrapeMovies, deepFetchReleases } = require('./scrape-releases');
|
2020-03-06 01:49:55 +00:00
|
|
|
const { storeReleases } = require('./releases');
|
2019-11-19 03:36:15 +00:00
|
|
|
const { scrapeActors, scrapeBasicActors } = require('./actors');
|
2019-03-11 03:19:36 +00:00
|
|
|
|
2020-02-20 01:35:23 +00:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
require('longjohn'); // eslint-disable-line global-require
|
|
|
|
}
|
|
|
|
|
2019-03-04 03:19:03 +00:00
|
|
|
async function init() {
|
2019-12-13 02:28:52 +00:00
|
|
|
if (argv.scene) {
|
2020-03-09 04:06:37 +00:00
|
|
|
await scrapeScenes(argv.scene);
|
2019-11-16 02:33:36 +00:00
|
|
|
}
|
2019-04-10 02:44:36 +00:00
|
|
|
|
2019-12-13 02:28:52 +00:00
|
|
|
if (argv.movie) {
|
2020-03-09 04:06:37 +00:00
|
|
|
await scrapeMovies(argv.movie);
|
2019-12-13 02:28:52 +00:00
|
|
|
}
|
2019-05-06 00:01:57 +00:00
|
|
|
|
2019-11-16 22:37:33 +00:00
|
|
|
if (argv.scrape || argv.networks || argv.sites) {
|
2019-11-16 02:33:36 +00:00
|
|
|
await scrapeSites();
|
2019-03-18 03:46:53 +00:00
|
|
|
}
|
2019-11-16 02:33:36 +00:00
|
|
|
|
2019-11-19 03:36:15 +00:00
|
|
|
if (argv.actors && argv.actors.length > 0) {
|
2020-01-31 00:55:55 +00:00
|
|
|
const actors = await scrapeActors();
|
|
|
|
|
|
|
|
if (argv.withReleases) {
|
2020-03-06 01:49:55 +00:00
|
|
|
const baseReleases = actors.map(actor => actor?.releases || []).flat();
|
|
|
|
const releases = await deepFetchReleases(baseReleases, null, 'scene');
|
2020-01-31 00:55:55 +00:00
|
|
|
|
2020-03-06 01:49:55 +00:00
|
|
|
await storeReleases(releases);
|
2020-01-31 00:55:55 +00:00
|
|
|
}
|
2019-11-17 02:56:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-25 03:26:49 +00:00
|
|
|
if (argv.actors && argv.actors.length === 0) {
|
2019-11-19 03:36:15 +00:00
|
|
|
await scrapeBasicActors();
|
2019-12-13 02:28:52 +00:00
|
|
|
}
|
2019-11-19 03:36:15 +00:00
|
|
|
|
2019-12-13 02:28:52 +00:00
|
|
|
if (argv.server) {
|
|
|
|
await initServer();
|
2019-11-19 03:36:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-13 02:28:52 +00:00
|
|
|
knex.destroy();
|
2019-03-03 03:18:33 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
module.exports = init;
|