Files
animexe/app/Console/Commands/FetchAniListImages.php
T
2026-07-14 00:01:48 +03:00

68 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Console\Commands;
use App\Models\Anime;
use App\Services\AniListService;
use Illuminate\Console\Command;
class FetchAniListImages extends Command
{
protected $signature = 'anime:fetch-images
{--missing : Sadece kapak veya banneri olmayan animeleri işle (varsayılan)}
{--all : Tüm animeleri işle (dolu alanların üzerine yazmaz)}
{--id= : Belirli bir anime ID}
{--limit=50 : Tek seferinde işlenecek maksimum sayı}';
protected $description = 'AniList\'ten kapak ve banner resimlerini çek';
public function handle(): void
{
$service = new AniListService();
$query = Anime::query();
if ($id = $this->option('id')) {
$query->where('id', $id);
} elseif (!$this->option('all')) {
// Varsayılan: eksik resmi olanlar
$query->where(function ($q) {
$q->whereNull('cover_image')->orWhere('cover_image', '')
->orWhereNull('banner_image')->orWhere('banner_image', '');
});
}
$limit = (int) $this->option('limit');
$animes = $query->limit($limit)->get();
if ($animes->isEmpty()) {
$this->info('Eksik resim bulunamadı.');
return;
}
$this->info("İşlenecek: {$animes->count()} anime");
$bar = $this->output->createProgressBar($animes->count());
$bar->start();
$ok = $skip = $fail = 0;
foreach ($animes as $anime) {
try {
$updated = $service->fillImages($anime);
$updated ? $ok++ : $skip++;
} catch (\Throwable $e) {
$fail++;
$this->newLine();
$this->warn("#{$anime->id} {$anime->title}: {$e->getMessage()}");
}
$bar->advance();
usleep(500_000); // AniList rate limit: 90 req/dakika
}
$bar->finish();
$this->newLine(2);
$this->info("Bitti — güncellendi: {$ok}, değişmedi: {$skip}, hata: {$fail}");
}
}