makerをOGPタイトルに含まれる著者名などから取得するように変更
This commit is contained in:
@@ -37,16 +37,36 @@ class DLsiteResolver implements Resolver
|
||||
@$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8'));
|
||||
$xpath = new \DOMXPath($dom);
|
||||
|
||||
// 抽出
|
||||
$title = $xpath->query('//title')->item(0)->textContent;
|
||||
preg_match('~\[([^\[\]]*)\] \| DLsite.+$~', $title, $match);
|
||||
$maker = $match[1];
|
||||
// OGPタイトルから[]に囲まれているmakerを取得する
|
||||
// 複数の作者がいる場合スペース区切りになるためexplodeしている
|
||||
// スペースを含むmakerの場合名前の一部しか取れないが動作には問題ない
|
||||
preg_match('~ \[([^\[\]]*)\] \| DLsite(がるまに)?$~', $metadata->title, $match);
|
||||
$makers = explode(' ', $match[1]);
|
||||
|
||||
// makerに一致するthのテキストを探す
|
||||
$makerHead = trim($xpath->query('//a[contains(text(), "'.$maker.'")]/ancestor::tr/th')->item(0)->textContent);
|
||||
//フォローボタン(.btn_follow)はテキストを含んでしまうことがあるので要素を削除しておく
|
||||
$followButtonNode = $xpath->query('//*[@class="btn_follow"]')->item(0);
|
||||
$followButtonNode->parentNode->removeChild($followButtonNode);
|
||||
|
||||
// maker, makerHeadを探す
|
||||
|
||||
// makers
|
||||
// #work_makerから「makerを含むテキスト」を持つ要素を持つtdを探す
|
||||
// 作者名単体の場合もあるし、"作者A / 作者B"のようになることもある
|
||||
$makersNode = $xpath->query('//*[@id="work_maker"]//*[contains(text(), "' . $makers[0] . '")]/ancestor::td')->item(0);
|
||||
$makers = trim($makersNode->textContent);
|
||||
|
||||
// makersHaed
|
||||
// $makerNode(td)に対するthを探す
|
||||
// "著者", "サークル名", "ブランド名"など
|
||||
$makersHeadNode = $xpath->query('preceding-sibling::th', $makersNode)->item(0);
|
||||
$makersHead = trim($makersHeadNode->textContent);
|
||||
|
||||
// 余分な文を消す
|
||||
|
||||
// OGPタイトルから作者名とサイト名を消す
|
||||
$metadata->title = trim(preg_replace('~ \[([^\[\]]*)\] \| DLsite(がるまに)?$~', '', $metadata->title));
|
||||
|
||||
// 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));
|
||||
} else {
|
||||
@@ -54,7 +74,7 @@ class DLsiteResolver implements Resolver
|
||||
}
|
||||
|
||||
// 整形
|
||||
$metadata->description = $makerHead.': ' . $maker . PHP_EOL . $metadata->description;
|
||||
$metadata->description = $makersHead . ': ' . $makers . PHP_EOL . $metadata->description;
|
||||
$metadata->image = str_replace('img_sam.jpg', 'img_main.jpg', $metadata->image);
|
||||
|
||||
return $metadata;
|
||||
|
Reference in New Issue
Block a user