PatreonResolverを追加 (#51)

This commit is contained in:
Eai 2019-02-03 20:35:59 +09:00 committed by shibafu
parent 1835776a9c
commit e20bb75e00
2 changed files with 29 additions and 0 deletions

View File

@ -15,6 +15,7 @@ class MetadataResolver implements Resolver
'~www\.pixiv\.net/member_illust\.php\?illust_id=\d+~' => PixivResolver::class,
'~fantia\.jp/posts/\d+~' => FantiaResolver::class,
'~dmm\.co\.jp/~' => FanzaResolver::class,
'~www\.patreon\.com/~' => PatreonResolver::class,
'~www\.deviantart\.com/.*/art/.*~' => DeviantArtResolver::class,
'/.*/' => OGPResolver::class
];

View File

@ -0,0 +1,28 @@
<?php
namespace App\MetadataResolver;
use Carbon\Carbon;
class PatreonResolver 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());
parse_str(parse_url($metadata->image, PHP_URL_QUERY), $temp);
$expires_at_unixtime = $temp["token-time"];
$expires_at = Carbon::createFromTimestamp($expires_at_unixtime);
$metadata->expires_at = $expires_at;
return $metadata;
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}