From c93ccb43c8bb80cadd7b856876cb8045bc219a43 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 20 Aug 2019 00:52:00 +0900 Subject: [PATCH 1/6] =?UTF-8?q?strip=5Ftags=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/DLsiteResolver.php | 5 +- .../MetadataResolver/DLsiteResolverTest.php | 16 + tests/fixture/DLsite/testHTMLdescription.html | 2325 +++++++++++++++++ 3 files changed, 2344 insertions(+), 2 deletions(-) create mode 100644 tests/fixture/DLsite/testHTMLdescription.html diff --git a/app/MetadataResolver/DLsiteResolver.php b/app/MetadataResolver/DLsiteResolver.php index 32e2769..5969d57 100644 --- a/app/MetadataResolver/DLsiteResolver.php +++ b/app/MetadataResolver/DLsiteResolver.php @@ -97,10 +97,11 @@ class DLsiteResolver implements Resolver // OGP説明文から定型文を消す if (strpos($url, 'dlsite.com/eng/') || strpos($url, 'dlsite.com/ecchi-eng/')) { - $metadata->description = trim(preg_replace('~DLsite.+ is a download shop for .+With a huge selection of products, we\'re sure you\'ll find whatever tickles your fancy\. DLsite is one of the greatest indie contents download shops in Japan\.$~', '', $metadata->description)); + $metadata->description = preg_replace('~DLsite.+ is a download shop for .+With a huge selection of products, we\'re sure you\'ll find whatever tickles your fancy\. DLsite is one of the greatest indie contents download shops in Japan\.$~', '', $metadata->description); } else { - $metadata->description = trim(preg_replace('~「DLsite.+」は.+のダウンロードショップ。お気に入りの作品をすぐダウンロードできてすぐ楽しめる!毎日更新しているのであなたが探している作品にきっと出会えます。国内最大級の二次元総合ダウンロードショップ「DLsite」!$~', '', $metadata->description)); + $metadata->description = preg_replace('~「DLsite.+」は.+のダウンロードショップ。お気に入りの作品をすぐダウンロードできてすぐ楽しめる!毎日更新しているのであなたが探している作品にきっと出会えます。国内最大級の二次元総合ダウンロードショップ「DLsite」!$~', '', $metadata->description); } + $metadata->description = trim(strip_tags($metadata->description)); // 整形 $metadata->description = $makersHead . ': ' . $makers . PHP_EOL . $metadata->description; diff --git a/tests/Unit/MetadataResolver/DLsiteResolverTest.php b/tests/Unit/MetadataResolver/DLsiteResolverTest.php index 780d73e..7cac98b 100644 --- a/tests/Unit/MetadataResolver/DLsiteResolverTest.php +++ b/tests/Unit/MetadataResolver/DLsiteResolverTest.php @@ -226,4 +226,20 @@ class DLsiteResolverTest extends TestCase $this->assertSame('https://dlsite.jp/howtw/RJ221761.html', (string) $this->handler->getLastRequest()->getUri()); } } + + public function testHTMLdescription() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/DLsite/testHTMLdescription.html'); + + $this->createResolver(DLsiteResolver::class, $responseText); + + $metadata = $this->resolver->resolve('https://www.dlsite.com/books/work/=/product_id/BJ123822.html'); + $this->assertEquals('獣○彼女カタログ', $metadata->title); + $this->assertEquals('著者: チキコ / MUJIN編集部' . PHP_EOL . '【DLsite.com独占販売】 エロ漫画界騒然、1冊まるごと獣○オンリー単行本! 人間チ×ポは出てきませんっ!!', $metadata->description); + $this->assertEquals('https://img.dlsite.jp/modpub/images2/work/books/BJ124000/BJ123822_img_main.jpg', $metadata->image); + $this->assertEquals(['断面図', '制服', '水着', 'メイド', '巫女', '軍服', '中出し', 'フェラチオ', '複数プレイ/乱交', '異種姦', '巨乳/爆乳', '処女', '褐色/日焼け'], $metadata->tags); + if ($this->shouldUseMock()) { + $this->assertSame('https://www.dlsite.com/books/work/=/product_id/BJ123822.html', (string) $this->handler->getLastRequest()->getUri()); + } + } } diff --git a/tests/fixture/DLsite/testHTMLdescription.html b/tests/fixture/DLsite/testHTMLdescription.html new file mode 100644 index 0000000..ecfb7a3 --- /dev/null +++ b/tests/fixture/DLsite/testHTMLdescription.html @@ -0,0 +1,2325 @@ + + + + + + + + + + + + + + + + + + + + + + + + 獣○彼女カタログ [ティーアイネット] | DLsite 成年コミック - R18 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
    + + +
+ +
+ +
+ +
+
+ + + +
+ +
+ +
+ + + + + + +
+
+ +
+ +
+ +
+ + +
+ +
+ +
+ + + +DLsite独占 + + + + +
+

