get($url); if ($res->getStatusCode() === 200) { $ogpResolver = new OGPResolver(); $metadata = $ogpResolver->parse($res->getBody()); preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illustId}_p0_square1200\.jpg~", $res->getBody(), $match); $illustThumbnailUrl = $match[0]; $illustUrl = $this->thumbnailToMasterUrl($illustThumbnailUrl); // 指定ページに変換 $illustUrl = str_replace('p0_master', "p{$page}_master", $illustUrl); $metadata->image = $this->proxize($illustUrl); return $metadata; } else { throw new \RuntimeException("{$res->getStatusCode()}: $url"); } } else { $client = new \GuzzleHttp\Client(); $res = $client->get($url); if ($res->getStatusCode() === 200) { $ogpResolver = new OGPResolver(); $metadata = $ogpResolver->parse($res->getBody()); // OGP がデフォルト画像であるようならなんとかして画像を取得する if (strpos($metadata->image, 'pixiv_logo.gif') || strpos($metadata->image, 'pictures.jpg')) { // 作品ページの場合のみ対応 if ($params['mode'] === 'medium') { preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illustId}(_p0)?_square1200\.jpg~", $res->getBody(), $match); $illustThumbnailUrl = $match[0]; $illustUrl = $this->thumbnailToMasterUrl($illustThumbnailUrl); $metadata->image = $this->proxize($illustUrl); } } return $metadata; } else { throw new \RuntimeException("{$res->getStatusCode()}: $url"); } } } }