first commit

This commit is contained in:
2025-04-09 23:03:16 +03:00
commit 909d514552
129 changed files with 17249 additions and 0 deletions
+107
View File
@@ -0,0 +1,107 @@
<?php
namespace App\Console\Commands;
use App\Services\IgdbService;
use Illuminate\Console\Command;
use MarcReichel\IGDBLaravel\Models\Game;
class BuildGameLibrary extends Command
{
protected $signature = 'igdb:build-library
{--limit=100 : Number of games to fetch per batch}
{--batches=10 : Number of batches to process}
{--start-year=1980 : Start year for game releases}
{--end-year=2024 : End year for game releases}';
protected $description = 'Build a comprehensive game library by fetching games in batches';
public function handle(IgdbService $igdbService): int
{
$limit = (int) $this->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;
}
}