tissue/app/MetadataResolver/MetadataResolver.php

31 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\MetadataResolver;
class MetadataResolver implements Resolver
{
public $rules = [
'~(((sp\.)?seiga\.nicovideo\.jp/seiga(/#!)?|nico\.ms))/im~' => NicoSeigaResolver::class,
'~nijie\.info/view(_popup)?\.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,
2018-11-20 23:31:57 +09:00
'~iwara\.tv/videos/.*~' => IwaraResolver::class,
2019-01-14 04:22:40 +09:00
'~www\.dlsite\.com/.*/work/=/product_id/..\d+\.html~' => DLsiteResolver::class,
2019-01-14 16:01:58 +09:00
'~www\.pixiv\.net/member_illust\.php\?illust_id=\d+~' => PixivResolver::class,
2019-01-14 22:55:01 +09:00
'~fantia\.jp/posts/\d+~' => FantiaResolver::class,
'/.*/' => 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.');
}
}