From 8594caade19621c8a5361ce5bfc2d938551095b0 Mon Sep 17 00:00:00 2001 From: MitarashiDango Date: Fri, 9 Aug 2019 00:57:14 +0900 Subject: [PATCH 01/13] =?UTF-8?q?=E3=82=BF=E3=82=B0=E5=85=A5=E5=8A=9B?= =?UTF-8?q?=E7=A2=BA=E5=AE=9A=E6=99=82=E3=81=AE=E3=83=95=E3=82=A9=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=90=E3=83=83=E3=82=AF=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/components/TagInput.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/assets/js/components/TagInput.vue b/resources/assets/js/components/TagInput.vue index 194e827..be3458b 100644 --- a/resources/assets/js/components/TagInput.vue +++ b/resources/assets/js/components/TagInput.vue @@ -46,6 +46,14 @@ } event.preventDefault(); break; + case 'Unidentified': + // 実際にテキストボックスに入力されている文字を見に行く (フォールバック処理) + if (event.srcElement && (event.srcElement as HTMLInputElement).value.slice(-1) == ' ') { + this.tags.push(this.buffer); + this.buffer = ""; + event.preventDefault(); + } + break; } } else if (event.key === "Enter") { // 誤爆防止 From 7baf51fc0912f771a6b8a7681225265af26cdd21 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 21 Aug 2019 03:40:47 +0900 Subject: [PATCH 02/13] =?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 03/13] =?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 5069f20b50625d0e2b835b91ff0e285bf7fe07b0 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 21 Aug 2019 05:08:17 +0900 Subject: [PATCH 04/13] =?UTF-8?q?=E3=82=BF=E3=82=B0=E5=AF=BE=E5=BF=9C,=20i?= =?UTF-8?q?mages=E5=AF=BE=E5=BF=9C,=20=E3=83=86=E3=82=B9=E3=83=88=E6=9B=B4?= =?UTF-8?q?=E6=96=B0,=20=E3=81=9D=E3=81=AE=E4=BB=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/IwaraResolver.php | 60 +- app/MetadataResolver/MetadataResolver.php | 2 +- .../MetadataResolver/IwaraResolverTest.php | 71 + tests/fixture/Iwara/images.html | 644 +++++++ tests/fixture/Iwara/video.html | 1713 +++++++++++++++++ tests/fixture/Iwara/youtube.html | 1013 ++++++++++ 6 files changed, 3468 insertions(+), 35 deletions(-) create mode 100644 tests/Unit/MetadataResolver/IwaraResolverTest.php create mode 100644 tests/fixture/Iwara/images.html create mode 100644 tests/fixture/Iwara/video.html create mode 100644 tests/fixture/Iwara/youtube.html diff --git a/app/MetadataResolver/IwaraResolver.php b/app/MetadataResolver/IwaraResolver.php index 361501d..f19efc9 100644 --- a/app/MetadataResolver/IwaraResolver.php +++ b/app/MetadataResolver/IwaraResolver.php @@ -3,6 +3,7 @@ namespace App\MetadataResolver; use GuzzleHttp\Client; +use Symfony\Component\DomCrawler\Crawler; class IwaraResolver implements Resolver { @@ -19,46 +20,37 @@ class IwaraResolver implements Resolver public function resolve(string $url): Metadata { $res = $this->client->get($url); - if ($res->getStatusCode() === 200) { - $dom = new \DOMDocument(); - @$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8')); - $xpath = new \DOMXPath($dom); - $metadata = new Metadata(); + $html = (string) $res->getBody(); + $crawler = new Crawler($html); - // find title - foreach ($xpath->query('//title') as $node) { - $content = $node->textContent; - if (!empty($content)) { - $metadata->title = $content; - break; + $descriptionElement = $crawler->filter('#video-player + div, .field-name-field-video-url + div, .field-name-field-images + div'); + $title = $descriptionElement->filter('h1.title')->text(); + $author = $descriptionElement->filter('.username')->text(); + $description = $descriptionElement->children('div')->eq(1)->text(); + $tags = $descriptionElement->filter('a[href^="/video-categories"], a[href^="/images"]')->extract('_text'); + + $metadata->title = $title; + $metadata->description = '投稿者: ' . $author . PHP_EOL . $description; + $metadata->tags = $tags; + + // iwara video + if ($crawler->filter('#video-player')->count()) { + $metadata->image = 'https:' . $crawler->filter('#video-player')->attr('poster'); + } + + // youtube + if ($crawler->filter('iframe[src^="//www.youtube.com"]')->count()) { + if (preg_match('~youtube\.com/embed/(\S+)\?~', $crawler->filter('iframe[src^="//www.youtube.com"]')->attr('src'), $matches) === 1) { + $youtubeId = $matches[1]; + $metadata->image = 'https://img.youtube.com/vi/' . $youtubeId . '/maxresdefault.jpg'; } } - // find thumbnail - foreach ($xpath->query('//*[@id="video-player"]') as $node) { - $poster = $node->getAttribute('poster'); - if (!empty($poster)) { - if (strpos($poster, '//') === 0) { - $poster = 'https:' . $poster; - } - $metadata->image = $poster; - break; - } - } - if (empty($metadata->image)) { - // YouTube embedded? - foreach ($xpath->query('//div[@class="embedded-video"]//iframe') as $node) { - $src = $node->getAttribute('src'); - if (preg_match('~youtube\.com/embed/(\S+)\?~', $src, $matches) !== -1) { - $youtubeId = $matches[1]; - $iwaraThumbUrl = 'https://i.iwara.tv/sites/default/files/styles/thumbnail/public/video_embed_field_thumbnails/youtube/' . $youtubeId . '.jpg'; - - $metadata->image = $iwaraThumbUrl; - break; - } - } + // images + if ($crawler->filter('.field-name-field-images')->count()) { + $metadata->image = 'https:' . $crawler->filter('.field-name-field-images a')->first()->attr('href'); } return $metadata; diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index e53f7d6..363b6f3 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -14,7 +14,7 @@ class MetadataResolver implements Resolver '~komiflo\.com(/#!)?/comics/(\\d+)~' => KomifloResolver::class, '~www\.melonbooks\.co\.jp/detail/detail\.php~' => MelonbooksResolver::class, '~ec\.toranoana\.(jp|shop)/(tora|joshi)(_[rd]+)?/(ec|digi)/item/~' => ToranoanaResolver::class, - '~iwara\.tv/videos/.*~' => IwaraResolver::class, + '~iwara\.tv/(videos|images)/.*~' => IwaraResolver::class, '~www\.dlsite\.com/.*/(work|announce)/=/product_id/..\d+(\.html)?~' => DLsiteResolver::class, '~dlsite\.jp/...tw/..\d+~' => DLsiteResolver::class, '~www\.pixiv\.net/member_illust\.php\?illust_id=\d+~' => PixivResolver::class, diff --git a/tests/Unit/MetadataResolver/IwaraResolverTest.php b/tests/Unit/MetadataResolver/IwaraResolverTest.php new file mode 100644 index 0000000..d8865b2 --- /dev/null +++ b/tests/Unit/MetadataResolver/IwaraResolverTest.php @@ -0,0 +1,71 @@ +shouldUseMock()) { + sleep(1); + } + } + + public function testVideo() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/Iwara/video.html'); + + $this->createResolver(IwaraResolver::class, $responseText); + + $url = 'https://ecchi.iwara.tv/videos/wqlwatgmvhqg40kg'; + $metadata = $this->resolver->resolve($url); + $this->assertEquals('Cakeface【鈴谷、プリンツ】', $metadata->title); + $this->assertEquals('投稿者: kuro@vov' . PHP_EOL . 'Thank you for watching!いつもありがとうございます' . PHP_EOL . 'こっそり微修正…' . PHP_EOL . 'Model:鈴谷&プリンツ つみだんご様 罪袋:BCD様' . PHP_EOL . '(いずれも改変)クレジット漏れゴメンナサイ。。。' . PHP_EOL, $metadata->description); + $this->assertEquals(['Uncategorized', 'KanColle'], $metadata->tags); + $this->assertEquals('https://i.iwara.tv/sites/default/files/videos/thumbnails/238591/thumbnail-238591_0004.jpg', $metadata->image); + if ($this->shouldUseMock()) { + $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); + } + } + + public function testYouTube() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/Iwara/youtube.html'); + + $this->createResolver(IwaraResolver::class, $responseText); + + $url = 'https://iwara.tv/videos/z4dn6fag4iko08o0'; + $metadata = $this->resolver->resolve($url); + $this->assertEquals('むちむち天龍ちゃんで君色に染まる', $metadata->title); + $this->assertEquals('投稿者: kochira' . PHP_EOL . 'Ray-cast test. Still trying to figure out how Ray-cast works so I\'m sorry if anything looks off.' . PHP_EOL . 'Unauthorized reproduction prohibited (無断転載は禁止です/未經授權禁止複製)' . PHP_EOL, $metadata->description); + $this->assertEquals(['Uncategorized', 'KanColle'], $metadata->tags); + $this->assertEquals('https://img.youtube.com/vi/pvA5Db082yo/maxresdefault.jpg', $metadata->image); + if ($this->shouldUseMock()) { + $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); + } + } + + public function testImages() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/Iwara/images.html'); + + $this->createResolver(IwaraResolver::class, $responseText); + + $url = 'https://iwara.tv/images/%E9%8F%A1%E9%9F%B3%E3%82%8A%E3%82%9318%E6%AD%B3'; + $metadata = $this->resolver->resolve($url); + $this->assertEquals('鏡音りん18歳', $metadata->title); + $this->assertEquals('投稿者: Tonjiru Lion' . PHP_EOL . '今回はあんまエロくないです。' . PHP_EOL, $metadata->description); + $this->assertEquals(['Vocaloid'], $metadata->tags); + $this->assertEquals('https://i.iwara.tv/sites/default/files/photos/jing_yin_rin18sui_a.png', $metadata->image); + if ($this->shouldUseMock()) { + $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); + } + } +} diff --git a/tests/fixture/Iwara/images.html b/tests/fixture/Iwara/images.html new file mode 100644 index 0000000..eb48004 --- /dev/null +++ b/tests/fixture/Iwara/images.html @@ -0,0 +1,644 @@ + + + + 鏡音りん18歳 | Iwara + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ +
+ + +
+
+ + +
+
+
+
+ + + + +
+
+ + +
+
+
+
+
+ + +

今回はあんまエロくないです。

+
12,424
+
+ +
+ +
+ +
+ +
+
+

+ コメント数 6

+ + +
+ + +
+ + +
+

良いカスタムモデルですね
+ぶっちゃけ裸よりエロいです(*´ω`)

+
+ +
+
+ +
+ + +
+ + +
+

可愛いと思います!

+
+ +
+
+ +
+ + +
+ + +
+

これくらいの微エロも捗りますね

+
+ +
+
+ +
+ + +
+ + +
+

これはけしからん18歳

+
+ +
+
+ +
+ + +
+ + +
+

That is Nice!

+
+ +
+
+ +
+ + +
+ + +
+

Lovely! I wanna make her videos!! plz

+
+ +
+
+ +
+
+ + +
+
+
+ +
+
+
+ + + + + + + diff --git a/tests/fixture/Iwara/video.html b/tests/fixture/Iwara/video.html new file mode 100644 index 0000000..03fff45 --- /dev/null +++ b/tests/fixture/Iwara/video.html @@ -0,0 +1,1713 @@ + + + + Cakeface【鈴谷、プリンツ】 | Iwara + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ +
+ + +
+
+
+ + +
+
+
+
+ + + + +
+
+ + +
+
+
+ + + + +
+ + + +

Thank you for watching!いつもありがとうございます
+こっそり微修正…
+Model:鈴谷&プリンツ つみだんご様 罪袋:BCD様
+(いずれも改変)クレジット漏れゴメンナサイ。。。

+
+ 5966 742,707
+
+ +
+ + + ダウンロード + + + +
+ +
+ +
+
+
+ +
+
+

+ コメント数 213

+ + +
+ + +
+ + +
+

Thank you it's too great!!

+
+ +
+
+ +
+ + +
+ + +
+

NICE*N

+
+ +
+
+ +
+ + +
+ + +
+

good!

+
+ +
+
+ +
+ + +
+ + +
+

哇 又有 新的MMD了 先留言 感谢 UP

+
+ +
+
+ +
+
+ + +
+ + +
+

问下怎么下载啊……点了下载按钮弹出来一个空白页面

+
+ +
+
+ +
+
+ + +
+ + +
+

我是挂的SS 用IDM下载的。。 首先你的网络要支持 然后要用下载软件。

+
+ +
+
+
+
+ + +
+ + +
+

投稿お疲れ様です。素晴らしいです。kuroさんは間違いなく紳士MMD界の歴史に名を刻む人だ❗色んな事が凄すぎる。

+
+ +
+
+ +
+ + +
+ + +
+

Holy shit, your videos are seriously so damn good.

+
+ +
+
+ +
+ + +
+ + +
+

ちょっとこのクオリティはやばくないですかねぇ・・・・・・
+あっ、そこの人ティッシュ取って

+
+ +
+
+ +
+
+ + +
+ + +
+

あ、どうぞ (´・ω・`)つ

