From 72ab8bf101d11a60d3ee9ecc152fc0e5aaceb5f3 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 22:55:01 +0900 Subject: [PATCH] =?UTF-8?q?FantiaResolver=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/FantiaResolver.php | 38 +++++++++++++++++++++++ app/MetadataResolver/MetadataResolver.php | 1 + 2 files changed, 39 insertions(+) create mode 100644 app/MetadataResolver/FantiaResolver.php diff --git a/app/MetadataResolver/FantiaResolver.php b/app/MetadataResolver/FantiaResolver.php new file mode 100644 index 0000000..8e95bba --- /dev/null +++ b/app/MetadataResolver/FantiaResolver.php @@ -0,0 +1,38 @@ +get($url); + if ($res->getStatusCode() === 200) { + $ogpResolver = new OGPResolver(); + $metadata = $ogpResolver->parse($res->getBody()); + + $dom = new \DOMDocument(); + @$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8')); + $xpath = new \DOMXPath($dom); + + $node = $xpath->query("//meta[@property='twitter:image']")->item(0); + $ogpUrl = $node->getAttribute('content'); + + preg_match("~https:\/\/fantia\.s3\.amazonaws\.com\/uploads\/post\/file\/{$postId}\/ogp_(.*?).jpg~", $ogpUrl, $match); + $uuid = $match[1]; + + // 大きい画像に変換 + $metadata->image = "https://c.fantia.jp/uploads/post/file/{$postId}/main_{$uuid}.jpg"; + + return $metadata; + } else { + throw new \RuntimeException("{$res->getStatusCode()}: $url"); + } + } +} diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index 528c73c..cec63a6 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -13,6 +13,7 @@ class MetadataResolver implements Resolver '~iwara\.tv/videos/.*~' => IwaraResolver::class, '~www\.dlsite\.com/.*/work/=/product_id/..\d+\.html~' => DLsiteResolver::class, '~www\.pixiv\.net/member_illust\.php\?illust_id=\d+~' => PixivResolver::class, + '~fantia\.jp/posts/\d+~' => FantiaResolver::class, '/.*/' => OGPResolver::class ];