Files
movies/app/Console/Commands/ItemProcessing/FetchItemDataCommand.php
T

92 lines
2.4 KiB
PHP
Raw Normal View History

2024-12-30 01:51:28 +02:00
<?php
namespace App\Console\Commands\ItemProcessing;
use App\Models\ItemToFetch;
2025-01-27 22:40:26 +02:00
use App\Models\ItemToFetchJobs;
use App\Models\Movie;
2024-12-30 01:51:28 +02:00
use App\Service\MediaProcessing\FactoryService;
2025-02-10 01:58:12 +02:00
use App\Service\MediaProcessing\MovieProcessingService;
use App\Service\MediaProcessing\ShowProcessingService;
2024-12-30 01:51:28 +02:00
use Illuminate\Console\Command;
class FetchItemDataCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
2025-02-10 01:58:12 +02:00
protected $signature = 'processing:fetch-item-data {type=movie} {batch=50} {job=Details} {tmdbId?}';
2024-12-30 01:51:28 +02:00
/**
* 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()
{
2025-02-10 01:58:12 +02:00
$this->info("Start");
2024-12-30 01:51:28 +02:00
$type = $this->argument('type');
$batch = $this->argument('batch');
$job = $this->argument('job');
2025-02-10 01:58:12 +02:00
$tmdbId = $this->argument('tmdbId');
2024-12-30 01:51:28 +02:00
2025-02-10 01:58:12 +02:00
$items = $this->getBatch($type, $batch, $job, $tmdbId);
2024-12-30 01:51:28 +02:00
2025-02-10 01:58:12 +02:00
$this->info("Processing ".count($items)." items of type `{$type}`.");
$this->processItems($items, $job, $type);
$this->info("Fin.");
2024-12-30 01:51:28 +02:00
}
2025-02-10 01:58:12 +02:00
private function getBatch(string $type, int $batch, string $job, int $tmdbId = null)
2024-12-30 01:51:28 +02:00
{
2025-02-10 01:58:12 +02:00
switch ($type){
case ItemToFetch::TYPE_MOVIE:
2026-03-07 13:29:50 +02:00
$items = MovieProcessingService::getBatch($batch, $job);
if ($items->count() == 0){
$items = MovieProcessingService::getMissingMoviesBatch($batch, $job);
}
return $items;
2025-02-10 01:58:12 +02:00
case ItemToFetch::TYPE_TV_SERIES:
return ShowProcessingService::getBatch($batch, $job, $tmdbId);
2025-01-27 22:40:26 +02:00
}
2024-12-30 01:51:28 +02:00
}
2025-02-10 01:58:12 +02:00
private function processItems(\Illuminate\Database\Eloquent\Collection $items, $job, $type)
2024-12-30 01:51:28 +02:00
{
2025-02-10 01:58:12 +02:00
$bar = $this->output->createProgressBar(count($items));
2024-12-30 01:51:28 +02:00
foreach ($items as $item) {
2025-10-09 00:22:54 +03:00
echo "Processing ".$item->tmdb_id."\n";
2025-02-10 01:58:12 +02:00
$this->processItem($item, $job, $type);
$bar->advance();
2024-12-30 01:51:28 +02:00
}
2025-02-10 01:58:12 +02:00
$bar->finish();
2024-12-30 01:51:28 +02:00
}
2025-02-10 01:58:12 +02:00
private function processItem($item, $job, $type)
2024-12-30 01:51:28 +02:00
{
2025-02-10 01:58:12 +02:00
$this->factoryService->process($item, $job, $type);
2024-12-30 01:51:28 +02:00
}
}