tongyifan/doubanphp

从豆瓣电影解析电影和电视剧元数据的库

0.1.1 2020-02-22 07:20 UTC

This package is auto-updated.

Last update: 2024-09-26 23:00:00 UTC


README

从豆瓣电影解析电影和电视剧元数据的库。该库使用来自 Rhilip/pt-gen-cfworker 的数据 API,包含缓存。

  1. 在 Cloudflare Worker 上设置自己的 pt-gen。参见 Rhilip/pt-gen-cfworker。然后更改 conf/config.ini 中的 api_endpoint 为您的 cfworker。

  2. 要求

  • PHP >= 5.6
  • PHP cURL 扩展
  • PHP JSON 扩展
  1. 安装
composer install tongyifan/doubanphp
  1. 用法
<?php
require 'vendor/autoload.php';

use Douban\Douban;

$douban_id = '30458442';
$douban = new Douban($douban_id);

$douban_rating = $douban->douban_rating;
  1. 高级用法
  • 您可以通过更改 conf/config.ini 来更改缓存设置。
  • 或者直接在您的应用程序中更改。
<?php
require 'vendor/autoload.php';

use Douban\Douban;
use Douban\Config;

$config = new Config();
// see https://book.cakephp.com.cn/3/en/core-libraries/caching.html for more information.
$config->cache_config = [
    'className' => 'Redis',
    'duration' => '+14 days',
    'prefix' => 'doubanphp_',
    'host' => '127.0.0.1',
    'port' => 6379
];

$imdb_id = 'tt11043632';
$douban = new Douban($imdb_id, null, $config);
$douban_rating = $douban->douban_rating;

// or use numeric IMDb id, but you should add "source".
$imdb_id = '11043632';
$douban = new Douban($imdb_id, 'imdb', $config);
$douban_rating = $douban->douban_rating;