Merge pull request #290 from eai04191/feature/resolver-pixiv-new-url
PixivResolver 新URL形式に対応
This commit is contained in:
		@@ -20,6 +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/user/\d+/series/\d+~' => PixivResolver::class,
 | 
			
		||||
        '~fantia\.jp/posts/\d+~' => FantiaResolver::class,
 | 
			
		||||
        '~dmm\.co\.jp/~' => FanzaResolver::class,
 | 
			
		||||
 
 | 
			
		||||
@@ -44,14 +44,18 @@ class PixivResolver implements Resolver
 | 
			
		||||
            return $metadata;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $page = 0;
 | 
			
		||||
        if (preg_match('~www\.pixiv\.net/artworks/(\d+)~', $url, $matches)) {
 | 
			
		||||
            $illustId = $matches[1];
 | 
			
		||||
        } else {
 | 
			
		||||
            parse_str(parse_url($url, PHP_URL_QUERY), $params);
 | 
			
		||||
            $illustId = $params['illust_id'];
 | 
			
		||||
        $page = 0;
 | 
			
		||||
 | 
			
		||||
            // 漫画ページ(ページ数はmanga_bigならあるかも)
 | 
			
		||||
            if ($params['mode'] === 'manga_big' || $params['mode'] === 'manga') {
 | 
			
		||||
                $page = $params['page'] ?? 0;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $res = $this->client->get('https://www.pixiv.net/ajax/illust/' . $illustId);
 | 
			
		||||
        $json = json_decode($res->getBody()->getContents(), true);
 | 
			
		||||
 
 | 
			
		||||
@@ -65,4 +65,20 @@ class PixivResolverTest extends TestCase
 | 
			
		||||
            $this->assertSame('https://www.pixiv.net/ajax/illust/46713544', (string) $this->handler->getLastRequest()->getUri());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testArtworkUrl()
 | 
			
		||||
    {
 | 
			
		||||
        $responseText = file_get_contents(__DIR__ . '/../../fixture/Pixiv/illust.json');
 | 
			
		||||
 | 
			
		||||
        $this->createResolver(PixivResolver::class, $responseText);
 | 
			
		||||
 | 
			
		||||
        $metadata = $this->resolver->resolve('https://www.pixiv.net/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());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user