2019-01-18 00:16:02 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\MetadataResolver;
|
|
|
|
|
|
|
|
class FanzaResolver implements Resolver
|
|
|
|
{
|
|
|
|
public function resolve(string $url): Metadata
|
|
|
|
{
|
|
|
|
$client = new \GuzzleHttp\Client();
|
|
|
|
$res = $client->get($url);
|
|
|
|
if ($res->getStatusCode() === 200) {
|
|
|
|
$ogpResolver = new OGPResolver();
|
|
|
|
$metadata = $ogpResolver->parse($res->getBody());
|
2019-01-19 03:02:37 +09:00
|
|
|
$metadata->image = preg_replace("~(pr|ps)\.jpg$~", 'pl.jpg', $metadata->image);
|
2019-01-18 00:16:02 +09:00
|
|
|
|
|
|
|
return $metadata;
|
|
|
|
} else {
|
|
|
|
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|