+ +

+ + +
+
+ + + +
+ + + +
+ +
+ + +
+ +
+ + + + + + + + +
+ + + + + + + + +
     
+
+ +
+ +
({{ product.rate_count }})
+ +
+
+ + + + + + + + + + + + + +
平均

{{ product.rate_average_2dp }}

内訳 +
+
+

星5つ

+
+
+
+
+
+ ({{ product.rate_count_detail ? product.rate_count_detail[4].count : 0 }}) +
+
+

星4つ

+
+
+
+
+
+ ({{ product.rate_count_detail ? product.rate_count_detail[3].count : 0 }}) +
+
+

星3つ

+
+
+
+
+
+ ({{ product.rate_count_detail ? product.rate_count_detail[2].count : 0 }}) +
+
+

星2つ

+
+
+
+
+
+ ({{ product.rate_count_detail ? product.rate_count_detail[1].count : 0 }}) +
+
+

星1つ

+
+
+
+
+
+ ({{ product.rate_count_detail ? product.rate_count_detail[0].count : 0 }}) +
+
+
+
+
+
+ +
+
}
+
+ + + + +
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ + + +
+
+
+
+
    + +
  • 獣○彼女カタログ [ティーアイネット]
  • + + +
+
+
+
+
+ +
+
+
    + +
+
+
+
+
+
+
+
+ + HTML版で表示 + + + +
+ + +
+
+ +
+
+ +
+
+
+
+
+
+
{{ swiper.realIndex + 1 }} / {{ items.length }}
+
+
+
+
+
+ + 獣○彼女カタログ [ティーアイネット] + +
+
+
+ + + +
+
+
+
+ +
+
+ + +
+ + + +
+
+ + +
+ + + + + + + + + + + + + +
著者 +チキコ / MUJIN編集部
出版社名ティーアイネットフォローする
レーベルMUJINコミックス
+ +
+ + + + + + + + + + + + + + + +
販売日2017年10月27日
年齢指定
作品形式
ファイル形式
専用ビューア
ページ数218
ジャンル
ファイル容量
+122.36MB +
+ + + +
    + +
  • +
    + この作品はブラウザ上でそのままご覧いただけます。 + なお、ダウンロードして閲覧するには「DLsite Viewer」が必要です。 + 専用ビューアについて ] +
    +
  • + + +
  • +
    + この作品はMacではDLsitePlayのみの対応となります。 + ブラウザ対応について ] +
    +
  • + + + + + + +
+ + + + + +
+ + + + +
+ +
+ + + + + +

作品内容

+
+【DLsite.com独占販売】
+
+※第1話がまるごと「体験版」で読めちゃいます!!
+
+獣に恋したら、ただの雌
+エロ漫画界騒然、1冊まるごと獣○オンリー単行本!
+人間チ×ポは出てきませんっ!!
+
+軍馬に種付けされる敗戦国の女少尉、伝説の白い狼に恋をする少女、
+トラの“専用給仕"として仕えるメイド、イルカとのセックスに溺れてゆく水泳部の少女、
+家畜と契り繁栄の御加護を得るという巫女、出会い系サイトでアルパカと出会ってしまった女子校生…。
+少女達は、獣に恋をする―――。
+
+描き下ろし豪華25P、短編まるごと1本&カラーも1ページ! +
+ + + + + + + + + + + + + + + + + + + + + + +

この作品を買った人はこんな作品も買っています

+
+
+
+
    +
  • +
+ + +
+
+ + + + +
+ + + + + +

こちらの作品も見られています

+
+
+
+
    +
  • +
+ + +
+
+ + + + +
+ + +

最近チェックした作品

+
+
+
+
    +
  • +
+ + +
+
+ + + + +
+ + + + + +
+ + + + + + + + +
+

レビュアーに多く選ばれたジャンル :

+
+ 獣姦(4) +
+ +
+

レビュー数 : 6件

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
いろいろな動物と
+

+ 2019年01月11日   + 人気レビュアー:Best600 + 購入済み +

+
+
+ レビュアーオススメ! +
+
+
+

レビュアーが選んだジャンル :

+ +
+ + +
+

空想の生き物ではなく、リアルにいる生き物とします。設定はエロ漫画の中身としては、申し分ありません!作者が生物系の表現にかなり長けていて、あそこもかなりリアルに描かれています!ある意味、動物に詳しくなります!獣○が好きなら購入しても後悔しないと思いますよ!

+

+ + 1人 が役に立ったと答えています 報告する ] +

+ +
+
+
+
獣○が選り取りみどり!
+

+ 2018年10月04日   + 人気レビュアー:Best300 + 購入済み +

+
+
+ レビュアーオススメ! +
+
+ + +
+

獣○短編集でした!色々と豪華過ぎる内容の獣○漫画でとても楽しめました…個人的には巫女さんのお話とアルパ彼氏が良かったです…!!!チキコさんの描く動物は
+怖そうに見えますが可愛い動物も出てきますよ!それと秀逸なタイトルにも注目です!!

