askancy/metacritic-api-php

PHP API scraper for Metacritic game scores, returns JSON data.

1.0 2025-06-04 10:16 UTC

This package is auto-updated.

Last update: 2025-06-04 10:22:28 UTC


README

Level up your apps with real-time Metacritic scores using this lightweight PHP package.
No API keys, no rate limits โ€” just smart scraping and structured JSON output. ๐Ÿง โšก

๐Ÿ“ฆ Install & Deploy

Install it via Composer and get your first score in less than 60 seconds:

composer require askancy/metacritic-api-php

๐Ÿ•น๏ธ How to Play (Usage)

require 'vendor/autoload.php';

use Askancy\Metacritic\MetacriticScraper;
use Askancy\Metacritic\Exceptions\MetacriticException;

$scraper = new MetacriticScraper();

try {
    $result = $scraper->fetch('elden-ring'); // Use the Metacritic slug
    echo json_encode($result, JSON_PRETTY_PRINT);
} catch (MetacriticException $e) {
    echo "๐Ÿ’ฅ Error: " . $e->getMessage();
}

๐Ÿง  Pro Tip: You can pass any valid slug like 'god-of-war-ragnarok', 'cyberpunk-2077', 'final-fantasy-vii-remake', etc.

๐Ÿงพ Sample JSON Response

{
  "slug": "elden-ring",
  "url": "https://www.metacritic.com/game/elden-ring",
  "score": "96"
}
  • slug: Slug used to build the URL
  • url: Full Metacritic link to the game page
  • score: Metacritic metascore (0-100)

๐Ÿงช Unit Testing (PHPUnit)

Run the full test suite to validate your setup:

composer install
vendor/bin/phpunit tests/

โœ… Includes:

  • Score presence and format check
  • Proper exception handling on 404 pages
  • JSON serialization test

๐Ÿ› ๏ธ Directory Structure

metacritic-api-php/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ MetacriticScraper.php        # Main class
โ”‚   โ””โ”€โ”€ Exceptions/
โ”‚       โ””โ”€โ”€ MetacriticException.php  # Custom error
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ MetacriticScraperTest.php    # PHPUnit test
โ”œโ”€โ”€ composer.json
โ”œโ”€โ”€ README.md

๐Ÿง™โ€โ™‚๏ธ Advanced Features

  • โœ… No API key required
  • โš ๏ธ Graceful error handling (timeouts, 404s)
  • ๐Ÿงฉ Easily extendable to retrieve more metadata (e.g., platforms, release date)
  • ๐Ÿ•ต๏ธโ€โ™€๏ธ Smart fallback: if JSON-LD fails, uses HTML metascore node

๐Ÿง  Game Dev Friendly

This package is perfect for:

  • Game databases ๐Ÿ—ƒ๏ธ
  • Gaming communities ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘
  • Game recommendation engines ๐Ÿค–
  • Gamified profiles or dashboards ๐Ÿ“Š

๐Ÿ“œ License

This package is licensed under the MIT License, with one twist:

โŒ Redistribution and reselling is NOT allowed. ๐Ÿ” Contributions and improvements are always welcome.

๐Ÿ”— Credits & Contact

Made with โค๏ธ by Askancy For support, bugs or PRs: GitHub Issues

๐Ÿ’ฌ "Always check the score, before you hit Play." ๐ŸŽฎ