1. Go to this page and download the library: Download zyan/v2d library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Zyan\V2d\Adapters\Douyin\DouyinAdapter;
use Zyan\V2d\Adapters\Kuaishou\KuaishouAdapter;
use Zyan\V2d\Adapters\Xiaohongshu\XiaohongshuAdapter;
$douyin = new DouyinAdapter();
$result = $douyin->fetch('https://v.douyin.com/coTA27_qFBA/');
// 判断适配器是否支持某链接
$douyin->supports('https://v.douyin.com/xxx/'); // true
use Zyan\V2d\Adapters\Xiaohongshu\XiaohongshuAdapter;
$adapter = (new XiaohongshuAdapter())
->withCookie('webId=xxx; a1=xxx; web_session=xxx;');
$result = $adapter->fetch('http://xhslink.com/o/wjWTM5ZvMj');
use GuzzleHttp\Client;
use Zyan\V2d\V2d;
$client = new Client([
'proxy' => 'http://127.0.0.1:7890',
'timeout' => 20,
'verify' => false,
]);
$v2d = new V2d(null, $client);
$result = $v2d->fetch('https://v.kuaishou.com/Jdl248ZA');
use Zyan\V2d\Adapters\AbstractAdapter;
use Zyan\V2d\Results\Result;
class BilibiliAdapter extends AbstractAdapter
{
public function getPlatform(): string
{
return 'bilibili';
}
public function supports(string $url): bool
{
return (bool) preg_match('#b23\.tv/#i', $url);
}
public function fetch(string $url): Result
{
// 解析逻辑...
}
}
$v2d = new V2d();
$v2d->register(new BilibiliAdapter());
use Zyan\V2d\V2d;
use Zyan\V2d\Exceptions\Exception;
try {
$result = (new V2d())->fetch($url);
} catch (Exception $e) {
// 统一捕获
echo $e->getMessage();
}