PlurkResolverを追加
This commit is contained in:
parent
eb97f01c79
commit
1beb411050
@ -23,6 +23,7 @@ class MetadataResolver implements Resolver
|
|||||||
'~www\.deviantart\.com/.*/art/.*~' => DeviantArtResolver::class,
|
'~www\.deviantart\.com/.*/art/.*~' => DeviantArtResolver::class,
|
||||||
'~\.syosetu\.com/n\d+[a-z]{2,}~' => NarouResolver::class,
|
'~\.syosetu\.com/n\d+[a-z]{2,}~' => NarouResolver::class,
|
||||||
'~ci-en\.jp/creator/\d+/article/\d+~' => CienResolver::class,
|
'~ci-en\.jp/creator/\d+/article/\d+~' => CienResolver::class,
|
||||||
|
'~www\.plurk\.com\/p\/.*~' => PlurkResolver::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
public $mimeTypes = [
|
public $mimeTypes = [
|
||||||
|
44
app/MetadataResolver/PlurkResolver.php
Normal file
44
app/MetadataResolver/PlurkResolver.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\MetadataResolver;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
|
class PlurkResolver implements Resolver
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Client
|
||||||
|
*/
|
||||||
|
private $client;
|
||||||
|
/**
|
||||||
|
* @var OGPResolver
|
||||||
|
*/
|
||||||
|
private $ogpResolver;
|
||||||
|
|
||||||
|
public function __construct(Client $client, OGPResolver $ogpResolver)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
$this->ogpResolver = $ogpResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolve(string $url): Metadata
|
||||||
|
{
|
||||||
|
$res = $this->client->get($url);
|
||||||
|
if ($res->getStatusCode() === 200) {
|
||||||
|
$metadata = $this->ogpResolver->parse($res->getBody());
|
||||||
|
|
||||||
|
$dom = new \DOMDocument();
|
||||||
|
@$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8'));
|
||||||
|
$xpath = new \DOMXPath($dom);
|
||||||
|
$imageNode = $xpath->query('//div[@class="text_holder"]/a[1]')->item(0);
|
||||||
|
|
||||||
|
if($imageNode) {
|
||||||
|
$metadata->image = $imageNode->getAttribute('href');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
} else {
|
||||||
|
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user