86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\ItemProcessing;
|
|
|
|
use App\Models\ItemToFetch;
|
|
use App\Models\ItemToFetchJobs;
|
|
use App\Models\Movie;
|
|
use App\Service\MediaProcessing\FactoryService;
|
|
use App\Service\MediaProcessing\MovieProcessingService;
|
|
use App\Service\MediaProcessing\ShowProcessingService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class FetchItemDataCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'processing:fetch-item-data {type=movie} {batch=50} {job=Details} {tmdbId?}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
private FactoryService $factoryService;
|
|
|
|
public function __construct(FactoryService $factoryService)
|
|
{
|
|
$this->factoryService = $factoryService;
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info("Start");
|
|
|
|
$type = $this->argument('type');
|
|
$batch = $this->argument('batch');
|
|
$job = $this->argument('job');
|
|
$tmdbId = $this->argument('tmdbId');
|
|
|
|
$items = $this->getBatch($type, $batch, $job, $tmdbId);
|
|
|
|
$this->info("Processing ".count($items)." items of type `{$type}`.");
|
|
|
|
$this->processItems($items, $job, $type);
|
|
|
|
$this->info("Fin.");
|
|
}
|
|
|
|
private function getBatch(string $type, int $batch, string $job, int $tmdbId = null)
|
|
{
|
|
switch ($type){
|
|
case ItemToFetch::TYPE_MOVIE:
|
|
return MovieProcessingService::getBatch($batch, $job);
|
|
case ItemToFetch::TYPE_TV_SERIES:
|
|
return ShowProcessingService::getBatch($batch, $job, $tmdbId);
|
|
}
|
|
}
|
|
|
|
private function processItems(\Illuminate\Database\Eloquent\Collection $items, $job, $type)
|
|
{
|
|
$bar = $this->output->createProgressBar(count($items));
|
|
|
|
foreach ($items as $item) {
|
|
$this->processItem($item, $job, $type);
|
|
$bar->advance();
|
|
}
|
|
|
|
$bar->finish();
|
|
}
|
|
|
|
private function processItem($item, $job, $type)
|
|
{
|
|
$this->factoryService->process($item, $job, $type);
|
|
}
|
|
|
|
|
|
}
|