+

+ + 1人 が役に立ったと答えています 報告する ] +

+ +
+
+
+
獣姦好きなら外せない
+

+ 2017年11月14日   + 人気レビュアー:Best300 + 購入済み +

+
+
+
+

レビュアーが選んだジャンル :

+ +
+ + +
+

収録作全て獣姦で、しかも馬・牛・イルカなど大型の動物と女の子の豪快な交尾が多めになっております。背徳的ではなく、堂々と獣姦がまかり通るような世界設定が多いです。
+登場する女の子達が人間ではあり得ない形状のモノに圧倒されながらも、しっかり快楽を感じているのが素晴らしいですね。

+

+ + 1人 が役に立ったと答えています 報告する ] +

+ +
+
+
+
明るく楽しい作品
+

+ 2019年08月06日   + 人気レビュアー:Best400 + 購入済み +

+
+
+ + +
+

まるまる全部が獣姦という作品集。
+
+全体的に大型で、馬や豚といったポピュラーなものから
+トラ、イルカ、アルパカというレアなものまで扱っています。
+それぞれの生き物たちの生態や性器を具体的に描きつつ、
+性器のグロさや人間側の負担などマイナスの部分を
+上手くオミットされているので獣姦としては濃い内容でありながら
+性的にはマイルドで明るく獣姦初心者にもおすすめです。

+

+ + 報告する ] +

+ +
+
+
+
けものせっくす
+

+ 2019年05月10日   + 購入済み +

+
+
+
+

レビュアーが選んだジャンル :

+ +
+ + +
+

いろんな獣とセックスして種付けされてしまいますが、獣それぞれの性器やセックスの特徴をうまく捉えており、なかなかマニアックな作品に仕上がっています。
+ボリュームもたくさんで、獣○好きには大満足の内容です。

+

+ + 報告する ] +

+ +
+
+
+
よき
+

+ 2019年02月12日   + 人気レビュアー:Best200 + 購入済み +

+
+
+ レビュアーオススメ! +
+
+
+

レビュアーが選んだジャンル :

+ +
+ + +
+

絵は少し独特でしたが、女の子は特に嫌がることなくむしろ積極的に楽しんでいるので良かったです。
+終わり方もいい感じでしたし、オチもあってみていて楽しかったです。
+
+このジャンルを見たことがない方にもオススメできます。

+

+ + 報告する ] +

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

関連まとめ記事

+
+ + + + + + + +
+

+ この作品のまとめ記事を投稿しよう! 書き方や詳細については まとめの作り方 をご覧ください。

+
+
+ + + + + +
+

開催中の企画・キャンペーン

