dopelgan/metacritic-scraper

从metacritic.com检索电影、游戏、专辑、电视剧、人物、视频、公司、故事信息的库

v0.9.0-beta 2024-03-04 14:03 UTC

This package is auto-updated.

Last update: 2024-09-04 15:09:49 UTC


README

Build Status Total Downloads Latest Stable Version License

使用这个Metacritic API,您可以在metacritic.com上搜索、浏览和提取电影、电视剧、音乐和游戏的数据。

安装

此库抓取metacritic.com,因此其网站更改可能会导致此库的部分功能失效。您可能每年需要更新几次。

要求

  • PHP >= 7.3
  • PHP cURL扩展

通过composer安装

$ composer require dopelgan/metacritic-scraper

运行示例

示例为您提供快速演示,以确保一切正常,一些示例代码,并让您轻松查看一些可用数据。

从此存储库根目录中的示例文件夹开始启动PHP内置的web服务器,并浏览到https://:8000

php -S localhost:8000

示例

获取电影数据

电影:黑客帝国 (1999) / URL: https://www.metacritic.com/movie/the-matrix

$metacritic = new Hooshid\MetacriticScraper\Metacritic();
$extract = $metacritic->extract("/movie/the-matrix");
$result = $extract['result'];
$error = $extract['error'];

// get all available data as json
echo json_encode($extract);

在上面的示例中,我们首先从Metacritic()类创建一个新的对象,然后调用extract方法,并在第一个参数中提供metacritic.com的URL。

如果一切正常,则result键被填充,如果不正常,则error键被填充,其中包含发生的错误

电视剧:权力的游戏 (2011-2019) / URL: https://www.metacritic.com/tv/game-of-thrones

$metacritic = new Hooshid\MetacriticScraper\Metacritic();
$extract = $metacritic->extract("/tv/game-of-thrones");
$result = $extract['result'];
$error = $extract['error'];

if ($error) {
    echo $error;
} else {
    echo $result['type']; // type (movie, tv, game, person and ...)
    echo $result['title']; // movie/series title
    echo $result['thumbnail']; // Poster thumbnail
    echo $result['summary']; // Summary
    echo $result['release_year']; // Release year
    echo $result['must_see']; // Must see?
    
    echo $result['meta_score']; // Meta Score
    echo $result['meta_votes']; // Meta Votes
    echo $result['user_score']; // User Score
    echo number_format($result['user_votes']); // User Votes
}

您必须始终首先捕获错误并获取结果。

搜索

$metacritic = new Hooshid\MetacriticScraper\Metacritic();
$result = $metacritic->search("it");

// get all available data as json
echo json_encode($result);
$metacritic = new Hooshid\MetacriticScraper\Metacritic();
$result = $metacritic->search("it", 0, "movie");

// output
{
  "results": [
    {
      "full_url": "https://www.metacritic.com/movie/it",
      "url": "/movie/it",
      "url_slug": "it",
      "title": "It",
      "description": "When children begin to disappear in the town of Derry, Maine, a group of young kids are faced with their biggest fears when they square off against an evil clown named Pennywise, whose history of...",
      "thumbnail": "https://static.metacritic.com/images/products/movies/8/ae92ae06d681d7eb2b0374d47787f3f8-78.jpg",
      "year": 2017,
      "type": "movie",
      "meta_score": 69,
      "must_see": false,
      "score_class": "positive"
    },
    {
        ...
    }
  ],
  "paginate": {
    "current_page": 0,
    "last_page": 16,
    "per_page": 10
  }
}

在上面的示例中,我们向方法提供了两个新参数,$page必须是整数,用作分页。

$type默认返回所有内容,但您可以指定此参数为(all,movie,tv,game,album,music,person,video,company,story)

完整示例

只需打开示例文件夹,我们在其中为您提供了所有示例和方法演示!

相关项目

许可

MIT许可证(MIT)。有关更多信息,请参阅许可文件