Added movie flush.

This commit is contained in:
DebaucheryLibrarian 2021-02-05 04:14:13 +01:00
parent a95a159978
commit 80fa953f60
2 changed files with 39 additions and 9 deletions

View File

@ -287,6 +287,10 @@ const { argv } = yargs
describe: 'Remove all scenes.',
type: 'boolean',
})
.option('flush-movies', {
describe: 'Remove all movies.',
type: 'boolean',
})
.option('delete-scenes', {
describe: 'Remove scenes by ID.',
type: 'array',

View File

@ -159,6 +159,24 @@ async function deleteScenes(sceneIds) {
return deleteCount;
}
async function deleteMovies(movieIds) {
if (movieIds.length === 0) {
return 0;
}
await knex('movies_scenes')
.whereIn('movie_id', movieIds)
.delete();
const deleteCount = await knex('movies')
.whereIn('id', movieIds)
.delete();
logger.info(`Removed ${deleteCount}/${movieIds.length} movies`);
return deleteCount;
}
async function flushScenes() {
const sceneIds = await knex('releases').select('id').pluck('id');
@ -180,18 +198,25 @@ async function flushScenes() {
logger.info(`Removed ${deleteCount}/${sceneIds.length} scenes`);
}
async function deleteMovies(movieIds) {
if (movieIds.length === 0) {
return 0;
}
async function flushMovies() {
const movieIds = await knex('movies').select('id').pluck('id');
const deleteCount = await knex('movies')
.whereIn('id', movieIds)
.delete();
const confirmed = await inquirer.prompt([{
type: 'confirm',
name: 'flushMovies',
message: `You are about to remove ${movieIds.length} movies. Are you sure?`,
default: false,
}]);
if (!confirmed.flushScenes) {
logger.warn('Confirmation rejected, not flushing scenes');
return;
}
const deleteCount = await deleteMovies(movieIds);
await flushOrphanedMedia();
logger.info(`Removed ${deleteCount}/${movieIds.length} movies`);
return deleteCount;
}
async function flushBatches(batchIds) {
@ -233,6 +258,7 @@ module.exports = {
fetchScene,
fetchScenes,
flushBatches,
flushMovies,
flushScenes,
searchScenes,
deleteScenes,