Skip to content

Instantly share code, notes, and snippets.

@manse
Last active July 28, 2022 07:48
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manse/4006178 to your computer and use it in GitHub Desktop.
Save manse/4006178 to your computer and use it in GitHub Desktop.
Pixivのお気に入りユーザーの新着イラストをRSSリーダーで読めるようにします。
<?php
/* ----- configure ----- */
//Pixiv ID
define('PIXIV_ID', 'your_pixiv_id');
//Pixiv password
define('PIXIV_PASSWORD', 'your_pixiv_password');
/* ----- configure ----- */
function socket($url) {
$url = parse_url($url);
$header = array(
'GET ' . $url['path'] . '?' . $url['query'] . ' HTTP/1.1',
'Host: ' . $url['host'],
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: 0'
);
$request = implode("\r\n", $header);
$request .= "\r\n\r\n";
$response = '';
$sock = fsockopen($url['host'], 80);
fputs($sock, $request);
while(!feof($sock)) {
$response .= fgets($sock);
}
fclose($sock);
return $response;
}
function unchunk($body) {
$data = '';
while ($body) {
$body = ltrim($body);
$pair = explode("\r\n", $body, 2);
if (count($pair) === 1) break;
$byte = hexdec($pair[0]);
if ($byte > 0) {
$data .= substr($pair[1], 0, $byte);
$body = substr($pair[1], $byte);
} else {
$body = $pair[1];
}
}
return $data;
}
function receive() {
$src = socket('http://spapi.pixiv.net/iphone/login.php?mode=login&pixiv_id=' . PIXIV_ID . '&pass=' . PIXIV_PASSWORD . '&skip=0');
preg_match_all('/Set-Cookie\:\sPHPSESSID=(\w+)/', $src, $m);
$sessid = $m[1][1];
$data = socket('http://spapi.pixiv.net/iphone/bookmark_user_new_illust.php?dummy=0&PHPSESSID=' . $sessid . '&p=1&c_mode=10');
$data = explode("\r\n\r\n", $data, 2);
$data = unchunk($data[1]);
$data = explode("\n", $data);
array_pop($data);
return $data;
}
header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel>
<title>Pixiv::<?php echo PIXIV_ID;?></title>
<link>http://pixiv.net/</link>
<description><?php echo PIXIV_ID;?>のお気に入りユーザーの新着作品</description>
<dc:language>ja</dc:language>
<dc:creator>info@manse.jp</dc:creator>
<dc:rights>Copyright 2012</dc:rights>
<dc:date><?php echo date('c', mktime(0, 0, 0, date('m'), date('d'), date('Y')));?></dc:date>
<?php
foreach((array)receive() as $row) {
$row = str_getcsv($row, ',', '"');
?>
<item>
<title><?php echo $row[3];?>(<?php echo $row[5];?>)</title>
<link>http://www.pixiv.net/member_illust.php?mode=medium&amp;illust_id=<?php echo $row[0];?></link>
<description><![CDATA[<p><?php echo $row[18];?></p><p align="center"><img src="<?php echo $row[9];?>" /></p>]]></description>
<dc:date><?php echo date('c', strtotime($row[12]));?></dc:date>
</item>
<?php
}
?>
</channel>
</rss>
@NaokiSato102
Copy link

使用方法はどのようなものでしょうか。ざっくりとしたヒントだけでいいので教えていただけないでしょうか。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment