Skip to content

Instantly share code, notes, and snippets.

@arrowrowe
Created May 9, 2016 11:36
Show Gist options
  • Save arrowrowe/0d0cf9ff647deb1676fbf3706eb741f1 to your computer and use it in GitHub Desktop.
Save arrowrowe/0d0cf9ff647deb1676fbf3706eb741f1 to your computer and use it in GitHub Desktop.
Given a rank of a day, find the right work on Pixiv.
/*** Dependencies ************************************************************/
const Promise = require('bluebird');
const jsEnv = Promise.promisify(require('jsdom').env);
/*** The Function ************************************************************/
const getLinksByRank = (date, rank) =>
jsEnv('http://www.pixiv.net/ranking.php?mode=daily&date=' + date)
.then(window => window.document.getElementById(rank).getElementsByClassName('work')[0].href)
.then(jsEnv)
.then(window => window.document.getElementsByClassName('_work')[0].getElementsByTagName('img')[0].src)
const linkPreviewToOrigin = preview =>
'http://i1.pixiv.net/img-original/img/' + preview.match(/\d{4}(?:\/\d{2}){5}\/\d+_p\d+/)[0] + '.jpg';
/*** Usage *******************************************************************/
const log = console.log.bind(console);
getLinksByRank('20160505', 1)
.tap(log) // Link for preview.
.then(linkPreviewToOrigin)
.tap(log); // Link for origin. Need to set REFERER to download.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment