From 3b2e81818b534306d5e1431872184f1d618c57d7 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 15 Apr 2018 21:46:49 +0900 Subject: [PATCH] =?UTF-8?q?sp.nijie.info=E3=81=AE=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=E6=AD=A3=E3=81=97=E3=81=8F=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #7 --- app/MetadataResolver/NijieResolver.php | 4 + .../MetadataResolver/NijieResolverTest.php | 105 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tests/Unit/MetadataResolver/NijieResolverTest.php diff --git a/app/MetadataResolver/NijieResolver.php b/app/MetadataResolver/NijieResolver.php index f4fdba1..7d3d1d6 100644 --- a/app/MetadataResolver/NijieResolver.php +++ b/app/MetadataResolver/NijieResolver.php @@ -6,6 +6,10 @@ class NijieResolver implements Resolver { public function resolve(string $url): Metadata { + if (mb_strpos($url, '//sp.nijie.info') !== false) { + $url = preg_replace('~//sp\.nijie\.info~', '//nijie.info', $url); + } + $client = new \GuzzleHttp\Client(); $res = $client->get($url); if ($res->getStatusCode() === 200) { diff --git a/tests/Unit/MetadataResolver/NijieResolverTest.php b/tests/Unit/MetadataResolver/NijieResolverTest.php new file mode 100644 index 0000000..0344415 --- /dev/null +++ b/tests/Unit/MetadataResolver/NijieResolverTest.php @@ -0,0 +1,105 @@ +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); + } + + public function testMultiplePicture() + { + sleep(1); + $resolver = new NijieResolver(); + + $metadata = $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); + } + + public function testAnimationGif() + { + sleep(1); + $resolver = new NijieResolver(); + + $metadata = $resolver->resolve('https://nijie.info/view.php?id=258078'); + $this->assertEquals('騎乗位ルーミア | しょったれ', $metadata->title); + $this->assertEquals("以前pixivに投稿したgifアニメ。\r\n気の利いたタイトルが浮かばなかった。", $metadata->description); + $this->assertRegExp('/pic\d+\.nijie\.info/', $metadata->image); + $this->assertNotRegExp('~/diff/main/~', $metadata->image); + } + + public function testMp4Movie() + { + sleep(1); + $resolver = new NijieResolver(); + + $metadata = $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('/pic\d+\.nijie\.info/', $metadata->image); + $this->assertNotRegExp('~/diff/main/~', $metadata->image); + } + + public function testStandardPictureSp() + { + sleep(1); + $resolver = new NijieResolver(); + + $metadata = $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); + } + + public function testMultiplePictureSp() + { + sleep(1); + $resolver = new NijieResolver(); + + $metadata = $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); + } + + public function testAnimationGifSp() + { + sleep(1); + $resolver = new NijieResolver(); + + $metadata = $resolver->resolve('https://sp.nijie.info/view.php?id=258078'); + $this->assertEquals('騎乗位ルーミア | しょったれ', $metadata->title); + $this->assertEquals("以前pixivに投稿したgifアニメ。\r\n気の利いたタイトルが浮かばなかった。", $metadata->description); + $this->assertRegExp('/pic\d+\.nijie\.info/', $metadata->image); + $this->assertNotRegExp('~/diff/main/~', $metadata->image); + } + + public function testMp4MovieSp() + { + sleep(1); + $resolver = new NijieResolver(); + + $metadata = $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('/pic\d+\.nijie\.info/', $metadata->image); + $this->assertNotRegExp('~/diff/main/~', $metadata->image); + } +}