hooshid/metacritic-scraper

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

2.3.0 2024-07-31 06:43 UTC

This package is auto-updated.

Last update: 2024-09-22 03:54:08 UTC


README

Build Status Total Downloads Latest Stable Version License

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

安装

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

需求

  • PHP >= 7.3
  • PHP cURL扩展

通过composer安装

$ composer require hooshid/metacritic-scraper

运行示例

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

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

php -S localhost:8000

示例

获取电影数据

电影:The Matrix (1999) / 网址: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()类创建一个新的obj,然后调用extract方法,并将metacritic.com的URL作为第一个参数。

如果一切正常,则result键填充,如果不正常,则error键填充错误信息

电视剧:Game of Thrones (2011-2019) / 网址: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...",
      "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,person)

完整示例

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

相关项目

许可

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