通販サイトのメタデータ対応

This commit is contained in:
shibafu 2018-06-13 01:00:24 +09:00
parent 9bd22d9f77
commit 9646f90ce3
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace App\MetadataResolver;
use GuzzleHttp\Cookie\CookieJar;
class MelonbooksResolver implements Resolver
{
public function resolve(string $url): Metadata
{
$cookieJar = CookieJar::fromArray(['AUTH_ADULT' => '1'], 'www.melonbooks.co.jp');
$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");
}
}
}

View File

@ -8,6 +8,8 @@ class MetadataResolver implements Resolver
'~(((sp\.)?seiga\.nicovideo\.jp/seiga(/#!)?|nico\.ms))/im~' => NicoSeigaResolver::class,
'~nijie\.info/view\.php~' => NijieResolver::class,
'~komiflo\.com(/#!)?/comics/(\\d+)~' => KomifloResolver::class,
'~www\.melonbooks\.co\.jp/detail/detail\.php~' => MelonbooksResolver::class,
'~ec\.toranoana\.jp/tora_r/ec/item/.*~' => ToranoanaResolver::class,
'/.*/' => OGPResolver::class
];

View File

@ -0,0 +1,22 @@
<?php
namespace App\MetadataResolver;
use GuzzleHttp\Cookie\CookieJar;
class ToranoanaResolver implements Resolver
{
public function resolve(string $url): Metadata
{
$cookieJar = CookieJar::fromArray(['adflg' => '0'], 'ec.toranoana.jp');
$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");
}
}
}