+
+ +
+
+
+
+ + +
+ + +
+

Thank you
+Nice video

+
+ +
+
+ +
+ + +
+ + +
+

投稿お疲れ!

+
+ +
+
+ +
+ + +
+ + +
+

お前がナンバーワンだ

+
+ +
+
+ +
+ + +
+ + +
+

ついから急いで来ました。
+す、素晴しい!!
+ぶらーーーぼぉーーー!
+ぶーーーらぁーーーぼぉーーー!

+
+ +
+
+ +
+ + +
+ + +
+

This is High End entertainment

+
+ +
+
+ +
+ + +
+ + +
+

素晴らしい動画をありがとうございます!

+
+ +
+
+ +
+ + +
+ + +
+

That is beautiful.

+
+ +
+
+ +
+ + +
+ + +
+

マジやばくね

+
+ +
+
+ +
+ + +
+ + +
+

Best Kancolle MMDer!

+
+ +
+
+ +
+ + +
+ + +
+

毎度素晴らしいクオリティとシコリティで実にありがたい…。

+
+ +
+
+ +
+ + +
+ + +
+

Amazing!
+Completely beyond comparison to any other work!

+
+ +
+
+ +
+ + +
+ + +
+

投稿お疲れ!

+
+ +
+
+ +
+ + +
+ + +
+

