2018-04-15 02:05:41 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\MetadataResolver;
|
|
|
|
|
|
|
|
class MetadataResolver implements Resolver
|
|
|
|
{
|
|
|
|
public $rules = [
|
|
|
|
'~(((sp\.)?seiga\.nicovideo\.jp/seiga(/#!)?|nico\.ms))/im~' => NicoSeigaResolver::class,
|
2018-12-17 23:27:19 +09:00
|
|
|
'~nijie\.info/view(_popup)?\.php~' => NijieResolver::class,
|
2018-06-08 00:44:42 +09:00
|
|
|
'~komiflo\.com(/#!)?/comics/(\\d+)~' => KomifloResolver::class,
|
2018-06-13 01:00:24 +09:00
|
|
|
'~www\.melonbooks\.co\.jp/detail/detail\.php~' => MelonbooksResolver::class,
|
|
|
|
'~ec\.toranoana\.jp/tora_r/ec/item/.*~' => ToranoanaResolver::class,
|
2018-11-20 23:31:57 +09:00
|
|
|
'~iwara\.tv/videos/.*~' => IwaraResolver::class,
|
2018-04-15 02:05:41 +09:00
|
|
|
'/.*/' => OGPResolver::class
|
|
|
|
];
|
|
|
|
|
|
|
|
public function resolve(string $url): Metadata
|
|
|
|
{
|
|
|
|
foreach ($this->rules as $pattern => $class) {
|
|
|
|
if (preg_match($pattern, $url) === 1) {
|
|
|
|
$resolver = new $class;
|
|
|
|
return $resolver->resolve($url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \UnexpectedValueException('URL not matched.');
|
|
|
|
}
|
|
|
|
}
|