OGP画像が全て代替イメージになっていたため、サムネイルのスクレイピングを実施

This commit is contained in:
shibafu 2019-08-02 23:48:56 +09:00
parent fb84a1d416
commit e4ef935dd2

View File

@ -28,7 +28,17 @@ class ToranoanaResolver implements Resolver
$res = $this->client->get($url, ['cookies' => $cookieJar]);
if ($res->getStatusCode() === 200) {
return $this->ogpResolver->parse($res->getBody());
$metadata = $this->ogpResolver->parse($res->getBody());
$dom = new \DOMDocument();
@$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8'));
$xpath = new \DOMXPath($dom);
$imgNode = $xpath->query('//*[@id="preview"]//img')->item(0);
if ($imgNode !== null) {
$metadata->image = $imgNode->getAttribute('src');
}
return $metadata;
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}