this is the best cakeface mmd i've ever seen

+
+ +
+
+ +
+ + +
+ + +
+

投稿お疲れ様です、エロイ・・・・スゴク・・・エロいです

+
+ +
+
+ +
+ + +
+ + +
+

石更火暴

+
+ +
+
+ +
+ + +
+ + +
+

This.. This is amazing!
+It's a masterpiece!!

+
+ +
+
+ +
+ + +
+ + +
+

新作ありがとうございます。

+
+ +
+
+ +
+ + +
+ + +
+

プリンツ ლ(゚д゚ლ)

+
+ +
+
+ +
+ + +
+ + +
+

Damn you are good! This is great!!

+
+ +
+
+ +
+ + +
+ + +
+

love the lighting

+
+ +
+
+ +
+ + +
+ + +
+

It's legendary! XD

+
+ +
+
+ +
+ + +
+ + +
+

great work

+
+ +
+
+ +
+ + +
+ + +
+

kuro@vov さんの動画はどれも素晴らしいのですが、今回のコレはずば抜けてすごい出来ですね…

+
+ +
+
+ +
+ + +
+ + +
+

投稿お疲れ様です!
+次は武蔵のが見たいな(チラッ

+
+ +
+
+ +
+ + +
+ + +
+

The best in which I've watched in 2 or 3 months.

+
+ +
+
+ +
+ + +
+ + +
+

素晴らしすぎます 

+
+ +
+
+ +
+ + +
+ + +
+

新上傳的MMD好棒!!!!!!!!!

+
+ +
+
+ +
+ + +
+ + +
+

相変わらず、素晴らしいの一言です、今夜は色々忙しくなりそうです

+
+ +
+
+ +
+ + +
+ + +
+

Amazing artwork!Such a masterpiece !

+
+ +
+
+ +
+ + +
+ + +
+

この二人に搾り取られたいw

+
+ +
+
+ +
+ + +
+ + +
+

MMDにおけるCakefaceをさらにエロく進化させる方が現れるとは…。
+ダンケ百唱モノです!

+
+ +
+
+ +
+ + +
+ + +
+

鈴谷んとプリンツに挟まれるなんて・・・なんて・・・何て贅沢なんだっ( ;∀;)

+
+ +
+
+ +
+ + +
+ + +
+

こちらこそいつも良い作品ありがとうございます!!

+
+ +
+
+ +
+ + +
+ + +
+

Good work,love it <3

+
+ +
+
+ +
+ + +
+ + +
+

これは…これは…素晴らしいだとしか言葉が出ないクォリティーですね。本当に素晴らしい作品です!

+
+ +
+
+ +
+ + +
+ + +
+

投稿お疲れ様です。すごいとしか言いようが無いですが、
+圧巻です。この技術と労力をかけてくださるkuroさんに
+感謝。

+
+ +
+
+ +
+ + +
+ + +
+

あっいつもの神様ですね分かります。

+
+ +
+
+ +
+ + +
+ + +
+

マジで格が違うすげぇ・・・

+
+ +
+
+ +
+ + +
+ + +
+

投稿お疲れ様です ありがとうございます

+
+ +
+
+ +
+ + +
+ + +
+

作品真的很用心,也非常好用,期待您更多的佳作。

+
+ +
+
+

ページ

+
+
+
+
+ +
+ +
+
+
+ + + + + + + + diff --git a/tests/fixture/Iwara/youtube.html b/tests/fixture/Iwara/youtube.html new file mode 100644 index 0000000..e646ffb --- /dev/null +++ b/tests/fixture/Iwara/youtube.html @@ -0,0 +1,1013 @@ + + + + むちむち天龍ちゃんで君色に染まる | Iwara + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+ +
+ + +
+
+
+ + +
+
+
+
+ + + + +
+
+ + +
+
+
+
+
+
+
+
+
+
+ + + +

Ray-cast test. Still trying to figure out how Ray-cast works so I'm sorry if anything looks off.

+

Unauthorized reproduction prohibited (無断転載は禁止です/未經授權禁止複製)

+
+ 240 37,644
+
+ +
+ + + + +
+ +
+ +
+
+
+ +
+
+

+ コメント数 17

+ + +
+ + +
+ + +
+

Wow, the Ray-cast looks great! I hope you do all of your videos like that. I have to add though I would prefer a Tenryuu with a skinnier waist and a smaller butt though. But beggars can't be choosers. T_T

+

Edit: And with her tits out!

+
+ +
+
+ +
+
+ + +
+ + +
+

I agree with your edit, comrade. Haha, I would love a nude version in the future :P

+
+ +
+
+ +
+ + +
+ + +
+

666666666

+
+ +
+
+
+
+ + +
+ + +
+

Looking real good :D And I don't know why, but I really like this thicc design of her. So... Fertile and healthy. GJ! She's super sexy (Reminds me of Kunaboto doujins, so lewd)

+
+ +
+
+ +
+ + +
+ + +
+

むちむち天龍!

+
+ +
+
+ +
+ + +
+ + +
+

Welcome back.

+
+ +
+
+ +
+ + +
+ + +
+

最高ですね。
+このモデルでもう1度NEW THANGが観たいです!

+
+ +
+
+ +
+ + +
+ + +
+

復活おめでとう

+
+ +
+
+ +
+ + +
+ + +
+

なんというお肉…埋もれたい('Д')

+
+ +
+
+ +
+ + +
+ + +
+

良い表情してるね
+すごく楽しそう

+
+ +
+
+ +
+ + +
+ + +
+

最高です!復活おめでとう

+
+ +
+
+ +
+ + +
+ + +
+

Yay welcome back Kochira nice video I love it lol.

+
+ +
+
+ +
+ + +
+ + +
+

Missed you <3

+
+ +
+
+ +
+ + +
+ + +
+

天龍ちゃん最高!

+
+ +
+
+ +
+ + +
+ + +
+

oh god!!! Uncensored version please!!! <3 this is so good GJ!!!

+
+ +
+
+ +
+ + +
+ + +
+

Very sexy♥♥

+
+ +
+
+ +
+ + +
+ + +
+

I hope to see a Uncensored version.

+
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+ + + + + + + From 9926cc335742f435b4f60dbdf093aeb9b26ab6c4 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Thu, 22 Aug 2019 05:17:23 +0900 Subject: [PATCH 05/13] =?UTF-8?q?=E5=BD=B9=E3=81=AB=E7=AB=8B=E3=81=9F?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=82=BF=E3=82=B0=E3=82=92=E5=90=AB=E3=82=81?= =?UTF-8?q?=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/IwaraResolver.php | 2 ++ tests/Unit/MetadataResolver/IwaraResolverTest.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/MetadataResolver/IwaraResolver.php b/app/MetadataResolver/IwaraResolver.php index f19efc9..29938d6 100644 --- a/app/MetadataResolver/IwaraResolver.php +++ b/app/MetadataResolver/IwaraResolver.php @@ -30,6 +30,8 @@ class IwaraResolver implements Resolver $author = $descriptionElement->filter('.username')->text(); $description = $descriptionElement->children('div')->eq(1)->text(); $tags = $descriptionElement->filter('a[href^="/video-categories"], a[href^="/images"]')->extract('_text'); + // 役に立たないタグを削除する + $tags = array_values(array_diff($tags, ['Uncategorized', 'Other'])); $metadata->title = $title; $metadata->description = '投稿者: ' . $author . PHP_EOL . $description; diff --git a/tests/Unit/MetadataResolver/IwaraResolverTest.php b/tests/Unit/MetadataResolver/IwaraResolverTest.php index d8865b2..ee19bb9 100644 --- a/tests/Unit/MetadataResolver/IwaraResolverTest.php +++ b/tests/Unit/MetadataResolver/IwaraResolverTest.php @@ -28,7 +28,7 @@ class IwaraResolverTest extends TestCase $metadata = $this->resolver->resolve($url); $this->assertEquals('Cakeface【鈴谷、プリンツ】', $metadata->title); $this->assertEquals('投稿者: kuro@vov' . PHP_EOL . 'Thank you for watching!いつもありがとうございます' . PHP_EOL . 'こっそり微修正…' . PHP_EOL . 'Model:鈴谷&プリンツ つみだんご様 罪袋:BCD様' . PHP_EOL . '(いずれも改変)クレジット漏れゴメンナサイ。。。' . PHP_EOL, $metadata->description); - $this->assertEquals(['Uncategorized', 'KanColle'], $metadata->tags); + $this->assertEquals(['KanColle'], $metadata->tags); $this->assertEquals('https://i.iwara.tv/sites/default/files/videos/thumbnails/238591/thumbnail-238591_0004.jpg', $metadata->image); if ($this->shouldUseMock()) { $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); @@ -45,7 +45,7 @@ class IwaraResolverTest extends TestCase $metadata = $this->resolver->resolve($url); $this->assertEquals('むちむち天龍ちゃんで君色に染まる', $metadata->title); $this->assertEquals('投稿者: kochira' . PHP_EOL . 'Ray-cast test. Still trying to figure out how Ray-cast works so I\'m sorry if anything looks off.' . PHP_EOL . 'Unauthorized reproduction prohibited (無断転載は禁止です/未經授權禁止複製)' . PHP_EOL, $metadata->description); - $this->assertEquals(['Uncategorized', 'KanColle'], $metadata->tags); + $this->assertEquals(['KanColle'], $metadata->tags); $this->assertEquals('https://img.youtube.com/vi/pvA5Db082yo/maxresdefault.jpg', $metadata->image); if ($this->shouldUseMock()) { $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); From 0a994884a03af92ec5d31379b8def98e54d114f0 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Thu, 22 Aug 2019 05:23:28 +0900 Subject: [PATCH 06/13] =?UTF-8?q?=E4=BD=9C=E8=80=85=E5=90=8D=E3=82=92?= =?UTF-8?q?=E3=82=BF=E3=82=B0=E3=81=AB=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/IwaraResolver.php | 1 + tests/Unit/MetadataResolver/IwaraResolverTest.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/MetadataResolver/IwaraResolver.php b/app/MetadataResolver/IwaraResolver.php index 29938d6..736b3ca 100644 --- a/app/MetadataResolver/IwaraResolver.php +++ b/app/MetadataResolver/IwaraResolver.php @@ -32,6 +32,7 @@ class IwaraResolver implements Resolver $tags = $descriptionElement->filter('a[href^="/video-categories"], a[href^="/images"]')->extract('_text'); // 役に立たないタグを削除する $tags = array_values(array_diff($tags, ['Uncategorized', 'Other'])); + array_push($tags, $author); $metadata->title = $title; $metadata->description = '投稿者: ' . $author . PHP_EOL . $description; diff --git a/tests/Unit/MetadataResolver/IwaraResolverTest.php b/tests/Unit/MetadataResolver/IwaraResolverTest.php index ee19bb9..453fdd7 100644 --- a/tests/Unit/MetadataResolver/IwaraResolverTest.php +++ b/tests/Unit/MetadataResolver/IwaraResolverTest.php @@ -28,7 +28,7 @@ class IwaraResolverTest extends TestCase $metadata = $this->resolver->resolve($url); $this->assertEquals('Cakeface【鈴谷、プリンツ】', $metadata->title); $this->assertEquals('投稿者: kuro@vov' . PHP_EOL . 'Thank you for watching!いつもありがとうございます' . PHP_EOL . 'こっそり微修正…' . PHP_EOL . 'Model:鈴谷&プリンツ つみだんご様 罪袋:BCD様' . PHP_EOL . '(いずれも改変)クレジット漏れゴメンナサイ。。。' . PHP_EOL, $metadata->description); - $this->assertEquals(['KanColle'], $metadata->tags); + $this->assertEquals(['KanColle', 'kuro@vov'], $metadata->tags); $this->assertEquals('https://i.iwara.tv/sites/default/files/videos/thumbnails/238591/thumbnail-238591_0004.jpg', $metadata->image); if ($this->shouldUseMock()) { $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); @@ -45,7 +45,7 @@ class IwaraResolverTest extends TestCase $metadata = $this->resolver->resolve($url); $this->assertEquals('むちむち天龍ちゃんで君色に染まる', $metadata->title); $this->assertEquals('投稿者: kochira' . PHP_EOL . 'Ray-cast test. Still trying to figure out how Ray-cast works so I\'m sorry if anything looks off.' . PHP_EOL . 'Unauthorized reproduction prohibited (無断転載は禁止です/未經授權禁止複製)' . PHP_EOL, $metadata->description); - $this->assertEquals(['KanColle'], $metadata->tags); + $this->assertEquals(['KanColle', 'kochira'], $metadata->tags); $this->assertEquals('https://img.youtube.com/vi/pvA5Db082yo/maxresdefault.jpg', $metadata->image); if ($this->shouldUseMock()) { $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); @@ -62,7 +62,7 @@ class IwaraResolverTest extends TestCase $metadata = $this->resolver->resolve($url); $this->assertEquals('鏡音りん18歳', $metadata->title); $this->assertEquals('投稿者: Tonjiru Lion' . PHP_EOL . '今回はあんまエロくないです。' . PHP_EOL, $metadata->description); - $this->assertEquals(['Vocaloid'], $metadata->tags); + $this->assertEquals(['Vocaloid', 'Tonjiru Lion'], $metadata->tags); $this->assertEquals('https://i.iwara.tv/sites/default/files/photos/jing_yin_rin18sui_a.png', $metadata->image); if ($this->shouldUseMock()) { $this->assertSame($url, (string) $this->handler->getLastRequest()->getUri()); From b7eafd881f77864d450216f636dec2431eb24a97 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Thu, 22 Aug 2019 07:28:28 +0900 Subject: [PATCH 07/13] =?UTF-8?q?description=E3=81=8C=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E3=81=97=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/IwaraResolver.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/MetadataResolver/IwaraResolver.php b/app/MetadataResolver/IwaraResolver.php index 736b3ca..a518d24 100644 --- a/app/MetadataResolver/IwaraResolver.php +++ b/app/MetadataResolver/IwaraResolver.php @@ -28,7 +28,10 @@ class IwaraResolver implements Resolver $descriptionElement = $crawler->filter('#video-player + div, .field-name-field-video-url + div, .field-name-field-images + div'); $title = $descriptionElement->filter('h1.title')->text(); $author = $descriptionElement->filter('.username')->text(); - $description = $descriptionElement->children('div')->eq(1)->text(); + $description = ''; + if ($descriptionElement->filter('.field-type-text-with-summary')->count()) { + $description = $descriptionElement->filter('.field-type-text-with-summary')->text(); + } $tags = $descriptionElement->filter('a[href^="/video-categories"], a[href^="/images"]')->extract('_text'); // 役に立たないタグを削除する $tags = array_values(array_diff($tags, ['Uncategorized', 'Other'])); From 4f23a9404b68a8cae07bb913a46fd34a787b963f Mon Sep 17 00:00:00 2001 From: eai04191 Date: Thu, 22 Aug 2019 07:47:42 +0900 Subject: [PATCH 08/13] =?UTF-8?q?=E5=90=8D=E5=89=8D=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/IwaraResolver.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/MetadataResolver/IwaraResolver.php b/app/MetadataResolver/IwaraResolver.php index a518d24..b876315 100644 --- a/app/MetadataResolver/IwaraResolver.php +++ b/app/MetadataResolver/IwaraResolver.php @@ -25,14 +25,14 @@ class IwaraResolver implements Resolver $html = (string) $res->getBody(); $crawler = new Crawler($html); - $descriptionElement = $crawler->filter('#video-player + div, .field-name-field-video-url + div, .field-name-field-images + div'); - $title = $descriptionElement->filter('h1.title')->text(); - $author = $descriptionElement->filter('.username')->text(); + $infoElements = $crawler->filter('#video-player + div, .field-name-field-video-url + div, .field-name-field-images + div'); + $title = $infoElements->filter('h1.title')->text(); + $author = $infoElements->filter('.username')->text(); $description = ''; - if ($descriptionElement->filter('.field-type-text-with-summary')->count()) { - $description = $descriptionElement->filter('.field-type-text-with-summary')->text(); + if ($infoElements->filter('.field-type-text-with-summary')->count()) { + $description = $infoElements->filter('.field-type-text-with-summary')->text(); } - $tags = $descriptionElement->filter('a[href^="/video-categories"], a[href^="/images"]')->extract('_text'); + $tags = $infoElements->filter('a[href^="/video-categories"], a[href^="/images"]')->extract('_text'); // 役に立たないタグを削除する $tags = array_values(array_diff($tags, ['Uncategorized', 'Other'])); array_push($tags, $author); From 5ac1bae73fd3d6b0294ab17aaacbf08100664024 Mon Sep 17 00:00:00 2001 From: shibafu Date: Wed, 28 Aug 2019 23:25:48 +0900 Subject: [PATCH 09/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d812ce..f773c6b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ a.k.a. shikorism.net ## 実行環境 -- PHP 7.1 +- PHP 7.3 - PostgreSQL 9.6 ## 開発環境の構築 From 150a8152a4be0d5cdb45cbbcd3f1490578865d96 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 28 Aug 2019 23:48:53 +0900 Subject: [PATCH 10/13] =?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 { From 8ef9a1f8f4301622d447ddee70aece8fff92a2a0 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 28 Aug 2019 23:57:23 +0900 Subject: [PATCH 11/13] Update fixture --- tests/fixture/Iwara/images.html | 42 +++---- tests/fixture/Iwara/video.html | 196 +++++++++++++++---------------- tests/fixture/Iwara/youtube.html | 84 ++++++------- 3 files changed, 160 insertions(+), 162 deletions(-) diff --git a/tests/fixture/Iwara/images.html b/tests/fixture/Iwara/images.html index eb48004..4c81d00 100644 --- a/tests/fixture/Iwara/images.html +++ b/tests/fixture/Iwara/images.html @@ -86,7 +86,7 @@ window.jQuery || document.write(" @@ -128,7 +128,7 @@ jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"","ajaxPageState": @@ -183,7 +183,7 @@ jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"","ajaxPageState":

Cakeface【鈴谷、プリンツ】

@@ -194,7 +194,7 @@ jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"","ajaxPageState": こっそり微修正…
Model:鈴谷&プリンツ つみだんご様 罪袋:BCD様
(いずれも改変)クレジット漏れゴメンナサイ。。。

-
- 5966 742,707
+ 6028 749,365
@@ -400,9 +400,7 @@ Model:鈴谷&プリンツ つみだんご様 罪袋:BCD様
+
-
ユーザー 超大电饭锅 の写真
- +
ユーザー sjenlin の写真
+
1日
@@ -1234,7 +1232,7 @@ It's a masterpiece!!

More from user

-
+
@@ -1242,14 +1240,48 @@ It's a masterpiece!!

+
+
+
+ + + + +
+
KotonohaYugi【Suzuya】
+
+ +
+
+
+
+
+
+ + + + +
+
BBペレ【mv】
+
+ +
+
+
+
+
+ 3234
+ 161.9k
摩耶とH
@@ -1258,32 +1290,32 @@ It's a masterpiece!!

-
+
+ 2173
+ 59.1k
-
KotonohaYugi【Suzuya】
+
IN your room【NO DANCE】マシュとH
-
+
+ 3003
+ 249.3k
HappyHalloween
@@ -1296,10 +1328,10 @@ It's a masterpiece!!

+ 2359
+ 232.5k
KotonohaYugi【Kongo】
@@ -1307,40 +1339,6 @@ It's a masterpiece!!

-
-
-
-
-
-
- - - - -
-
立ってる...【折岸みつ】
-
- -
-
-
-
-
-
- - - - -
-
BBペレ【mv】
-
- -
-
@@ -1357,7 +1355,7 @@ It's a masterpiece!!

More like this

-
Cakeface (※Futanari)
@@ -1403,10 +1401,10 @@ It's a masterpiece!!

+ 114
+ 7.4k
【MMD】 CAKEFACE
@@ -1437,10 +1435,10 @@ It's a masterpiece!!

+ 1362
+ 114.7k
プリンツ・ろーちゃんの黒丸いたずら一心不乱♡♡♡♡
@@ -1453,7 +1451,7 @@ It's a masterpiece!!

+ 240
@@ -1474,7 +1472,7 @@ It's a masterpiece!!

448
+ 37.2k
プリンツ 拘束中出しsex
@@ -1487,7 +1485,7 @@ It's a masterpiece!!

+ 201
@@ -1508,7 +1506,7 @@ It's a masterpiece!!

717
+ 30k
CakeFace!!! [R-18]
@@ -1542,7 +1540,7 @@ It's a masterpiece!!

191 + 35.5k
cakeface
@@ -1555,10 +1553,10 @@ It's a masterpiece!!

+ 582
+ 43.8k
Cakeface
@@ -1573,10 +1571,10 @@ It's a masterpiece!!

+ 158
+ 11.1k
CAKEFACE
@@ -1589,10 +1587,10 @@ It's a masterpiece!!

+ 146
+ 12.9k
cakeface
@@ -1623,10 +1621,10 @@ It's a masterpiece!!

+ 206
+ 13.1k
cakeface
@@ -1682,11 +1680,11 @@ It's a masterpiece!!

新しいフォーラムトピック

diff --git a/tests/fixture/Iwara/youtube.html b/tests/fixture/Iwara/youtube.html index e646ffb..e5aea12 100644 --- a/tests/fixture/Iwara/youtube.html +++ b/tests/fixture/Iwara/youtube.html @@ -86,7 +86,7 @@ window.jQuery || document.write("