From 72ab8bf101d11a60d3ee9ecc152fc0e5aaceb5f3 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 22:55:01 +0900 Subject: [PATCH 1/4] =?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 ]; From f134cbefa800527304f975555126d27c6809ef8b Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 23:08:37 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E6=8A=95=E7=A8=BF=E3=81=AB=E7=94=BB?= =?UTF-8?q?=E5=83=8F=E3=81=8C=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/FantiaResolver.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/MetadataResolver/FantiaResolver.php b/app/MetadataResolver/FantiaResolver.php index 8e95bba..85584a3 100644 --- a/app/MetadataResolver/FantiaResolver.php +++ b/app/MetadataResolver/FantiaResolver.php @@ -24,11 +24,14 @@ class FantiaResolver implements Resolver $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]; + // 投稿に画像がない場合(ogp.jpgでない場合)のみ大きい画像に変換する + if($ogpUrl != "http://fantia.jp/images/ogp.jpg"){ + 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"; + // 大きい画像に変換 + $metadata->image = "https://c.fantia.jp/uploads/post/file/{$postId}/main_{$uuid}.jpg"; + } return $metadata; } else { From 3dedb57fe4f669215872d0f54860a8e9a139e45e Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 23:46:39 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E6=AD=A3=E8=A6=8F=E8=A1=A8=E7=8F=BE?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/FantiaResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/MetadataResolver/FantiaResolver.php b/app/MetadataResolver/FantiaResolver.php index 85584a3..6720462 100644 --- a/app/MetadataResolver/FantiaResolver.php +++ b/app/MetadataResolver/FantiaResolver.php @@ -26,7 +26,7 @@ class FantiaResolver implements Resolver // 投稿に画像がない場合(ogp.jpgでない場合)のみ大きい画像に変換する if($ogpUrl != "http://fantia.jp/images/ogp.jpg"){ - preg_match("~https:\/\/fantia\.s3\.amazonaws\.com\/uploads\/post\/file\/{$postId}\/ogp_(.*?).jpg~", $ogpUrl, $match); + preg_match("~https://fantia\.s3\.amazonaws\.com/uploads/post/file/{$postId}/ogp_(.*?).jpg~", $ogpUrl, $match); $uuid = $match[1]; // 大きい画像に変換 From dcf31865a13902c69f964598f9adac9ed922568c Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 23:50:15 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E6=8B=A1=E5=BC=B5=E5=AD=90=E3=81=8Cpng?= =?UTF-8?q?=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/FantiaResolver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/MetadataResolver/FantiaResolver.php b/app/MetadataResolver/FantiaResolver.php index 6720462..3f801ca 100644 --- a/app/MetadataResolver/FantiaResolver.php +++ b/app/MetadataResolver/FantiaResolver.php @@ -26,11 +26,12 @@ class FantiaResolver implements Resolver // 投稿に画像がない場合(ogp.jpgでない場合)のみ大きい画像に変換する if($ogpUrl != "http://fantia.jp/images/ogp.jpg"){ - preg_match("~https://fantia\.s3\.amazonaws\.com/uploads/post/file/{$postId}/ogp_(.*?).jpg~", $ogpUrl, $match); + preg_match("~https://fantia\.s3\.amazonaws\.com/uploads/post/file/{$postId}/ogp_(.*?)\.(jpg|png)~", $ogpUrl, $match); $uuid = $match[1]; + $extension = $match[2]; // 大きい画像に変換 - $metadata->image = "https://c.fantia.jp/uploads/post/file/{$postId}/main_{$uuid}.jpg"; + $metadata->image = "https://c.fantia.jp/uploads/post/file/{$postId}/main_{$uuid}.{$extension}"; } return $metadata;