parent
1835776a9c
commit
e887f2d83e
@ -16,6 +16,7 @@ class MetadataResolver implements Resolver
|
|||||||
'~fantia\.jp/posts/\d+~' => FantiaResolver::class,
|
'~fantia\.jp/posts/\d+~' => FantiaResolver::class,
|
||||||
'~dmm\.co\.jp/~' => FanzaResolver::class,
|
'~dmm\.co\.jp/~' => FanzaResolver::class,
|
||||||
'~www\.deviantart\.com/.*/art/.*~' => DeviantArtResolver::class,
|
'~www\.deviantart\.com/.*/art/.*~' => DeviantArtResolver::class,
|
||||||
|
'~\.syosetu\.com/n\d+[a-z]{2,}~' => NarouResolver::class,
|
||||||
'/.*/' => OGPResolver::class
|
'/.*/' => OGPResolver::class
|
||||||
];
|
];
|
||||||
|
|
||||||
|
23
app/MetadataResolver/NarouResolver.php
Normal file
23
app/MetadataResolver/NarouResolver.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\MetadataResolver;
|
||||||
|
|
||||||
|
use GuzzleHttp\Cookie\CookieJar;
|
||||||
|
|
||||||
|
class NarouResolver implements Resolver
|
||||||
|
{
|
||||||
|
public function resolve(string $url): Metadata
|
||||||
|
{
|
||||||
|
$cookieJar = CookieJar::fromArray(['over18' => 'yes'], '.syosetu.com');
|
||||||
|
|
||||||
|
$client = new \GuzzleHttp\Client();
|
||||||
|
$res = $client->get($url, ['cookies' => $cookieJar]);
|
||||||
|
if ($res->getStatusCode() === 200) {
|
||||||
|
$ogpResolver = new OGPResolver();
|
||||||
|
|
||||||
|
return $ogpResolver->parse($res->getBody());
|
||||||
|
} else {
|
||||||
|
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user