Use climate directly and laravel built in progressbar in console commands

This commit is contained in:
DariusIII
2023-03-23 16:45:18 +01:00
parent 516a9406b7
commit 2f8cbc6963
8 changed files with 101 additions and 98 deletions
+5
View File
@@ -118,4 +118,9 @@ class ColorCLI
{
return $this->climate->progress();
}
public function climate()
{
return $this->climate;
}
}
-3
View File
@@ -40,7 +40,6 @@ class FanartTV
/**
* Getting movie pictures.
*
* @param string $id
* @return array|false
*/
public function getMovieFanArt(string $id): bool|array
@@ -60,7 +59,6 @@ class FanartTV
/**
* Getting tv show pictures.
*
* @param string $id
* @return array|false
*/
public function getTVFanart(string $id): bool|array
@@ -80,7 +78,6 @@ class FanartTV
/**
* The function making all the work using curl to call.
*
* @param string $path
* @return false|array
*/
private function _getUrl(string $path): bool|array
+4 -29
View File
@@ -15,23 +15,15 @@ class TraktAPI
{
protected const API_URL = 'https://api.trakt.tv/';
/**
* @var array
*/
private static array $types = ['imdb', 'tmdb', 'trakt', 'tvdb'];
/**
* List of headers to send to Trakt.tv when making a request.
*
* @see http://docs.trakt.apiary.io/#introduction/required-headers
*
* @var array
*/
private array $requestHeaders;
/**
* @var Client
*/
protected Client $client;
/**
@@ -53,11 +45,6 @@ class TraktAPI
}
/**
* @param int $id
* @param string $season
* @param string $ep
* @param string $type
* @return bool|array
* @throws GuzzleException
*/
public function episodeSummary(int $id, string $season = '', string $ep = '', string $type = 'min'): bool|array
@@ -78,7 +65,6 @@ class TraktAPI
}
/**
* @return bool|array
* @throws GuzzleException+
*/
public function getBoxOffice(): bool|array
@@ -94,9 +80,6 @@ class TraktAPI
}
/**
* @param string $start
* @param int $days
* @return bool|array
* @throws GuzzleException
*/
public function getCalendar(string $start = '', int $days = 7): bool|array
@@ -112,9 +95,8 @@ class TraktAPI
}
/**
* @param string $URI
* @param string $extended
* @return array|false
*
* @throws GuzzleException
*/
private function getJsonArray(string $URI, string $extended = 'min'): bool|array
@@ -153,9 +135,8 @@ class TraktAPI
}
/**
* @param string $movie
* @param string $type
* @return array|bool|mixed
*
* @throws GuzzleException
*/
public function movieSummary(string $movie = '', string $type = 'imdbid'): mixed
@@ -176,10 +157,8 @@ class TraktAPI
}
/**
* @param int|string $id
* @param string $site
* @param int|string $type
* @return array|bool|void
*
* @throws GuzzleException
*/
public function searchId(int|string $id, string $site = 'trakt', int|string $type = 0)
@@ -210,9 +189,6 @@ class TraktAPI
}
/**
* @param string $show
* @param string $type
* @return array|bool
* @throws GuzzleException
*/
public function showSearch(string $show = '', string $type = 'show'): bool|array
@@ -225,9 +201,8 @@ class TraktAPI
}
/**
* @param string $show
* @param string $type
* @return array|bool|void
*
* @throws GuzzleException
*/
public function showSummary(string $show = '', string $type = 'full')
+4 -4
View File
@@ -111,8 +111,8 @@ class TMDB extends TV
}
} else {
if ($this->echooutput) {
$this->colorCli->primaryOver('Found local TMDB match for: '.$release['cleanname']);
$this->colorCli->primary('. Attempting episode lookup!', true);
$this->colorCli->climate()->info('Found local TMDB match for: '.$release['cleanname']);
$this->colorCli->climate()->info('. Attempting episode lookup!');
}
$tmdbid = $this->getSiteIDFromVideoID('tmdb', $videoId);
}
@@ -127,7 +127,7 @@ class TMDB extends TV
if ($episodeNo === 'all') {
// Set the video ID and leave episode 0
$this->setVideoIdFound($videoId, $row['id'], 0);
$this->colorCli->primary('Found TMDB Match for Full Season!', true);
$this->colorCli->climate()->info('Found TMDB Match for Full Season!');
continue;
}
@@ -158,7 +158,7 @@ class TMDB extends TV
// Mark the releases video and episode IDs
$this->setVideoIdFound($videoId, $row['id'], $episode);
if ($this->echooutput) {
$this->colorCli->primary('Found TMDB Match!', true);
$this->colorCli->climate()->info('Found TMDB Match!');
}
} else {
//Processing failed, set the episode ID to the next processing group
+9 -13
View File
@@ -106,11 +106,9 @@ class TVDB extends TV
}
if ($tvDbId === false && $lookupSetting) {
// If it doesnt exist locally and lookups are allowed lets try to get it.
// If it doesn't exist locally and lookups are allowed lets try to get it.
if ($this->echooutput) {
$this->colorCli->primaryOver('Video ID for ').
$this->colorCli->headerOver($release['cleanname']).
$this->colorCli->primary(' not found in local db, checking web.', true);
$this->colorCli->climate()->error('Video ID for '.$release['cleanname'].' not found in local db, checking web.');
}
// Check if we have a valid country and set it in the array
@@ -129,9 +127,7 @@ class TVDB extends TV
$tvDbId = (int) $tvdbShow['tvdb'];
}
} elseif ($this->echooutput && $tvDbId !== false) {
$this->colorCli->primaryOver('Video ID for ').
$this->colorCli->headerOver($release['cleanname']).
$this->colorCli->primary(' found in local db, attempting episode match.', true);
$this->colorCli->climate()->info('Video ID for '.$release['cleanname'].' found in local db, attempting episode match.');
}
if ((int) $videoId > 0 && (int) $tvDbId > 0) {
@@ -145,7 +141,7 @@ class TVDB extends TV
if ($episodeNo === 'all') {
// Set the video ID and leave episode 0
$this->setVideoIdFound($videoId, $row['id'], 0);
$this->colorCli->primary('Found TVDB Match for Full Season!', true);
$this->colorCli->climate()->info('Found TVDB Match for Full Season!');
continue;
}
@@ -176,7 +172,7 @@ class TVDB extends TV
// Mark the releases video and episode IDs
$this->setVideoIdFound($videoId, $row['id'], $episode);
if ($this->echooutput) {
$this->colorCli->primary('Found TVDB Match!', true);
$this->colorCli->climate()->info('Found TVDB Match!');
}
} else {
//Processing failed, set the episode ID to the next processing group
@@ -220,7 +216,7 @@ class TVDB extends TV
try {
$response = $this->client->search()->search($cleanName, ['type' => 'series']);
} catch (ResourceNotFoundException $e) {
$this->colorCli->notice('Show not found on TVDB', true);
$this->colorCli->climate()->error('Show not found on TVDB');
}
if ($response === false && $country !== '') {
@@ -228,7 +224,7 @@ class TVDB extends TV
$response = $this->client->search()->search(rtrim(str_replace($country, '', $cleanName)));
} catch (ResourceNotFoundException $e) {
$response = false;
$this->colorCli->notice('Show not found on TVDB', true);
$this->colorCli->climate()->error('Show not found on TVDB', true);
}
}
@@ -353,14 +349,14 @@ class TVDB extends TV
$poster = $this->client->series()->artworks($show->tvdb_id);
$this->posterUrl = ! empty($poster->image) ? $poster->image : '';
} catch (ResourceNotFoundException $e) {
$this->colorCli->notice('Poster image not found on TVDB', true);
$this->colorCli->climate()->error('Poster image not found on TVDB');
}
try {
$imdbId = $this->client->series()->extended($show->tvdb_id);
preg_match('/tt(?P<imdbid>\d{6,9})$/i', $imdbId->getIMDBId(), $imdb);
} catch (ResourceNotFoundException $e) {
$this->colorCli->notice('Show ImdbId not found on TVDB', true);
$this->colorCli->climate()->error('Show ImdbId not found on TVDB');
}
return [
+3 -5
View File
@@ -119,9 +119,7 @@ class TVMaze extends TV
}
} else {
if ($this->echooutput) {
$this->colorCli->primaryOver('Found local TVMaze match for: ').
$this->colorCli->headerOver($release['cleanname']).
$this->colorCli->primary('. Attempting episode lookup!', true);
$this->colorCli->climate()->info('Found local TVMaze match for: '.$release['cleanname'].'. Attempting episode lookup!');
}
$tvMazeId = $this->getSiteIDFromVideoID('tvmaze', $videoId);
}
@@ -136,7 +134,7 @@ class TVMaze extends TV
if ($episodeNo === 'all') {
// Set the video ID and leave episode 0
$this->setVideoIdFound($videoId, $row['id'], 0);
$this->colorCli->primary('Found TVMaze Match for Full Season!', true);
$this->colorCli->climate()->info('Found TVMaze Match for Full Season!', true);
continue;
}
@@ -167,7 +165,7 @@ class TVMaze extends TV
// Mark the releases video and episode IDs
$this->setVideoIdFound($videoId, $row['id'], $episode);
if ($this->echooutput) {
$this->colorCli->primary('Found TVMaze Match!', true);
$this->colorCli->climate()->info('Found TVMaze Match!', true);
}
} else {
//Processing failed, set the episode ID to the next processing group
+4 -5
View File
@@ -123,9 +123,8 @@ class TraktTv extends TV
}
} else {
if ($this->echooutput) {
$this->colorCli->primaryOver('Found local TMDB match for: ').
$this->colorCli->headerOver($release['cleanname']).
$this->colorCli->primary('. Attempting episode lookup!', true);
$this->colorCli->climate()->info('Found local TMDB match for: '.$release['cleanname']);
$this->colorCli->climate()->info(' Attempting episode lookup!');
}
$traktid = $this->getSiteIDFromVideoID('trakt', $videoId);
$this->localizedTZ = $this->getLocalZoneFromVideoID($videoId);
@@ -141,7 +140,7 @@ class TraktTv extends TV
if ($episodeNo === 'all') {
// Set the video ID and leave episode 0
$this->setVideoIdFound($videoId, $row['id'], 0);
$this->colorCli->primary('Found TRAKT Match for Full Season!', true);
$this->colorCli->climate()->info('Found TRAKT Match for Full Season!');
continue;
}
@@ -166,7 +165,7 @@ class TraktTv extends TV
// Mark the releases video and episode IDs
$this->setVideoIdFound($videoId, $row['id'], $episode);
if ($this->echooutput) {
$this->colorCli->primary('Found TRAKT Match!', true);
$this->colorCli->climate()->info('Found TRAKT Match!');
}
} else {
//Processing failed, set the episode ID to the next processing group
@@ -38,16 +38,6 @@ class NntmuxResetPostProcessing extends Command
*/
protected $description = 'Reset all, multiple or single release category postprocessing';
/**
* @var ColorCLI
*/
private $colorCli;
/**
* @var ConsoleTools
*/
private $consoleTools;
/**
* Create a new command instance.
*
@@ -56,8 +46,6 @@ class NntmuxResetPostProcessing extends Command
public function __construct()
{
parent::__construct();
$this->colorCli = new ColorCLI();
$this->consoleTools = new ConsoleTools();
}
/**
@@ -72,7 +60,10 @@ class NntmuxResetPostProcessing extends Command
$affected = 0;
$total = \count($qry);
if ($total > 0) {
$this->colorCli->info('Resetting all postprocessing');
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$this->info('Resetting all postprocessing');
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
[
@@ -93,10 +84,12 @@ class NntmuxResetPostProcessing extends Command
'nfostatus' => -1,
]
);
$this->consoleTools->overWritePrimary('Resetting Releases: '.$this->consoleTools->percentString(++$affected, $total));
$bar->advance();
}
$bar->finish();
$this->newLine();
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
} else {
foreach ($this->option('category') as $option) {
@@ -138,6 +131,9 @@ class NntmuxResetPostProcessing extends Command
{
$qry = Release::query()->whereNotNull('consoleinfo_id')->whereBetween('categories_id', [Category::GAME_ROOT, Category::GAME_OTHER])->get();
$total = $qry->count();
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
if ($total > 0) {
$conCount = 0;
foreach ($qry as $releases) {
@@ -145,11 +141,13 @@ class NntmuxResetPostProcessing extends Command
[
'consoleinfo_id' => null,
]);
$this->consoleTools->overWritePrimary('Resetting console releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' consoleinfo_id\'s reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' consoleinfo_id\'s reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
@@ -158,6 +156,9 @@ class NntmuxResetPostProcessing extends Command
$qry = Release::query()->whereNotNull('movieinfo_id')->whereBetween('categories_id', [Category::MOVIE_ROOT, Category::MOVIE_OTHER])->get();
$total = $qry->count();
if ($total > 0) {
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$conCount = 0;
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
@@ -165,11 +166,13 @@ class NntmuxResetPostProcessing extends Command
'movieinfo_id' => null,
'imdbid' => null,
]);
$this->consoleTools->overWritePrimary('Resetting Movie releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' movieinfo_id\'s reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' movieinfo_id\'s reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
@@ -178,17 +181,22 @@ class NntmuxResetPostProcessing extends Command
$qry = Release::query()->whereNotNull('gamesinfo_id')->where('categories_id', '=', Category::PC_GAMES)->get();
$total = $qry->count();
if ($total > 0) {
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$conCount = 0;
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
[
'gamesinfo_id' => null,
]);
$this->consoleTools->overWritePrimary('Resetting PC GAME releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' gamesinfo_id\'s reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' gamesinfo_id\'s reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
@@ -197,17 +205,22 @@ class NntmuxResetPostProcessing extends Command
$qry = Release::query()->whereNotNull('bookinfo_id')->whereBetween('categories_id', [Category::BOOKS_ROOT, Category::BOOKS_UNKNOWN])->get();
$total = $qry->count();
if ($total > 0) {
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$conCount = 0;
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
[
'bookinfo_id' => null,
]);
$this->consoleTools->overWritePrimary('Resetting book releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' bookinfo_id\'s reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' bookinfo_id\'s reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
@@ -216,17 +229,22 @@ class NntmuxResetPostProcessing extends Command
$qry = Release::query()->whereNotNull('musicinfo_id')->whereBetween('categories_id', [Category::MUSIC_ROOT, Category::MUSIC_OTHER])->get();
$total = $qry->count();
if ($total > 0) {
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$conCount = 0;
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
[
'musicinfo_id' => null,
]);
$this->consoleTools->overWritePrimary('Resetting music releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' musicinfo_id\'s reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' musicinfo_id\'s reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
@@ -235,17 +253,22 @@ class NntmuxResetPostProcessing extends Command
$qry = Release::query()->whereNotNull('xxxinfo_id')->whereBetween('categories_id', [Category::XXX_ROOT, Category::XXX_OTHER])->get();
$total = $qry->count();
if ($total > 0) {
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$conCount = 0;
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
[
'xxxinfo_id' => null,
]);
$this->consoleTools->overWritePrimary('Resetting xxx releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' xxxinfo_id\'s reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' xxxinfo_id\'s reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
@@ -254,6 +277,9 @@ class NntmuxResetPostProcessing extends Command
$qry = Release::query()->where('videos_id', '!=', 0)->where('tv_episodes_id', '!=', 0)->whereBetween('categories_id', [Category::TV_ROOT, Category::TV_OTHER])->get();
$total = $qry->count();
if ($total > 0) {
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$conCount = 0;
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
@@ -261,11 +287,13 @@ class NntmuxResetPostProcessing extends Command
'videos_id' => 0,
'tv_episodes_id' => 0,
]);
$this->consoleTools->overWritePrimary('Resetting tv releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' video_id\'s reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' video_id\'s reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
@@ -274,6 +302,9 @@ class NntmuxResetPostProcessing extends Command
$qry = Release::query()->whereBetween('categories_id', [Category::OTHER_ROOT, Category::OTHER_HASHED])->get();
$total = $qry->count();
if ($total > 0) {
$bar = $this->output->createProgressBar($total);
$bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this?
$bar->start();
$conCount = 0;
foreach ($qry as $releases) {
Release::query()->where('id', $releases->id)->update(
@@ -285,11 +316,13 @@ class NntmuxResetPostProcessing extends Command
'audiostatus' => 0,
'nfostatus' => -1,
]);
$this->consoleTools->overWritePrimary('Resetting misc releases: '.$this->consoleTools->percentString(++$conCount, $total));
$bar->advance();
}
$this->colorCli->info(number_format($conCount).' misc releases reset.');
$bar->finish();
$this->newLine();
$this->info(number_format($conCount).' misc releases reset.');
} else {
$this->colorCli->info('No releases to reset');
$this->info('No releases to reset');
}
}
}