22 lines
641 B
PHP
22 lines
641 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\MetadataResolver;
|
||
|
|
||
|
use Illuminate\Support\Facades\Log;
|
||
|
|
||
|
class DLsiteResolver 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());
|
||
|
$metadata->image = str_replace("img_sam.jpg", "img_main.jpg", $metadata->image);
|
||
|
return $metadata;
|
||
|
} else {
|
||
|
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||
|
}
|
||
|
}
|
||
|
}
|