エロ漫画のタイトルくらいは取りたかった
This commit is contained in:
parent
dfe149e969
commit
4dc4efe10d
30
app/MetadataResolver/KomifloResolver.php
Normal file
30
app/MetadataResolver/KomifloResolver.php
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ class MetadataResolver implements Resolver
|
|||||||
public $rules = [
|
public $rules = [
|
||||||
'~(((sp\.)?seiga\.nicovideo\.jp/seiga(/#!)?|nico\.ms))/im~' => NicoSeigaResolver::class,
|
'~(((sp\.)?seiga\.nicovideo\.jp/seiga(/#!)?|nico\.ms))/im~' => NicoSeigaResolver::class,
|
||||||
'~nijie\.info/view\.php~' => NijieResolver::class,
|
'~nijie\.info/view\.php~' => NijieResolver::class,
|
||||||
|
'~komiflo\.com(/#!)?/comics/(\\d+)~' => KomifloResolver::class,
|
||||||
'/.*/' => OGPResolver::class
|
'/.*/' => OGPResolver::class
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user