Skip to content

Commit

Permalink
Merge pull request #469 from shikorism/fix/466-mobatwi
Browse files Browse the repository at this point in the history
Twitterのサブドメイン対応用Resolverを追加
  • Loading branch information
shibafu528 committed Aug 16, 2020
2 parents 0ca1645 + 04d546b commit 867cafa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/MetadataResolver/MetadataResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
33 changes: 33 additions & 0 deletions app/MetadataResolver/TwitterResolver.php
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 867cafa

Please sign in to comment.