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}/{$illust_id}_p0_square1200\.jpg~", $res->getBody(), $match); $illust_thumbnail_url = $match[0]; $illust_url = $this->thumbnailToMasterUrl($illust_thumbnail_url); // 指定ページに変換 $illust_url = str_replace("p0_master", "p{$page}_master", $illust_url); $metadata->image = $this->proxize($illust_url); ; 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 (strpos(parse_url($url)["query"], "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}/{$illust_id}(_p0)?_square1200\.jpg~", $res->getBody(), $match); $illust_thumbnail_url = $match[0]; $illust_url = $this->thumbnailToMasterUrl($illust_thumbnail_url); $metadata->image = $this->proxize($illust_url); ; } } return $metadata; } else { throw new \RuntimeException("{$res->getStatusCode()}: $url"); } } } }