option('limit'); $batches = (int) $this->option('batches'); $startYear = (int) $this->option('start-year'); $endYear = (int) $this->option('end-year'); $this->info("Starting to build game library..."); $this->info("Will fetch {$limit} games per batch for {$batches} batches"); $this->info("Covering games released between {$startYear} and {$endYear}"); $totalProcessed = 0; $totalAdded = 0; $totalSkipped = 0; for ($batch = 1; $batch <= $batches; $batch++) { $this->newLine(); $this->info("Processing batch {$batch} of {$batches}"); // Generate a random year within our range $year = rand($startYear, $endYear); $startTimestamp = strtotime("{$year}-01-01"); $endTimestamp = strtotime("{$year}-12-31"); // Generate a random query to get diverse results $query = $this->generateRandomQuery(); $this->info("Searching for games from {$year} with query: {$query}"); $games = $igdbService->get(); if (empty($games)) { $this->warn("No games found for this batch. Moving to next batch..."); continue; } $this->info(sprintf('Found %d games. Processing...', count($games))); $bar = $this->output->createProgressBar(count($games)); $bar->start(); /** @var Game $gameData */ foreach ($games as $gameData) { $totalProcessed++; try { $igdbService->processGameData($gameData); $totalAdded++; } catch (\Exception $e) { $this->warn("\nFailed to process game: {$e->getMessage()}"); $totalSkipped++; } $bar->advance(); } $bar->finish(); // Add a small delay between batches to avoid rate limiting if ($batch < $batches) { $this->info("\nWaiting 2 seconds before next batch..."); sleep(2); } } $this->newLine(2); $this->info("Library building complete!"); $this->info("Total games processed: {$totalProcessed}"); $this->info("New games added: {$totalAdded}"); $this->info("Games skipped (invalid data): {$totalSkipped}"); return 0; } protected function generateRandomQuery(): string { $prefixes = ['', 'the ', 'super ', 'mega ', 'ultimate ']; $suffixes = ['', ' game', ' edition', ' deluxe', ' special']; $words = ['action', 'adventure', 'rpg', 'strategy', 'shooter', 'platformer', 'racing', 'sports', 'fighting', 'puzzle', 'simulation', 'horror']; $prefix = $prefixes[array_rand($prefixes)]; $word = $words[array_rand($words)]; $suffix = $suffixes[array_rand($suffixes)]; return $prefix . $word . $suffix; } }