From 010a0a9c8fdd3592caf369dad593e3c272f3d802 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 10 Dec 2019 13:12:37 +0900 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E8=AA=9E=E7=89=88Pixiv=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/MetadataResolver.php | 2 +- app/MetadataResolver/PixivResolver.php | 4 ++-- .../Unit/MetadataResolver/PixivResolverTest.php | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index bb2ec08..f1dca76 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -20,7 +20,7 @@ class MetadataResolver implements Resolver '~www\.dlsite\.com/.*/dlaf/=/aid/.+/url/.+~' => DLsiteResolver::class, '~dlsite\.jp/...tw/..\d+~' => DLsiteResolver::class, '~www\.pixiv\.net/member_illust\.php\?illust_id=\d+~' => PixivResolver::class, - '~www\.pixiv\.net/artworks/\d+~' => PixivResolver::class, + '~www\.pixiv\.net/(en/)?artworks/\d+~' => PixivResolver::class, '~www\.pixiv\.net/user/\d+/series/\d+~' => PixivResolver::class, '~fantia\.jp/posts/\d+~' => FantiaResolver::class, '~dmm\.co\.jp/~' => FanzaResolver::class, diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index e6690ac..c7435a8 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -45,8 +45,8 @@ class PixivResolver implements Resolver } $page = 0; - if (preg_match('~www\.pixiv\.net/artworks/(\d+)~', $url, $matches)) { - $illustId = $matches[1]; + if (preg_match('~www\.pixiv\.net/(en/)?artworks/(?P\d+)~', $url, $matches)) { + $illustId = $matches['illustId']; } else { parse_str(parse_url($url, PHP_URL_QUERY), $params); $illustId = $params['illust_id']; diff --git a/tests/Unit/MetadataResolver/PixivResolverTest.php b/tests/Unit/MetadataResolver/PixivResolverTest.php index df5e83a..5565b7c 100644 --- a/tests/Unit/MetadataResolver/PixivResolverTest.php +++ b/tests/Unit/MetadataResolver/PixivResolverTest.php @@ -81,4 +81,20 @@ class PixivResolverTest extends TestCase $this->assertSame('https://www.pixiv.net/ajax/illust/68188073', (string) $this->handler->getLastRequest()->getUri()); } } + + public function testArtworkUrlEn() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/Pixiv/illust.json'); + + $this->createResolver(PixivResolver::class, $responseText); + + $metadata = $this->resolver->resolve('https://www.pixiv.net/en/artworks/68188073'); + $this->assertEquals('coffee break', $metadata->title); + $this->assertEquals('投稿者: 裕' . PHP_EOL, $metadata->description); + $this->assertEquals('https://i.pixiv.cat/img-master/img/2018/04/12/00/01/28/68188073_p0_master1200.jpg', $metadata->image); + $this->assertEquals(['オリジナル', 'カフェ', '眼鏡', 'イヤホン', 'ぱっつん', '艶ぼくろ', '眼鏡っ娘', 'オリジナル5000users入り'], $metadata->tags); + if ($this->shouldUseMock()) { + $this->assertSame('https://www.pixiv.net/ajax/illust/68188073', (string) $this->handler->getLastRequest()->getUri()); + } + } }