traxxx/src/app.js

65 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
2020-05-20 00:23:45 +00:00
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 } = require('./store-releases');
const { scrapeActors } = require('./actors');
const getFileEntries = require('./utils/file-entries');
async function init() {
if (argv.server) {
await initServer();
return;
}
if (argv.updateSearch) {
await updateReleasesSearch();
}
const actorsFromFile = argv.actorsFile && await getFileEntries(argv.actorsFile);
const actorNames = (argv.actors || []).concat(actorsFromFile || []);
const actors = actorNames.length > 0 && await scrapeActors(actorNames);
const actorBaseScenes = argv.actors && argv.actorScenes && actors.map(actor => actor.releases).flat().filter(Boolean);
const updateBaseScenes = (argv.all || 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).filter(Boolean);
const deepMovies = await fetchMovies([...(argv.movie || []), ...(sceneMovies || [])]);
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));
}
if (argv.save) {
if (deepScenes.length + deepMovieScenes.length > 0) {
await storeScenes(deepScenes.concat(deepMovieScenes));
}
if (deepMovies.length > 0) {
await storeMovies(deepMovies);
}
}
knex.destroy();
}
2019-12-09 04:00:49 +00:00
module.exports = init;