Merge pull request #469 from shikorism/fix/466-mobatwi
Twitterのサブドメイン対応用Resolverを追加
This commit is contained in:
commit
867cafa26b
@ -34,6 +34,7 @@ class MetadataResolver implements Resolver
|
||||
'~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class,
|
||||
'~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class,
|
||||
'~www\.hentai-foundry\.com/pictures/user/.+/\d+/.+~'=> HentaiFoundryResolver::class,
|
||||
'~(www\.)?((mobile|m)\.)?twitter\.com/(#!/)?[0-9a-zA-Z_]{1,15}/status(es)?/([0-9]+)/?(\\?.+)?$~' => TwitterResolver::class,
|
||||
];
|
||||
|
||||
public $mimeTypes = [
|
||||
|
33
app/MetadataResolver/TwitterResolver.php
Normal file
33
app/MetadataResolver/TwitterResolver.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\MetadataResolver;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class TwitterResolver 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
|
||||
{
|
||||
$url = preg_replace('/(www\.)?(mobile|m)\.twitter\.com/u', 'twitter.com', $url);
|
||||
|
||||
$res = $this->client->get($url);
|
||||
$html = (string) $res->getBody();
|
||||
|
||||
return $this->ogpResolver->parse($html);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user