不要な成否判定をやめる

This commit is contained in:
shibafu 2019-09-10 01:01:47 +09:00
parent 40fedf59d4
commit 59aec2c038

View File

@ -25,22 +25,18 @@ class NicoSeigaResolver implements Resolver
public function resolve(string $url): Metadata public function resolve(string $url): Metadata
{ {
$res = $this->client->get($url); $res = $this->client->get($url);
if ($res->getStatusCode() === 200) { $html = (string)$res->getBody();
$html = (string)$res->getBody(); $metadata = $this->ogpResolver->parse($html);
$metadata = $this->ogpResolver->parse($html); $crawler = new Crawler($html);
$crawler = new Crawler($html);
// タグ // タグ
$excludeTags = ['R-15']; $excludeTags = ['R-15'];
$metadata->tags = array_values(array_diff($crawler->filter('.tag')->extract(['_text']), $excludeTags)); $metadata->tags = array_values(array_diff($crawler->filter('.tag')->extract(['_text']), $excludeTags));
// ページURLからサムネイルURLに変換 // ページURLからサムネイルURLに変換
preg_match('~https?://(?:(?:sp\\.)?seiga\\.nicovideo\\.jp/seiga(?:/#!)?|nico\\.ms)/im(\\d+)~', $url, $matches); preg_match('~https?://(?:(?:sp\\.)?seiga\\.nicovideo\\.jp/seiga(?:/#!)?|nico\\.ms)/im(\\d+)~', $url, $matches);
$metadata->image = "https://lohas.nicoseiga.jp/thumb/${matches[1]}l?"; $metadata->image = "https://lohas.nicoseiga.jp/thumb/${matches[1]}l?";
return $metadata; return $metadata;
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
} }
} }