+
+ + + + + + + + + + +
+ +
+ + +
+ + + + + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + + + + + +
+ + + + +
+ + + + + + From 2112087e896c84f7b7b93a16d4f29673def3869e Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 20 Aug 2019 01:34:36 +0900 Subject: [PATCH 2/6] =?UTF-8?q?nbsp=E3=82=92space=E3=81=AB=E7=BD=AE?= =?UTF-8?q?=E6=8F=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/DLsiteResolver.php | 3 ++- tests/Unit/MetadataResolver/DLsiteResolverTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/MetadataResolver/DLsiteResolver.php b/app/MetadataResolver/DLsiteResolver.php index 5969d57..951bee4 100644 --- a/app/MetadataResolver/DLsiteResolver.php +++ b/app/MetadataResolver/DLsiteResolver.php @@ -82,7 +82,8 @@ class DLsiteResolver implements Resolver // #work_makerから「makerを含むテキスト」を持つ要素を持つtdを探す // 作者名単体の場合もあるし、"作者A / 作者B"のようになることもある $makersNode = $xpath->query('//*[@id="work_maker"]//*[contains(text(), "' . $makers[0] . '")]/ancestor::td')->item(0); - $makers = trim($makersNode->textContent); + // nbspをspaceに置換 + $makers = trim(str_replace("\xc2\xa0", ' ', $makersNode->textContent)); // makersHaed // $makerNode(td)に対するthを探す diff --git a/tests/Unit/MetadataResolver/DLsiteResolverTest.php b/tests/Unit/MetadataResolver/DLsiteResolverTest.php index 7cac98b..07d7d0c 100644 --- a/tests/Unit/MetadataResolver/DLsiteResolverTest.php +++ b/tests/Unit/MetadataResolver/DLsiteResolverTest.php @@ -106,7 +106,7 @@ class DLsiteResolverTest extends TestCase $metadata = $this->resolver->resolve('https://www.dlsite.com/books/work/=/product_id/BJ191317.html'); $this->assertEquals('永遠娘 vol.6', $metadata->title); - $this->assertEquals('著者: あまがえる / 玉之けだま / びんせん / 甘露アメ / 源五郎 / すみやお / 宇宙烏賊 / 毒茸人 / あやね / ガロウド / ハードボイルドよし子 / 夜歌 / 黒青郎君' . PHP_EOL . '君の命はどんな味なのだろうな?', $metadata->description); + $this->assertEquals('著者: あまがえる / 玉之けだま / びんせん / 甘露アメ / 源五郎 / すみやお / 宇宙烏賊 / 毒茸人 / あやね / ガロウド / ハードボイルドよし子 / 夜歌 / 黒青郎君' . PHP_EOL . '君の命はどんな味なのだろうな?', $metadata->description); $this->assertEquals('https://img.dlsite.jp/modpub/images2/work/books/BJ192000/BJ191317_img_main.jpg', $metadata->image); $this->assertEquals(['ツンデレ', 'ロリ', '妖怪', '人外娘/モンスター娘', 'セーラー服', 'メイド', 'ストッキング', 'ファンタジー', 'ぶっかけ', '中出し', '近親相姦', 'アヘ顔', '口内射精'], $metadata->tags); if ($this->shouldUseMock()) { From bc2f8662fcba342f0ad1e62324973212172797c1 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 7 Aug 2019 19:22:54 +0900 Subject: [PATCH 3/6] =?UTF-8?q?oEmbed=20API=E3=82=92=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/DeviantArtResolver.php | 28 ++++------- .../DeviantArtResolverTest.php | 50 +++++++++++++++++++ tests/fixture/DeviantArt/mature.json | 1 + tests/fixture/DeviantArt/wixmp.json | 1 + 4 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 tests/Unit/MetadataResolver/DeviantArtResolverTest.php create mode 100644 tests/fixture/DeviantArt/mature.json create mode 100644 tests/fixture/DeviantArt/wixmp.json diff --git a/app/MetadataResolver/DeviantArtResolver.php b/app/MetadataResolver/DeviantArtResolver.php index 2ef5898..9f775a7 100644 --- a/app/MetadataResolver/DeviantArtResolver.php +++ b/app/MetadataResolver/DeviantArtResolver.php @@ -23,31 +23,25 @@ class DeviantArtResolver implements Resolver public function resolve(string $url): Metadata { - $res = $this->client->get($url); + $res = $this->client->get('https://backend.deviantart.com/oembed?url=' . $url); if ($res->getStatusCode() === 200) { - $metadata = $this->ogpResolver->parse($res->getBody()); + $data = json_decode($res->getBody()->getContents(), true); + $metadata = new Metadata(); - $dom = new \DOMDocument(); - @$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8')); - $xpath = new \DOMXPath($dom); - - $node = $xpath->query('//*[@id="pimp-preload"]/following-sibling::div//img')->item(0); - $srcset = $node->getAttribute('srcset'); - $srcset_array = explode('w,', $srcset); - $src = end($srcset_array); - $src = preg_replace('~ \d+w$~', '', $src); - - if (preg_match('~\.wixmp\.com$~', parse_url($src)['host'])) { + if (preg_match('~\.wixmp\.com$~', parse_url($data['url'])['host'])) { // アスペクト比を保ったまま、縦か横が最大700pxになるように変換する。 // Ref: https://support.wixmp.com/en/article/image-service-3835799 - if (strpos($src, '/v1/fill/')) { - $src = preg_replace('~/v1/fill/w_\d+,h_\d+,q_\d+,strp~', '/v1/fit/w_700,h_700,q_70,strp', $src); + if (strpos($data['url'], '/v1/fill/')) { + $metadata->image = preg_replace('~/v1/fill/w_\d+,h_\d+,q_\d+,strp~', '/v1/fit/w_700,h_700,q_70,strp', $data['url']); } else { - $src = $src . '/v1/fit/w_700,h_700,q_70,strp/image.jpg'; + $metadata->image = $data['url'] . '/v1/fit/w_700,h_700,q_70,strp/image.jpg'; } + } else { + $metadata->image = $data['url']; } - $metadata->image = $src; + $metadata->title = $data['title'] ?? ''; + $metadata->description = 'By ' . $data['author_name']; return $metadata; } else { diff --git a/tests/Unit/MetadataResolver/DeviantArtResolverTest.php b/tests/Unit/MetadataResolver/DeviantArtResolverTest.php new file mode 100644 index 0000000..c87eeeb --- /dev/null +++ b/tests/Unit/MetadataResolver/DeviantArtResolverTest.php @@ -0,0 +1,50 @@ +shouldUseMock()) { + sleep(1); + } + } + + public function testWixmp() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/DeviantArt/wixmp.json'); + + $this->createResolver(DeviantArtResolver::class, $responseText); + + $metadata = $this->resolver->resolve('https://www.deviantart.com/bonchilo/art/Sally-Nox-743562408'); + $this->assertSame('Sally Nox', $metadata->title); + $this->assertSame('By Bonchilo', $metadata->description); + $this->assertSame('https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/f6b84a8f-053e-4ab6-bd6c-71276a4a9282/dcap4fc-6fd6359c-770b-4515-9e29-e99311d58d57.png/v1/fit/w_700,h_700,q_70,strp/sally__nox_by_bonchilo_dcap4fc-pre.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTE0MCIsInBhdGgiOiJcL2ZcL2Y2Yjg0YThmLTA1M2UtNGFiNi1iZDZjLTcxMjc2YTRhOTI4MlwvZGNhcDRmYy02ZmQ2MzU5Yy03NzBiLTQ1MTUtOWUyOS1lOTkzMTFkNThkNTcucG5nIiwid2lkdGgiOiI8PTEyODAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.zbw4e5eH0NafyMmhM15DKN1NjawSZBUwr2RWQWB7O3o', $metadata->image); + if ($this->shouldUseMock()) { + $this->assertSame('https://backend.deviantart.com/oembed?url=https://www.deviantart.com/bonchilo/art/Sally-Nox-743562408', (string) $this->handler->getLastRequest()->getUri()); + } + } + + public function testMature() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/DeviantArt/mature.json'); + + $this->createResolver(DeviantArtResolver::class, $responseText); + + $metadata = $this->resolver->resolve('https://www.deviantart.com/rasbii/art/backstage-620617246'); + $this->assertSame('backstage', $metadata->title); + $this->assertSame('By Rasbii', $metadata->description); + $this->assertSame('https://orig00.deviantart.net/eb50/f/2016/191/a/b/preview_by_rasbii-da9hzby.png', $metadata->image); + if ($this->shouldUseMock()) { + $this->assertSame('https://backend.deviantart.com/oembed?url=https://www.deviantart.com/rasbii/art/backstage-620617246', (string) $this->handler->getLastRequest()->getUri()); + } + } +} diff --git a/tests/fixture/DeviantArt/mature.json b/tests/fixture/DeviantArt/mature.json new file mode 100644 index 0000000..2f60b55 --- /dev/null +++ b/tests/fixture/DeviantArt/mature.json @@ -0,0 +1 @@ +{"version":"1.0","type":"photo","title":"backstage","category":"Anthro > Digital Media > Drawings > Animals","url":"https:\/\/orig00.deviantart.net\/eb50\/f\/2016\/191\/a\/b\/preview_by_rasbii-da9hzby.png","author_name":"Rasbii","author_url":"https:\/\/www.deviantart.com\/rasbii","provider_name":"DeviantArt","provider_url":"https:\/\/www.deviantart.com","safety":"adult","pubdate":"2016-07-09T13:12:42-07:00","community":{"statistics":{"_attributes":{"views":6678,"favorites":127,"comments":39,"downloads":0}}},"rating":"adult","license":{"_attributes":{"type":"text\/html","href":"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/3.0\/"},"0":"Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License"},"width":"689","height":"619","imagetype":"png","thumbnail_url":"https:\/\/t00.deviantart.net\/eJ1IFDUqQxCrbw2pGNP2ZYtyqk4=\/fit-in\/300x900\/filters:no_upscale():origin()\/pre00\/e504\/th\/pre\/f\/2016\/191\/a\/b\/preview_by_rasbii-da9hzby.png","thumbnail_width":300,"thumbnail_height":270,"thumbnail_url_150":"https:\/\/t00.deviantart.net\/EUshcQ7hG73H6zzfsrnH8xJl5dQ=\/fit-in\/150x150\/filters:no_upscale():origin()\/pre00\/e504\/th\/pre\/f\/2016\/191\/a\/b\/preview_by_rasbii-da9hzby.png","thumbnail_url_200h":"https:\/\/t00.deviantart.net\/ijA0nHI6NA42Ocm0Bfd1rhrDHh0=\/300x200\/filters:fixed_height(100,100):origin()\/pre00\/e504\/th\/pre\/f\/2016\/191\/a\/b\/preview_by_rasbii-da9hzby.png","thumbnail_width_200h":223,"thumbnail_height_200h":200} \ No newline at end of file diff --git a/tests/fixture/DeviantArt/wixmp.json b/tests/fixture/DeviantArt/wixmp.json new file mode 100644 index 0000000..73fd3c0 --- /dev/null +++ b/tests/fixture/DeviantArt/wixmp.json @@ -0,0 +1 @@ +{"version":"1.0","type":"photo","title":"Sally Nox","category":"Manga & Anime > Digital Media > Drawings","url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/f6b84a8f-053e-4ab6-bd6c-71276a4a9282\/dcap4fc-6fd6359c-770b-4515-9e29-e99311d58d57.png\/v1\/fill\/w_947,h_844,q_70,strp\/sally__nox_by_bonchilo_dcap4fc-pre.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTE0MCIsInBhdGgiOiJcL2ZcL2Y2Yjg0YThmLTA1M2UtNGFiNi1iZDZjLTcxMjc2YTRhOTI4MlwvZGNhcDRmYy02ZmQ2MzU5Yy03NzBiLTQ1MTUtOWUyOS1lOTkzMTFkNThkNTcucG5nIiwid2lkdGgiOiI8PTEyODAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.zbw4e5eH0NafyMmhM15DKN1NjawSZBUwr2RWQWB7O3o","author_name":"Bonchilo","author_url":"https:\/\/www.deviantart.com\/bonchilo","provider_name":"DeviantArt","provider_url":"https:\/\/www.deviantart.com","safety":"nonadult","pubdate":"2018-05-05T07:18:54-07:00","community":{"statistics":{"_attributes":{"views":243,"favorites":73,"comments":7,"downloads":7}}},"copyright":{"_attributes":{"url":"https:\/\/www.deviantart.com\/bonchilo","year":"2018","entity":"Bonchilo"}},"width":947,"height":844,"imagetype":"","thumbnail_url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/f6b84a8f-053e-4ab6-bd6c-71276a4a9282\/dcap4fc-6fd6359c-770b-4515-9e29-e99311d58d57.png\/v1\/fit\/w_300,h_900,q_70,strp\/sally__nox_by_bonchilo_dcap4fc-300w.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTE0MCIsInBhdGgiOiJcL2ZcL2Y2Yjg0YThmLTA1M2UtNGFiNi1iZDZjLTcxMjc2YTRhOTI4MlwvZGNhcDRmYy02ZmQ2MzU5Yy03NzBiLTQ1MTUtOWUyOS1lOTkzMTFkNThkNTcucG5nIiwid2lkdGgiOiI8PTEyODAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.zbw4e5eH0NafyMmhM15DKN1NjawSZBUwr2RWQWB7O3o","thumbnail_width":300,"thumbnail_height":267,"thumbnail_url_150":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/f6b84a8f-053e-4ab6-bd6c-71276a4a9282\/dcap4fc-6fd6359c-770b-4515-9e29-e99311d58d57.png\/v1\/fit\/w_150,h_150,q_70,strp\/sally__nox_by_bonchilo_dcap4fc-150.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTE0MCIsInBhdGgiOiJcL2ZcL2Y2Yjg0YThmLTA1M2UtNGFiNi1iZDZjLTcxMjc2YTRhOTI4MlwvZGNhcDRmYy02ZmQ2MzU5Yy03NzBiLTQ1MTUtOWUyOS1lOTkzMTFkNThkNTcucG5nIiwid2lkdGgiOiI8PTEyODAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.zbw4e5eH0NafyMmhM15DKN1NjawSZBUwr2RWQWB7O3o","thumbnail_url_200h":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/f6b84a8f-053e-4ab6-bd6c-71276a4a9282\/dcap4fc-6fd6359c-770b-4515-9e29-e99311d58d57.png\/v1\/fill\/w_225,h_200,q_70,strp\/sally__nox_by_bonchilo_dcap4fc-200h.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTE0MCIsInBhdGgiOiJcL2ZcL2Y2Yjg0YThmLTA1M2UtNGFiNi1iZDZjLTcxMjc2YTRhOTI4MlwvZGNhcDRmYy02ZmQ2MzU5Yy03NzBiLTQ1MTUtOWUyOS1lOTkzMTFkNThkNTcucG5nIiwid2lkdGgiOiI8PTEyODAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.zbw4e5eH0NafyMmhM15DKN1NjawSZBUwr2RWQWB7O3o","thumbnail_width_200h":225,"thumbnail_height_200h":200} \ No newline at end of file From ac40a411dabc83d2250887f6e5a571eae45939fe Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 27 Aug 2019 20:49:04 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=83=AA=E3=81=AE?= =?UTF-8?q?=E5=89=8D=E3=81=AB=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/DeviantArtResolver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/MetadataResolver/DeviantArtResolver.php b/app/MetadataResolver/DeviantArtResolver.php index 9f775a7..939c6dd 100644 --- a/app/MetadataResolver/DeviantArtResolver.php +++ b/app/MetadataResolver/DeviantArtResolver.php @@ -34,7 +34,8 @@ class DeviantArtResolver implements Resolver if (strpos($data['url'], '/v1/fill/')) { $metadata->image = preg_replace('~/v1/fill/w_\d+,h_\d+,q_\d+,strp~', '/v1/fit/w_700,h_700,q_70,strp', $data['url']); } else { - $metadata->image = $data['url'] . '/v1/fit/w_700,h_700,q_70,strp/image.jpg'; + $queryStartPos = strpos($data['url'], '?'); + $metadata->image = substr_replace($data['url'], '/v1/fit/w_700,h_700,strp/image.jpg', $queryStartPos, 0); } } else { $metadata->image = $data['url']; From 91e6cea79ad557ecce3d0a0095c4a23df2383c84 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 27 Aug 2019 21:36:44 +0900 Subject: [PATCH 5/6] =?UTF-8?q?wixmp=E3=81=AEURL=E5=A4=89=E6=8F=9B?= =?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 常にjpgを使用する 1024pxの画像を使用する q_が付いていない場合に対応 --- app/MetadataResolver/DeviantArtResolver.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/MetadataResolver/DeviantArtResolver.php b/app/MetadataResolver/DeviantArtResolver.php index 939c6dd..1233223 100644 --- a/app/MetadataResolver/DeviantArtResolver.php +++ b/app/MetadataResolver/DeviantArtResolver.php @@ -29,13 +29,14 @@ class DeviantArtResolver implements Resolver $metadata = new Metadata(); if (preg_match('~\.wixmp\.com$~', parse_url($data['url'])['host'])) { - // アスペクト比を保ったまま、縦か横が最大700pxになるように変換する。 + // アスペクト比を保ったまま、縦か横が最大1024pxになる画像を取得する。 // Ref: https://support.wixmp.com/en/article/image-service-3835799 + // 作成されていない画像が参照されると403を返すようなので、サイト内で使用されている1024pxにした。 if (strpos($data['url'], '/v1/fill/')) { - $metadata->image = preg_replace('~/v1/fill/w_\d+,h_\d+,q_\d+,strp~', '/v1/fit/w_700,h_700,q_70,strp', $data['url']); + $metadata->image = preg_replace('~/v1/fill/w_\d+,h_\d+(?:,q_\d+),strp/.+\.(jpg|png|webp|gif)~', '/v1/fit/w_1024,h_1024,strp/image.jpg', $data['url']); } else { $queryStartPos = strpos($data['url'], '?'); - $metadata->image = substr_replace($data['url'], '/v1/fit/w_700,h_700,strp/image.jpg', $queryStartPos, 0); + $metadata->image = substr_replace($data['url'], '/v1/fit/w_1024,h_1024,strp/image.jpg', $queryStartPos, 0); } } else { $metadata->image = $data['url']; From 13c3407a4e7e3ba35be06106d8cd83805e8ee655 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 27 Aug 2019 21:40:48 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MetadataResolver/DeviantArtResolverTest.php | 17 ++++++++++++++++- .../fixture/DeviantArt/wixmpNoImageOptions.json | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/fixture/DeviantArt/wixmpNoImageOptions.json diff --git a/tests/Unit/MetadataResolver/DeviantArtResolverTest.php b/tests/Unit/MetadataResolver/DeviantArtResolverTest.php index c87eeeb..88bae98 100644 --- a/tests/Unit/MetadataResolver/DeviantArtResolverTest.php +++ b/tests/Unit/MetadataResolver/DeviantArtResolverTest.php @@ -27,12 +27,27 @@ class DeviantArtResolverTest extends TestCase $metadata = $this->resolver->resolve('https://www.deviantart.com/bonchilo/art/Sally-Nox-743562408'); $this->assertSame('Sally Nox', $metadata->title); $this->assertSame('By Bonchilo', $metadata->description); - $this->assertSame('https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/f6b84a8f-053e-4ab6-bd6c-71276a4a9282/dcap4fc-6fd6359c-770b-4515-9e29-e99311d58d57.png/v1/fit/w_700,h_700,q_70,strp/sally__nox_by_bonchilo_dcap4fc-pre.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTE0MCIsInBhdGgiOiJcL2ZcL2Y2Yjg0YThmLTA1M2UtNGFiNi1iZDZjLTcxMjc2YTRhOTI4MlwvZGNhcDRmYy02ZmQ2MzU5Yy03NzBiLTQ1MTUtOWUyOS1lOTkzMTFkNThkNTcucG5nIiwid2lkdGgiOiI8PTEyODAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.zbw4e5eH0NafyMmhM15DKN1NjawSZBUwr2RWQWB7O3o', $metadata->image); + $this->assertStringStartsWith('https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/f6b84a8f-053e-4ab6-bd6c-71276a4a9282/dcap4fc-6fd6359c-770b-4515-9e29-e99311d58d57.png/v1/fit/w_1024,h_1024,strp/image.jpg?token=', $metadata->image); if ($this->shouldUseMock()) { $this->assertSame('https://backend.deviantart.com/oembed?url=https://www.deviantart.com/bonchilo/art/Sally-Nox-743562408', (string) $this->handler->getLastRequest()->getUri()); } } + public function testWixmpNoImageOptions() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/DeviantArt/wixmpNoImageOptions.json'); + + $this->createResolver(DeviantArtResolver::class, $responseText); + + $metadata = $this->resolver->resolve('https://www.deviantart.com/messenger-lame/art/rem-639676105'); + $this->assertSame('rem', $metadata->title); + $this->assertSame('By messenger-lame', $metadata->description); + $this->assertStringStartsWith('https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/9afa7937-381f-47f0-a8bc-40b9db1faad1/dakuh8p-aea3fc1c-c06e-466b-88ba-d27be8e164e9.png/v1/fit/w_1024,h_1024,strp/image.jpg?token=', $metadata->image); + if ($this->shouldUseMock()) { + $this->assertSame('https://backend.deviantart.com/oembed?url=https://www.deviantart.com/messenger-lame/art/rem-639676105', (string) $this->handler->getLastRequest()->getUri()); + } + } + public function testMature() { $responseText = file_get_contents(__DIR__ . '/../../fixture/DeviantArt/mature.json'); diff --git a/tests/fixture/DeviantArt/wixmpNoImageOptions.json b/tests/fixture/DeviantArt/wixmpNoImageOptions.json new file mode 100644 index 0000000..66a07b2 --- /dev/null +++ b/tests/fixture/DeviantArt/wixmpNoImageOptions.json @@ -0,0 +1 @@ +{"version":"1.0","type":"photo","title":"rem","category":"Manga & Anime > Digital Media > Drawings","url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/9afa7937-381f-47f0-a8bc-40b9db1faad1\/dakuh8p-aea3fc1c-c06e-466b-88ba-d27be8e164e9.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzlhZmE3OTM3LTM4MWYtNDdmMC1hOGJjLTQwYjlkYjFmYWFkMVwvZGFrdWg4cC1hZWEzZmMxYy1jMDZlLTQ2NmItODhiYS1kMjdiZThlMTY0ZTkucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.QX4iUJ00rh1B0PXwyBedqQVbEHR6C72Yp0a9DpM5UIg","author_name":"messenger-lame","author_url":"https:\/\/www.deviantart.com\/messenger-lame","provider_name":"DeviantArt","provider_url":"https:\/\/www.deviantart.com","safety":"nonadult","pubdate":"2016-10-12T05:03:58-07:00","community":{"statistics":{"_attributes":{"views":1612,"favorites":313,"comments":9,"downloads":71}}},"tags":"rem, re_zero_kara_hajimeru_isekai_seikatsu","copyright":{"_attributes":{"url":"https:\/\/www.deviantart.com\/messenger-lame","year":"2016","entity":"messenger-lame"}},"width":"750","height":"1000","imagetype":"png","thumbnail_url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/9afa7937-381f-47f0-a8bc-40b9db1faad1\/dakuh8p-aea3fc1c-c06e-466b-88ba-d27be8e164e9.png\/v1\/fit\/w_300,h_900,strp\/rem_by_messenger_lame_dakuh8p-300w.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTAwMCIsInBhdGgiOiJcL2ZcLzlhZmE3OTM3LTM4MWYtNDdmMC1hOGJjLTQwYjlkYjFmYWFkMVwvZGFrdWg4cC1hZWEzZmMxYy1jMDZlLTQ2NmItODhiYS1kMjdiZThlMTY0ZTkucG5nIiwid2lkdGgiOiI8PTc1MCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19._gC85PXUst0iqKJCZZSUVonW0YRr5GHj2Qen_Q_95Og","thumbnail_width":300,"thumbnail_height":400,"thumbnail_url_150":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/9afa7937-381f-47f0-a8bc-40b9db1faad1\/dakuh8p-aea3fc1c-c06e-466b-88ba-d27be8e164e9.png\/v1\/fit\/w_150,h_150,strp\/rem_by_messenger_lame_dakuh8p-150.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTAwMCIsInBhdGgiOiJcL2ZcLzlhZmE3OTM3LTM4MWYtNDdmMC1hOGJjLTQwYjlkYjFmYWFkMVwvZGFrdWg4cC1hZWEzZmMxYy1jMDZlLTQ2NmItODhiYS1kMjdiZThlMTY0ZTkucG5nIiwid2lkdGgiOiI8PTc1MCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19._gC85PXUst0iqKJCZZSUVonW0YRr5GHj2Qen_Q_95Og","thumbnail_url_200h":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/9afa7937-381f-47f0-a8bc-40b9db1faad1\/dakuh8p-aea3fc1c-c06e-466b-88ba-d27be8e164e9.png\/v1\/fill\/w_150,h_200,strp\/rem_by_messenger_lame_dakuh8p-200h.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTAwMCIsInBhdGgiOiJcL2ZcLzlhZmE3OTM3LTM4MWYtNDdmMC1hOGJjLTQwYjlkYjFmYWFkMVwvZGFrdWg4cC1hZWEzZmMxYy1jMDZlLTQ2NmItODhiYS1kMjdiZThlMTY0ZTkucG5nIiwid2lkdGgiOiI8PTc1MCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19._gC85PXUst0iqKJCZZSUVonW0YRr5GHj2Qen_Q_95Og","thumbnail_width_200h":150,"thumbnail_height_200h":200} \ No newline at end of file