mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 03:01:34 +00:00
Refactor ColorCLI class
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
$pdo = DB::connection()->getPdo();
|
||||
$consoletools = new ConsoleTools();
|
||||
$colorCli = new ColorCLI();
|
||||
$ran = false;
|
||||
|
||||
if (isset($argv[1]) && $argv[1] === 'all' && isset($argv[2]) && $argv[2] === 'true') {
|
||||
@@ -32,7 +33,7 @@ if (isset($argv[1]) && $argv[1] === 'all' && isset($argv[2]) && $argv[2] === 'tr
|
||||
$pdo->exec('TRUNCATE TABLE anidb_info');
|
||||
$pdo->exec('TRUNCATE TABLE anidb_episodes');
|
||||
}
|
||||
ColorCLI::header('Resetting all postprocessing');
|
||||
$colorCli->header('Resetting all postprocessing');
|
||||
$qry = $pdo->query('SELECT id FROM releases');
|
||||
$affected = 0;
|
||||
if ($qry instanceof \Traversable) {
|
||||
@@ -59,10 +60,10 @@ if (isset($argv[1]) && ($argv[1] === 'consoles' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE consoleinfo');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all Console postprocessing');
|
||||
$colorCli->header('Resetting all Console postprocessing');
|
||||
$where = ' WHERE consoleinfo_id IS NOT NULL';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed Console postprocessing');
|
||||
$colorCli->header('Resetting all failed Console postprocessing');
|
||||
$where = ' WHERE consoleinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::GAME_ROOT.' AND '.Category::GAME_OTHER;
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ if (isset($argv[1]) && ($argv[1] === 'consoles' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting Console Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' consoleinfoIDs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' consoleinfoIDs reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'games' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
@@ -87,10 +88,10 @@ if (isset($argv[1]) && ($argv[1] === 'games' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE gamesinfo');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all Games postprocessing');
|
||||
$colorCli->header('Resetting all Games postprocessing');
|
||||
$where = ' WHERE gamesinfo_id != 0';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed Games postprocessing');
|
||||
$colorCli->header('Resetting all failed Games postprocessing');
|
||||
$where = ' WHERE gamesinfo_id IN (-2, 0) AND categories_id = 4050';
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ if (isset($argv[1]) && ($argv[1] === 'games' || $argv[1] === 'all')) {
|
||||
$pdo->exec('UPDATE releases SET gamesinfo_id = 0 WHERE id = '.$releases['id']);
|
||||
$consoletools->overWritePrimary('Resetting Games Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' gameinfo_IDs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' gameinfo_IDs reset.');
|
||||
}
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'movies' || $argv[1] === 'all')) {
|
||||
@@ -116,10 +117,10 @@ if (isset($argv[1]) && ($argv[1] === 'movies' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE movieinfo');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all Movie postprocessing');
|
||||
$colorCli->header('Resetting all Movie postprocessing');
|
||||
$where = ' WHERE imdbid IS NOT NULL';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed Movie postprocessing');
|
||||
$colorCli->header('Resetting all failed Movie postprocessing');
|
||||
$where = ' WHERE imdbid IN (-2, 0) AND categories_id BETWEEN '.Category::MOVIE_ROOT.' AND '.Category::MOVIE_OTHER;
|
||||
}
|
||||
|
||||
@@ -136,7 +137,7 @@ if (isset($argv[1]) && ($argv[1] === 'movies' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting Movie Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' imdbIDs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' imdbIDs reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'music' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
@@ -144,10 +145,10 @@ if (isset($argv[1]) && ($argv[1] === 'music' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE musicinfo');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all Music postprocessing');
|
||||
$colorCli->header('Resetting all Music postprocessing');
|
||||
$where = ' WHERE musicinfo_id IS NOT NULL';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed Music postprocessing');
|
||||
$colorCli->header('Resetting all failed Music postprocessing');
|
||||
$where = ' WHERE musicinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::MUSIC_ROOT.' AND '.Category::MUSIC_OTHER;
|
||||
}
|
||||
|
||||
@@ -160,19 +161,19 @@ if (isset($argv[1]) && ($argv[1] === 'music' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting Music Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' musicinfo_ids reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' musicinfo_ids reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'misc' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all Additional postprocessing');
|
||||
$colorCli->header('Resetting all Additional postprocessing');
|
||||
$where = ' WHERE (haspreview != -1 AND haspreview != 0) OR (passwordstatus != -1 AND passwordstatus != 0) OR jpgstatus != 0 OR videostatus != 0 OR audiostatus != 0';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed Additional postprocessing');
|
||||
$colorCli->header('Resetting all failed Additional postprocessing');
|
||||
$where = ' WHERE haspreview < -1 OR haspreview = 0 OR passwordstatus < -1 OR passwordstatus = 0 OR jpgstatus < 0 OR videostatus < 0 OR audiostatus < 0';
|
||||
}
|
||||
|
||||
ColorCLI::primary('SELECT id FROM releases'.$where);
|
||||
$colorCli->primary('SELECT id FROM releases'.$where);
|
||||
$qry = $pdo->query('SELECT id FROM releases'.$where);
|
||||
if ($qry !== false) {
|
||||
$total = $qry->rowCount();
|
||||
@@ -186,7 +187,7 @@ if (isset($argv[1]) && ($argv[1] === 'misc' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' Releases reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' Releases reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'tv' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
@@ -196,10 +197,10 @@ if (isset($argv[1]) && ($argv[1] === 'tv' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE tv_episodes');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all TV postprocessing');
|
||||
$colorCli->header('Resetting all TV postprocessing');
|
||||
$where = ' WHERE videos_id != 0 AND tv_episodes_id != 0 AND categories_id BETWEEN '.Category::TV_ROOT.' AND '.Category::TV_OTHER;
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed TV postprocessing');
|
||||
$colorCli->header('Resetting all failed TV postprocessing');
|
||||
$where = ' WHERE tv_episodes_id < 0 AND categories_id BETWEEN '.Category::TV_ROOT.' AND '.Category::TV_OTHER;
|
||||
}
|
||||
|
||||
@@ -216,7 +217,7 @@ if (isset($argv[1]) && ($argv[1] === 'tv' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting TV Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' Video IDs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' Video IDs reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'anime' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
@@ -225,10 +226,10 @@ if (isset($argv[1]) && ($argv[1] === 'anime' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE anidb_episodes');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all Anime postprocessing');
|
||||
$colorCli->header('Resetting all Anime postprocessing');
|
||||
$where = ' WHERE categories_id = 5070';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed Anime postprocessing');
|
||||
$colorCli->header('Resetting all failed Anime postprocessing');
|
||||
$where = ' WHERE anidbid BETWEEN -2 AND -1 AND categories_id = '.Category::TV_ANIME;
|
||||
}
|
||||
|
||||
@@ -245,7 +246,7 @@ if (isset($argv[1]) && ($argv[1] === 'anime' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting Anime Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' anidbIDs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' anidbIDs reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'books' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
@@ -253,10 +254,10 @@ if (isset($argv[1]) && ($argv[1] === 'books' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE bookinfo');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all Book postprocessing');
|
||||
$colorCli->header('Resetting all Book postprocessing');
|
||||
$where = ' WHERE bookinfo_id IS NOT NULL';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed Book postprocessing');
|
||||
$colorCli->header('Resetting all failed Book postprocessing');
|
||||
$where = ' WHERE bookinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::BOOKS_ROOT.' AND '.Category::BOOKS_UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -269,7 +270,7 @@ if (isset($argv[1]) && ($argv[1] === 'books' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting Book Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' bookinfoIDs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' bookinfoIDs reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'xxx' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
@@ -277,10 +278,10 @@ if (isset($argv[1]) && ($argv[1] === 'xxx' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE xxxinfo');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all XXX postprocessing');
|
||||
$colorCli->header('Resetting all XXX postprocessing');
|
||||
$where = ' WHERE xxxinfo_id != 0';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed XXX postprocessing');
|
||||
$colorCli->header('Resetting all failed XXX postprocessing');
|
||||
$where = ' WHERE xxxinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::XXX_ROOT.' AND '.Category::XXX_X264;
|
||||
}
|
||||
|
||||
@@ -296,7 +297,7 @@ if (isset($argv[1]) && ($argv[1] === 'xxx' || $argv[1] === 'all')) {
|
||||
));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' xxxinfo_IDs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' xxxinfo_IDs reset.');
|
||||
}
|
||||
if (isset($argv[1]) && ($argv[1] === 'nfos' || $argv[1] === 'all')) {
|
||||
$ran = true;
|
||||
@@ -304,10 +305,10 @@ if (isset($argv[1]) && ($argv[1] === 'nfos' || $argv[1] === 'all')) {
|
||||
$pdo->exec('TRUNCATE TABLE release_nfos');
|
||||
}
|
||||
if (isset($argv[2]) && $argv[2] === 'true') {
|
||||
ColorCLI::header('Resetting all NFO postprocessing');
|
||||
$colorCli->header('Resetting all NFO postprocessing');
|
||||
$where = ' WHERE nfostatus != -1';
|
||||
} else {
|
||||
ColorCLI::header('Resetting all failed NFO postprocessing');
|
||||
$colorCli->header('Resetting all failed NFO postprocessing');
|
||||
$where = ' WHERE nfostatus < -1';
|
||||
}
|
||||
|
||||
@@ -320,12 +321,12 @@ if (isset($argv[1]) && ($argv[1] === 'nfos' || $argv[1] === 'all')) {
|
||||
$consoletools->overWritePrimary('Resetting NFO Releases: '.$consoletools->percentString(++$concount, $total));
|
||||
}
|
||||
}
|
||||
ColorCLI::header(PHP_EOL.number_format($concount).' NFOs reset.');
|
||||
$colorCli->header(PHP_EOL.number_format($concount).' NFOs reset.');
|
||||
}
|
||||
|
||||
if ($ran === false) {
|
||||
exit(
|
||||
ColorCLI::error(
|
||||
$colorCli->error(
|
||||
'\nThis script will reset postprocessing per category. It can also truncate the associated tables.'
|
||||
.'\nTo reset only those that have previously failed, those without covers, samples, previews, etc. use the '
|
||||
.'second argument false.\n'
|
||||
|
||||
Reference in New Issue
Block a user