Initial commit: Animexe Laravel platform
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?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}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user