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

60 lines
1.7 KiB
PHP
Raw Permalink 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\DeepSeekService;
use Illuminate\Console\Command;
class GenerateDiscoveryHooks extends Command
{
protected $signature = 'anime:generate-hooks {--limit=50 : Kaç anime işlensin} {--force : Zaten hook olanları da yeniden üret}';
protected $description = 'Keşfet sayfası için anime hook metinlerini AI ile üret';
public function handle(DeepSeekService $ai): int
{
if (!$ai->isConfigured()) {
$this->error('DeepSeek API anahtarı ayarlanmamış.');
return 1;
}
$limit = (int) $this->option('limit');
$force = $this->option('force');
$query = Anime::where('is_published', true)->with('genres:id,name');
if (!$force) {
$query->whereNull('discovery_hook');
}
$animes = $query->limit($limit)->get();
if ($animes->isEmpty()) {
$this->info('Hook üretilecek anime bulunamadı.');
return 0;
}
$this->info("Toplam {$animes->count()} anime için hook üretiliyor...");
$bar = $this->output->createProgressBar($animes->count());
$bar->start();
$done = 0; $failed = 0;
foreach ($animes as $anime) {
$hook = $ai->generateDiscoveryHook($anime);
if ($hook) {
$anime->updateQuietly(['discovery_hook' => $hook]);
$done++;
} else {
$failed++;
}
$bar->advance();
usleep(300_000); // Rate limit — 0.3sn ara
}
$bar->finish();
$this->newLine();
$this->info("Tamamlandı: {$done} başarılı, {$failed} başarısız.");
return 0;
}
}