From 7baf51fc0912f771a6b8a7681225265af26cdd21 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 21 Aug 2019 03:40:47 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B8=E3=81=8D=E7=9B=B4=E3=81=97,=20?= =?UTF-8?q?=E3=82=BF=E3=82=B0=E5=AF=BE=E5=BF=9C,=20=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/NijieResolver.php | 37 ++++-- .../MetadataResolver/NijieResolverTest.php | 103 +++++++-------- .../Nijie/testAnimationGifResponse.html | 89 +++++++++++-- tests/fixture/Nijie/testMp4MovieResponse.html | 124 ++++++++++++++---- .../Nijie/testMultiplePictureResponse.html | 91 +++++++++++-- .../Nijie/testStandardPictureResponse.html | 97 ++++++++++++-- 6 files changed, 411 insertions(+), 130 deletions(-) diff --git a/app/MetadataResolver/NijieResolver.php b/app/MetadataResolver/NijieResolver.php index 35ae370..f511092 100644 --- a/app/MetadataResolver/NijieResolver.php +++ b/app/MetadataResolver/NijieResolver.php @@ -3,6 +3,7 @@ namespace App\MetadataResolver; use GuzzleHttp\Client; +use Symfony\Component\DomCrawler\Crawler; class NijieResolver implements Resolver { @@ -30,23 +31,31 @@ class NijieResolver implements Resolver $url = preg_replace('~view_popup\.php~', 'view.php', $url); } - $client = $this->client; - $res = $client->get($url); + $res = $this->client->get($url); if ($res->getStatusCode() === 200) { - $metadata = $this->ogpResolver->parse($res->getBody()); + $metadata = $this->ogpResolver->parse((string) $res->getBody()); + $html = (string) $res->getBody(); + $crawler = new Crawler($html); - $dom = new \DOMDocument(); - @$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8')); - $xpath = new \DOMXPath($dom); - $dataNode = $xpath->query('//script[substring(@type, string-length(@type) - 3, 4) = "json"]'); - foreach ($dataNode as $node) { - // 改行がそのまま入っていることがあるのでデコード前にエスケープが必要 - $imageData = json_decode(preg_replace('/\r?\n/', '\n', $node->nodeValue), true); - if (isset($imageData['thumbnailUrl']) && !ends_with($imageData['thumbnailUrl'], '.gif') && !ends_with($imageData['thumbnailUrl'], '.mp4')) { - $metadata->image = preg_replace('~nijie\\.info/.*/nijie_picture/~', 'nijie.info/nijie_picture/', $imageData['thumbnailUrl']); - break; - } + // DomCrawler内でjson内の日本語がHTMLエンティティに変換されるのでhtml_entity_decode + $json = html_entity_decode($crawler->filter('script[type="application/ld+json"]')->first()->text()); + + // 改行がそのまま入っていることがあるのでデコード前にエスケープが必要 + $data = json_decode(preg_replace('/\r?\n/', '\n', $json), true); + + $tags = $crawler->filter('#view-tag span.tag_name')->extract('_text'); + + $metadata->title = $data['name']; + $metadata->description = '投稿者: ' . $data['author']['name'] . PHP_EOL . $data['description']; + if ( + isset($data['thumbnailUrl']) && + !ends_with($data['thumbnailUrl'], '.gif') && + !ends_with($data['thumbnailUrl'], '.mp4') + ) { + // サムネイルからメイン画像に + $metadata->image = str_replace('__rs_l160x160/', '', $data['thumbnailUrl']); } + $metadata->tags = $tags; return $metadata; } else { diff --git a/tests/Unit/MetadataResolver/NijieResolverTest.php b/tests/Unit/MetadataResolver/NijieResolverTest.php index eaf50b0..a7bed13 100644 --- a/tests/Unit/MetadataResolver/NijieResolverTest.php +++ b/tests/Unit/MetadataResolver/NijieResolverTest.php @@ -25,10 +25,10 @@ class NijieResolverTest extends TestCase $this->createResolver(NijieResolver::class, $responseText); $metadata = $this->resolver->resolve('https://nijie.info/view.php?id=66384'); - $this->assertEquals('チンポップくんの日常ep.1「チンポップくんと釣り」 | ニジエ運営', $metadata->title); - $this->assertEquals("メールマガジン漫画のバックナンバー第一話です!\r\n最新話はメールマガジンより配信中です。", $metadata->description); - $this->assertRegExp('/pic\d+\.nijie\.info/', $metadata->image); - $this->assertNotRegExp('~/diff/main/~', $metadata->image); + $this->assertSame('チンポップくんの日常ep.1「チンポップくんと釣り」', $metadata->title); + $this->assertSame('投稿者: ニジエ運営' . PHP_EOL . 'メールマガジン漫画のバックナンバー第一話です!' . PHP_EOL . '最新話はメールマガジンより配信中です。', $metadata->description); + $this->assertSame('https://pic.nijie.net/04/nijie_picture/38_20131130155623.png', $metadata->image); + $this->assertSame(['ニジエたん', '釣り', 'チンポップ君の日常', '公式漫画'], $metadata->tags); if ($this->shouldUseMock()) { $this->assertSame('https://nijie.info/view.php?id=66384', (string) $this->handler->getLastRequest()->getUri()); } @@ -41,10 +41,10 @@ class NijieResolverTest extends TestCase $this->createResolver(NijieResolver::class, $responseText); $metadata = $this->resolver->resolve('https://nijie.info/view.php?id=202707'); - $this->assertEquals('ニジエ壁紙 | ニジエ運営', $metadata->title); - $this->assertEquals("ニジエのPCとiphone用(4.7inch推奨)の壁紙です。\r\n保存してご自由にお使いくださいませ。", $metadata->description); - $this->assertRegExp('/pic\d+\.nijie\.info/', $metadata->image); - $this->assertNotRegExp('~/diff/main/~', $metadata->image); + $this->assertSame('ニジエ壁紙', $metadata->title); + $this->assertSame('投稿者: ニジエ運営' . PHP_EOL . 'ニジエのPCとiphone用(4.7inch推奨)の壁紙です。' . PHP_EOL . '保存してご自由にお使いくださいませ。', $metadata->description); + $this->assertSame('https://pic.nijie.net/03/nijie_picture/38_20170209185801_0.png', $metadata->image); + $this->assertSame(['ニジエたん', '壁紙'], $metadata->tags); if ($this->shouldUseMock()) { $this->assertSame('https://nijie.info/view.php?id=202707', (string) $this->handler->getLastRequest()->getUri()); } @@ -57,9 +57,10 @@ class NijieResolverTest extends TestCase $this->createResolver(NijieResolver::class, $responseText); $metadata = $this->resolver->resolve('https://nijie.info/view.php?id=9537'); - $this->assertEquals('ニジエがgifに対応したんだってね 奥さん | 黒末アプコ', $metadata->title); - $this->assertEquals('アニメgifとか専門外なのでよくわかりませんでした', $metadata->description); - $this->assertRegExp('~/nijie\.info/pic/logo~', $metadata->image); + $this->assertSame('ニジエがgifに対応したんだってね 奥さん', $metadata->title); + $this->assertSame('投稿者: 黒末アプコ' . PHP_EOL . 'アニメgifとか専門外なのでよくわかりませんでした', $metadata->description); + $this->assertStringStartsWith('https://nijie.info/pic/logo/nijie_logo_og.png', $metadata->image); + $this->assertSame(['おっぱい', '陥没乳首', '眼鏡', 'GIFアニメ', 'ぶるんぶるん', 'アニメgif'], $metadata->tags); if ($this->shouldUseMock()) { $this->assertSame('https://nijie.info/view.php?id=9537', (string) $this->handler->getLastRequest()->getUri()); } @@ -72,74 +73,60 @@ class NijieResolverTest extends TestCase $this->createResolver(NijieResolver::class, $responseText); $metadata = $this->resolver->resolve('https://nijie.info/view.php?id=256283'); - $this->assertEquals('てすと | ニジエ運営', $metadata->title); - $this->assertEquals("H264動画てすと あとで消します\r\n\r\n今の所、H264コーデックのみ、出力時に音声なしにしないと投稿できません\r\n動画は勝手にループします", $metadata->description); - $this->assertRegExp('~/nijie\.info/pic/logo~', $metadata->image); + $this->assertEquals('てすと', $metadata->title); + $this->assertEquals('投稿者: ニジエ運営' . PHP_EOL . 'H264動画てすと あとで消します' . PHP_EOL . PHP_EOL . '今の所、H264コーデックのみ、出力時に音声なしにしないと投稿できません' . PHP_EOL . '動画は勝手にループします', $metadata->description); + $this->assertStringStartsWith('https://nijie.info/pic/logo/nijie_logo_og.png', $metadata->image); + $this->assertSame([], $metadata->tags); if ($this->shouldUseMock()) { $this->assertSame('https://nijie.info/view.php?id=256283', (string) $this->handler->getLastRequest()->getUri()); } } - public function testStandardPictureSp() + public function testViewPopup() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/Nijie/testStandardPictureResponse.html'); + + $this->createResolver(NijieResolver::class, $responseText); + + $metadata = $this->resolver->resolve('https://nijie.info/view_popup.php?id=66384'); + $this->assertSame('チンポップくんの日常ep.1「チンポップくんと釣り」', $metadata->title); + $this->assertSame('投稿者: ニジエ運営' . PHP_EOL . 'メールマガジン漫画のバックナンバー第一話です!' . PHP_EOL . '最新話はメールマガジンより配信中です。', $metadata->description); + $this->assertSame('https://pic.nijie.net/04/nijie_picture/38_20131130155623.png', $metadata->image); + $this->assertSame(['ニジエたん', '釣り', 'チンポップ君の日常', '公式漫画'], $metadata->tags); + if ($this->shouldUseMock()) { + $this->assertSame('https://nijie.info/view.php?id=66384', (string) $this->handler->getLastRequest()->getUri()); + } + } + + public function testSp() { $responseText = file_get_contents(__DIR__ . '/../../fixture/Nijie/testStandardPictureResponse.html'); $this->createResolver(NijieResolver::class, $responseText); $metadata = $this->resolver->resolve('https://sp.nijie.info/view.php?id=66384'); - $this->assertEquals('チンポップくんの日常ep.1「チンポップくんと釣り」 | ニジエ運営', $metadata->title); - $this->assertEquals("メールマガジン漫画のバックナンバー第一話です!\r\n最新話はメールマガジンより配信中です。", $metadata->description); - $this->assertRegExp('/pic\d+\.nijie\.info/', $metadata->image); - $this->assertNotRegExp('~/diff/main/~', $metadata->image); + $this->assertSame('チンポップくんの日常ep.1「チンポップくんと釣り」', $metadata->title); + $this->assertSame('投稿者: ニジエ運営' . PHP_EOL . 'メールマガジン漫画のバックナンバー第一話です!' . PHP_EOL . '最新話はメールマガジンより配信中です。', $metadata->description); + $this->assertSame('https://pic.nijie.net/04/nijie_picture/38_20131130155623.png', $metadata->image); + $this->assertSame(['ニジエたん', '釣り', 'チンポップ君の日常', '公式漫画'], $metadata->tags); if ($this->shouldUseMock()) { $this->assertSame('https://nijie.info/view.php?id=66384', (string) $this->handler->getLastRequest()->getUri()); } } - public function testMultiplePictureSp() + public function testSpViewPopup() { - $responseText = file_get_contents(__DIR__ . '/../../fixture/Nijie/testMultiplePictureResponse.html'); + $responseText = file_get_contents(__DIR__ . '/../../fixture/Nijie/testStandardPictureResponse.html'); $this->createResolver(NijieResolver::class, $responseText); - $metadata = $this->resolver->resolve('https://sp.nijie.info/view.php?id=202707'); - $this->assertEquals('ニジエ壁紙 | ニジエ運営', $metadata->title); - $this->assertEquals("ニジエのPCとiphone用(4.7inch推奨)の壁紙です。\r\n保存してご自由にお使いくださいませ。", $metadata->description); - $this->assertRegExp('/pic\d+\.nijie\.info/', $metadata->image); - $this->assertNotRegExp('~/diff/main/~', $metadata->image); + $metadata = $this->resolver->resolve('https://sp.nijie.info/view_popup.php?id=66384'); + $this->assertSame('チンポップくんの日常ep.1「チンポップくんと釣り」', $metadata->title); + $this->assertSame('投稿者: ニジエ運営' . PHP_EOL . 'メールマガジン漫画のバックナンバー第一話です!' . PHP_EOL . '最新話はメールマガジンより配信中です。', $metadata->description); + $this->assertSame('https://pic.nijie.net/04/nijie_picture/38_20131130155623.png', $metadata->image); + $this->assertSame(['ニジエたん', '釣り', 'チンポップ君の日常', '公式漫画'], $metadata->tags); if ($this->shouldUseMock()) { - $this->assertSame('https://nijie.info/view.php?id=202707', (string) $this->handler->getLastRequest()->getUri()); - } - } - - public function testAnimationGifSp() - { - $responseText = file_get_contents(__DIR__ . '/../../fixture/Nijie/testAnimationGifResponse.html'); - - $this->createResolver(NijieResolver::class, $responseText); - - - $metadata = $this->resolver->resolve('https://nijie.info/view.php?id=9537'); - $this->assertEquals('ニジエがgifに対応したんだってね 奥さん | 黒末アプコ', $metadata->title); - $this->assertEquals('アニメgifとか専門外なのでよくわかりませんでした', $metadata->description); - $this->assertRegExp('~/nijie\.info/pic/logo~', $metadata->image); - if ($this->shouldUseMock()) { - $this->assertSame('https://nijie.info/view.php?id=9537', (string) $this->handler->getLastRequest()->getUri()); - } - } - - public function testMp4MovieSp() - { - $responseText = file_get_contents(__DIR__ . '/../../fixture/Nijie/testMp4MovieResponse.html'); - - $this->createResolver(NijieResolver::class, $responseText); - - $metadata = $this->resolver->resolve('https://sp.nijie.info/view.php?id=256283'); - $this->assertEquals('てすと | ニジエ運営', $metadata->title); - $this->assertEquals("H264動画てすと あとで消します\r\n\r\n今の所、H264コーデックのみ、出力時に音声なしにしないと投稿できません\r\n動画は勝手にループします", $metadata->description); - $this->assertRegExp('~/nijie\.info/pic/logo~', $metadata->image); - if ($this->shouldUseMock()) { - $this->assertSame('https://nijie.info/view.php?id=256283', (string) $this->handler->getLastRequest()->getUri()); + $this->assertSame('https://nijie.info/view.php?id=66384', (string) $this->handler->getLastRequest()->getUri()); } } } diff --git a/tests/fixture/Nijie/testAnimationGifResponse.html b/tests/fixture/Nijie/testAnimationGifResponse.html index f618032..66eb16e 100644 --- a/tests/fixture/Nijie/testAnimationGifResponse.html +++ b/tests/fixture/Nijie/testAnimationGifResponse.html @@ -1,11 +1,78 @@ -ニジエがgifに対応したんだってね 奥さん | 黒末アプコ | ニジエ - - - - - - - - - - +ニジエがgifに対応したんだってね 奥さん | 黒末アプコ | ニジエ +

ニジエがgifに対応したんだってね 奥さん | 黒末アプコ

+
+ + +
+ +
+ diff --git a/tests/fixture/Nijie/testMp4MovieResponse.html b/tests/fixture/Nijie/testMp4MovieResponse.html index f80c7c1..fa63667 100644 --- a/tests/fixture/Nijie/testMp4MovieResponse.html +++ b/tests/fixture/Nijie/testMp4MovieResponse.html @@ -1,30 +1,108 @@ -てすと | ニジエ運営 | ニジエ - - - てすと | ニジエ運営 | ニジエ +

てすと | ニジエ運営

+ - - - -

 

good job

名無しのチンポップ

2018-04-10

- - - - +動画は勝手にループします","interactionCount": "3705 UserPlays, 6 UserComments","datePublished": "Sun Apr 1 23:07:03 2018","uploadDate": "Sun Apr 1 23:07:03 2018","dateModified": "Sun Apr 1 23:20:49 2018","copyrightYear": "2018","genre":"Image","contentLocation":"Japan","width":160,"height":90,"thumbnailUrl": "https://pic.nijie.net/01/__rs_l160x160/nijie_picture/38_20180401230701_0.mp4","author": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"creator": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"editor": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"copyrightHolder": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"}}
+ + +
+ +
+ diff --git a/tests/fixture/Nijie/testMultiplePictureResponse.html b/tests/fixture/Nijie/testMultiplePictureResponse.html index 70d7a8e..b0068fe 100644 --- a/tests/fixture/Nijie/testMultiplePictureResponse.html +++ b/tests/fixture/Nijie/testMultiplePictureResponse.html @@ -1,12 +1,83 @@ - - ニジエ壁紙 | ニジエ運営 | ニジエ - - +ニジエ壁紙 | ニジエ運営 | ニジエ +

ニジエ壁紙 | ニジエ運営

- - - +保存してご自由にお使いくださいませ。","interactionCount": "2613 UserPlays, 5 UserComments","datePublished": "Thu Feb 9 18:58:03 2017","uploadDate": "Thu Feb 9 18:58:03 2017","dateModified": "Thu Feb 9 18:58:03 2017","copyrightYear": "2017","genre":"Image","contentLocation":"Japan","width":160,"height":90,"thumbnailUrl": "https://pic.nijie.net/03/__rs_l160x160/nijie_picture/38_20170209185801_0.png","author": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"creator": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"editor": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"copyrightHolder": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"}}
+ + +
+ +
+ diff --git a/tests/fixture/Nijie/testStandardPictureResponse.html b/tests/fixture/Nijie/testStandardPictureResponse.html index 9d356db..b371920 100644 --- a/tests/fixture/Nijie/testStandardPictureResponse.html +++ b/tests/fixture/Nijie/testStandardPictureResponse.html @@ -1,16 +1,85 @@ -チンポップくんの日常ep.1「チンポップくんと釣り」 | ニジエ運営 | ニジエ - - - チンポップくんの日常ep.1「チンポップくんと釣り」 | ニジエ運営 | ニジエ +

チンポップくんの日常ep.1「チンポップくんと釣り」 | ニジエ運営

+ - - - - - - - - +最新話はメールマガジンより配信中です。","interactionCount": "13799 UserPlays, 24 UserComments","datePublished": "Sat Nov 30 15:56:26 2013","uploadDate": "Sat Nov 30 15:56:26 2013","dateModified": "Sat Nov 30 15:56:26 2013","copyrightYear": "2013","genre":"Image","contentLocation":"Japan","width":160,"height":90,"thumbnailUrl": "https://pic.nijie.net/04/__rs_l160x160/nijie_picture/38_20131130155623.png","author": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"creator": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"editor": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"},"copyrightHolder": {"@type": "Person","name": "ニジエ運営","description": "ニジエンジョイ!","sameAs": "https://nijie.info/members.php?id=38","image": "https://pic.nijie.net/04/__rs_cs150x150/members_picture/38_1511696698.png"}}
+ + +
+ +
+ From 93387f1ff5c51ea900599d22286f24cc3bcbe96b Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 21 Aug 2019 03:53:32 +0900 Subject: [PATCH 2/3] =?UTF-8?q?assertEquals=E6=92=B2=E6=BB=85=E5=A7=94?= =?UTF-8?q?=E5=93=A1=E4=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/MetadataResolver/NijieResolverTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/MetadataResolver/NijieResolverTest.php b/tests/Unit/MetadataResolver/NijieResolverTest.php index a7bed13..417a853 100644 --- a/tests/Unit/MetadataResolver/NijieResolverTest.php +++ b/tests/Unit/MetadataResolver/NijieResolverTest.php @@ -73,8 +73,8 @@ class NijieResolverTest extends TestCase $this->createResolver(NijieResolver::class, $responseText); $metadata = $this->resolver->resolve('https://nijie.info/view.php?id=256283'); - $this->assertEquals('てすと', $metadata->title); - $this->assertEquals('投稿者: ニジエ運営' . PHP_EOL . 'H264動画てすと あとで消します' . PHP_EOL . PHP_EOL . '今の所、H264コーデックのみ、出力時に音声なしにしないと投稿できません' . PHP_EOL . '動画は勝手にループします', $metadata->description); + $this->assertSame('てすと', $metadata->title); + $this->assertSame('投稿者: ニジエ運営' . PHP_EOL . 'H264動画てすと あとで消します' . PHP_EOL . PHP_EOL . '今の所、H264コーデックのみ、出力時に音声なしにしないと投稿できません' . PHP_EOL . '動画は勝手にループします', $metadata->description); $this->assertStringStartsWith('https://nijie.info/pic/logo/nijie_logo_og.png', $metadata->image); $this->assertSame([], $metadata->tags); if ($this->shouldUseMock()) { From 150a8152a4be0d5cdb45cbbcd3f1490578865d96 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 28 Aug 2019 23:48:53 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8C=87=E6=91=98=E7=AE=87=E6=89=80?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/NijieResolver.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/MetadataResolver/NijieResolver.php b/app/MetadataResolver/NijieResolver.php index f511092..33408ab 100644 --- a/app/MetadataResolver/NijieResolver.php +++ b/app/MetadataResolver/NijieResolver.php @@ -33,8 +33,8 @@ class NijieResolver implements Resolver $res = $this->client->get($url); if ($res->getStatusCode() === 200) { - $metadata = $this->ogpResolver->parse((string) $res->getBody()); $html = (string) $res->getBody(); + $metadata = $this->ogpResolver->parse($html); $crawler = new Crawler($html); // DomCrawler内でjson内の日本語がHTMLエンティティに変換されるのでhtml_entity_decode @@ -43,8 +43,6 @@ class NijieResolver implements Resolver // 改行がそのまま入っていることがあるのでデコード前にエスケープが必要 $data = json_decode(preg_replace('/\r?\n/', '\n', $json), true); - $tags = $crawler->filter('#view-tag span.tag_name')->extract('_text'); - $metadata->title = $data['name']; $metadata->description = '投稿者: ' . $data['author']['name'] . PHP_EOL . $data['description']; if ( @@ -55,7 +53,7 @@ class NijieResolver implements Resolver // サムネイルからメイン画像に $metadata->image = str_replace('__rs_l160x160/', '', $data['thumbnailUrl']); } - $metadata->tags = $tags; + $metadata->tags = $crawler->filter('#view-tag span.tag_name')->extract('_text'); return $metadata; } else {