Merge pull request #469 from shikorism/fix/466-mobatwi

Twitterのサブドメイン対応用Resolverを追加
This commit is contained in:
shibafu 2020-08-16 16:17:00 +09:00 committed by GitHub
commit 867cafa26b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -34,6 +34,7 @@ class MetadataResolver implements Resolver
'~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class, '~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class,
'~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class, '~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class,
'~www\.hentai-foundry\.com/pictures/user/.+/\d+/.+~'=> HentaiFoundryResolver::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 = [ public $mimeTypes = [

View 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);
}
}