From a958ccaa08085695a752af5d3171215ff82665fb Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 30 Apr 2019 06:15:27 +0900 Subject: [PATCH] =?UTF-8?q?maker=E3=81=AB=E4=B8=80=E8=87=B4=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=83=86=E3=82=AD=E3=82=B9=E3=83=88=E3=82=92=E6=8E=A2?= =?UTF-8?q?=E3=81=99=E3=82=88=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/DLsiteResolver.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/MetadataResolver/DLsiteResolver.php b/app/MetadataResolver/DLsiteResolver.php index 9f6d6e7..a51cdaa 100644 --- a/app/MetadataResolver/DLsiteResolver.php +++ b/app/MetadataResolver/DLsiteResolver.php @@ -27,16 +27,24 @@ class DLsiteResolver implements Resolver if ($res->getStatusCode() === 200) { $metadata = $this->ogpResolver->parse($res->getBody()); + $dom = new \DOMDocument(); + @$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8')); + $xpath = new \DOMXPath($dom); + // 抽出 - preg_match('~\[(.+)\] \| DLsite$~', $metadata->title, $match); + $title = $xpath->query('//title')->item(0)->textContent; + preg_match('~\[(.+)\] \| DLsite.+$~', $title, $match); $maker = $match[1]; + // makerに一致するthのテキストを探す + $makerHead = $xpath->query('//a[contains(text(), "'.$maker.'")]/ancestor::tr/th')->item(0)->textContent; + // 余分な文を消す $metadata->title = trim(preg_replace('~ \[.+\] \| DLsite$~', '', $metadata->title)); $metadata->description = trim(preg_replace('~「DLsite.+」は同人誌・同人ゲーム・同人音声のダウンロードショップ。お気に入りの作品をすぐダウンロードできてすぐ楽しめる!毎日更新しているのであなたが探している作品にきっと出会えます。国内最大級の二次元総合ダウンロードショップ「DLsite」!$~', '', $metadata->description)); // 整形 - $metadata->description = 'サークル: ' . $maker . PHP_EOL . $metadata->description; + $metadata->description = $makerHead.': ' . $maker . PHP_EOL . $metadata->description; $metadata->image = str_replace('img_sam.jpg', 'img_main.jpg', $metadata->image); return $metadata;