askancy/howlongtobeat

A PHP wrapper to fetch data from howlongtobeat.com with dynamic API key extraction

dev-master 2025-06-01 18:16 UTC

This package is auto-updated.

Last update: 2025-06-01 18:16:33 UTC


README

A modern PHP wrapper to fetch game duration data from HowLongToBeat.com
Perfect for gaming apps, backlog tools, or completionist dashboards.

Packagist Version Packagist Downloads License

✨ Features

  • 🔍 Search games by title
  • ⏱ Get main/extra/completionist durations
  • 🧩 Fetch rich game details including platforms, stats, and genres
  • ⚡ Fully PSR-4, Guzzle-powered, clean and extendable

📦 Installation

Install via Composer:

composer require askancy/howlongtobeat

🚀 Usage

🔎 Search games

use Askancy\HowLongToBeat\HowLongToBeat;

$hl2b = new HowLongToBeat();
$results = $hl2b->search('Lego');

Sample response:

{
  "Results": [
    {
      "ID": "5265",
      "Title": "LEGO The Lord of the Rings",
      "Image": "https://howlongtobeat.com/gameimages/220px-Lego_Lord_of_the_Rings_cover.jpg",
      "Summary": {
        "Main Story": "10 Hours",
        "Main + Extra": "16 Hours",
        "Completionist": "33 Hours"
      }
    }
  ],
  "Pagination": {
    "Current Page": 1,
    "Last Page": 4
  }
}

You can also paginate:

$hl2b->search('Lego', 2);

🧠 Get game details by ID

$details = $hl2b->get(5265);

🚤 Laravel Example

You can easily integrate this wrapper into a Laravel controller or service class:

Controller example:

use Askancy\HowLongToBeat\HowLongToBeat;

class GameController extends Controller
{
    public function search(Request $request)
    {
        $query = $request->input('title');
        $hl2b = new HowLongToBeat();
        $results = $hl2b->search($query);

        return view('games.results', ['results' => $results]);
    }

    public function show($id)
    {
        $hl2b = new HowLongToBeat();
        $game = $hl2b->get($id);

        return view('games.show', ['game' => $game]);
    }
}

Then route it:

Route::get('/games/search', [GameController::class, 'search']);
Route::get('/games/{id}', [GameController::class, 'show']);

Includes:

  • Full summary and description
  • Developer & publisher info
  • Platform stats
  • Time breakdowns (Main, 100%, Speedrun, Multiplayer, etc.)

🤝 Contributing

Got a bug or an idea?
Open an issue or send a PR — contributions are welcome!

git clone https://github.com/askancy/howlongtobeat.git
composer install
vendor/bin/phpunit

📜 License

Released under the MIT License.