2018-04-14 17:19:35 +02:00
|
|
|
<?php
|
|
|
|
class PixivBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const MAINTAINER = 'teromene';
|
|
|
|
const NAME = 'Pixiv Bridge';
|
|
|
|
const URI = 'https://www.pixiv.net/';
|
|
|
|
const DESCRIPTION = 'Returns the tag search from pixiv.net';
|
|
|
|
|
|
|
|
|
|
|
|
const PARAMETERS = array( array(
|
|
|
|
'tag' => array(
|
|
|
|
'name' => 'Tag to search',
|
|
|
|
'exampleValue' => 'example',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
|
|
|
public function collectData(){
|
|
|
|
|
2018-11-05 12:55:58 +01:00
|
|
|
$html = getContents(static::URI . 'search.php?word=' . urlencode($this->getInput('tag')))
|
2018-04-14 17:19:35 +02:00
|
|
|
or returnClientError('Unable to query pixiv.net');
|
|
|
|
$regex = '/<input type="hidden"id="js-mount-point-search-result-list"data-items="([^"]*)/';
|
|
|
|
$timeRegex = '/img\/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/([0-9]{2})\/([0-9]{2})\/([0-9]{2})\//';
|
|
|
|
|
|
|
|
preg_match_all($regex, $html, $matches, PREG_SET_ORDER, 0);
|
|
|
|
if(!$matches) return;
|
|
|
|
|
|
|
|
$content = json_decode(html_entity_decode($matches[0][1]), true);
|
|
|
|
$count = 0;
|
|
|
|
foreach($content as $result) {
|
|
|
|
if($count == 10) break;
|
|
|
|
$count++;
|
|
|
|
|
|
|
|
$item = array();
|
2018-06-29 23:55:33 +02:00
|
|
|
$item['id'] = $result['illustId'];
|
|
|
|
$item['uri'] = 'https://www.pixiv.net/member_illust.php?mode=medium&illust_id=' . $result['illustId'];
|
|
|
|
$item['title'] = $result['illustTitle'];
|
|
|
|
$item['author'] = $result['userName'];
|
2018-04-14 17:19:35 +02:00
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
preg_match_all($timeRegex, $result['url'], $dt, PREG_SET_ORDER, 0);
|
|
|
|
$elementDate = DateTime::createFromFormat('YmdHis',
|
2018-08-18 21:54:24 +02:00
|
|
|
$dt[0][1] . $dt[0][2] . $dt[0][3] . $dt[0][4] . $dt[0][5] . $dt[0][6],
|
|
|
|
new DateTimeZone('Asia/Tokyo'));
|
2018-06-29 23:55:33 +02:00
|
|
|
$item['timestamp'] = $elementDate->getTimestamp();
|
2018-04-14 17:19:35 +02:00
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
$item['content'] = "<img src='" . $this->cacheImage($result['url'], $item['id']) . "' />";
|
2018-04-14 17:19:35 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:53:45 +02:00
|
|
|
private function cacheImage($url, $illustId) {
|
2018-04-14 17:19:35 +02:00
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
$url = str_replace('_master1200', '', $url);
|
|
|
|
$url = str_replace('c/240x240/img-master/', 'img-original/', $url);
|
2018-11-10 19:48:05 +01:00
|
|
|
$path = PATH_CACHE . 'pixiv_img/';
|
2018-04-14 17:19:35 +02:00
|
|
|
|
|
|
|
if(!is_dir($path))
|
|
|
|
mkdir($path, 0755, true);
|
|
|
|
|
|
|
|
if(!is_file($path . '/' . $illustId . '.jpeg')) {
|
2018-06-29 23:55:33 +02:00
|
|
|
$headers = array('Referer: https://www.pixiv.net/member_illust.php?mode=medium&illust_id=' . $illustId);
|
2018-04-14 17:19:35 +02:00
|
|
|
$illust = getContents($url, $headers);
|
2018-06-29 23:55:33 +02:00
|
|
|
if(strpos($illust, '404 Not Found') !== false) {
|
|
|
|
$illust = getContents(str_replace('jpg', 'png', $url), $headers);
|
2018-04-14 17:19:35 +02:00
|
|
|
}
|
|
|
|
file_put_contents($path . '/' . $illustId . '.jpeg', $illust);
|
|
|
|
}
|
|
|
|
|
2018-06-29 23:55:33 +02:00
|
|
|
return 'cache/pixiv_img/' . $illustId . '.jpeg';
|
2018-04-14 17:19:35 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|