エロ漫画のタイトルくらいは取りたかった

This commit is contained in:
shibafu 2018-06-08 00:44:42 +09:00
parent dfe149e969
commit 4dc4efe10d
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace App\MetadataResolver;
class KomifloResolver implements Resolver
{
public function resolve(string $url): Metadata
{
if (preg_match('~komiflo\.com(?:/#!)?/comics/(\\d+)~', $url, $matches) !== 1) {
throw new \RuntimeException("Unmatched URL Pattern: $url");
}
$id = $matches[1];
$client = new \GuzzleHttp\Client();
$res = $client->get('https://api.komiflo.com/content/id/' . $id);
if ($res->getStatusCode() === 200) {
$json = json_decode($res->getBody()->getContents(), true);
$metadata = new Metadata();
$metadata->title = $json['content']['data']['title'] ?? '';
$metadata->description = ($json['content']['attributes']['artists']['children'][0]['data']['name'] ?? '?') .
' - ' .
($json['content']['parents'][0]['data']['title'] ?? '?');
return $metadata;
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}

View File

@ -7,6 +7,7 @@ class MetadataResolver implements Resolver
public $rules = [
'~(((sp\.)?seiga\.nicovideo\.jp/seiga(/#!)?|nico\.ms))/im~' => NicoSeigaResolver::class,
'~nijie\.info/view\.php~' => NijieResolver::class,
'~komiflo\.com(/#!)?/comics/(\\d+)~' => KomifloResolver::class,
'/.*/' => OGPResolver::class
];