项目作者: HakurouKen

项目描述 :
A third-party Node.js library for Pixiv.
高级语言: JavaScript
项目地址: git://github.com/HakurouKen/pixiv-illust.git
创建时间: 2016-09-23T15:16:30Z
项目社区:https://github.com/HakurouKen/pixiv-illust

开源协议:MIT License

下载


pixiv-illust

npm
LICENCE

A third-party Node.js library for Pixiv.

Install

By Git

  1. git clone https://github.com/HakurouKen/pixiv-illust.git
  2. cd pixiv-illust && npm install
  3. npm link

NOTE: npm link will alias pixiv-download as global command.
If you don’t want to set global alias, use ./bin/download instead.

By npm

  1. npm install pixiv-illust -g

NOTE: If you only want to use javascript api without global command pixiv-download, just use npm install pixiv-illust --save in your project.

Cli

Basic Config

  1. -h, --help output usage information
  2. -u --user <username> username
  3. -p --password <password> password
  4. -c --cookies <cookies> json cookie file
  5. -d --dest [folder] download destination folder

If -u -p is specified, the -c params will be ignored.
Once logged in, login cookies will be cached as json in file .cookies.json. If no login params is specified, the program will try to load this default cached cookies.

Illust

Download illust by id.

  1. pixiv-download illust <id>

Bookmark

Download all favorited illust

  1. pixiv-download bookmark

Author

Download by author id

  1. pixiv-downoad author <id>

Rank

Download leaderboard illusts.

Option:

-m --mode <mode> rank mode, default daily.

-t --date <date> date of rank list yyyyMMdd, default date at 30 hours before.

-r --rank <rank> top n rank, default 50

  1. pixiv-download rank

Example

  1. # Download single illust
  2. pixiv-download illust 59615212 -u username -p password -d ../
  3. # Download illust use cached json-cookie file.
  4. pixiv-download illust 59657563
  5. # Download author illusts
  6. pixiv-download author 8895868
  7. # Download all bookmarks
  8. pixiv-download bookmarks
  9. # Download leaderboard
  10. pixiv-download rank
  11. # Download weekly top 50
  12. pixv-download rank -m weekly -n 50
  13. # Download top 100 ranked by male in 2016-10-01
  14. pixiv-download rank -m daily -t 20161001 -n 100

Api

login

Login in pixiv(CN). Most of actions need login state, so do it before other operations.

An error will be thrown when you do other operations needs login before login.

When you loggged in, you can cached your cookies as a json file use login.dumps, and next time you can load your login states from file using login.loads.

You can also clear your login state use login.reset. Note that this is the only synchronous method of login actions.

  1. var login = require('pixiv-illust').login;
  2. // return a Promise resolved with the response.
  3. login.login('PIXIV_ACCOUNT','PIXIV_PASSWORD').then(function(resp){
  4. // login now.
  5. console.log(resp);
  6. // save the cookies.
  7. return login.dumps('./.cookies.json');
  8. }).then(function(){
  9. // clear the login cookies.
  10. login.reset();
  11. }).catch(function(err){
  12. // some error happend when login.
  13. });
  14. // Or you can load cookies from file.
  15. login.loads('./cookies.json').then(function(){
  16. console.log('Already logged in.');
  17. });

illust

Get the illust by pixiv illust id.

Illust.prototype.getInfo() : Get illust info.

Illust.prototype.download(pathTemplate) : Download the illust to specified path. Strings wrapped by {{}}(eg: {{title}}) will be treated as a template string and will be replaced by the corresponded value of illust. Values id,title,suffix,author,date are vaild.

  1. var pixiv = require('pixiv-illust');
  2. var login = pixiv.login,
  3. Illust = pixiv.Illust;
  4. var loggedIn = login.login('PIXIV_ACCOUNT','PIXIV_PASSWORD');
  5. var illust = new Illust(36486718);
  6. // Get info of illust.
  7. loggedIn.then(function(){
  8. return illust.getInfo();
  9. }).then(function(info){
  10. console.log(info);
  11. // { id: 36486718,
  12. // title: 'セーラームーン',
  13. // author: 'SALT',
  14. // tools: [ 'Photoshop' ],
  15. // page: 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=36486718',
  16. // date: '2013年6月19日 02:26' }
  17. })
  18. // Download illust.
  19. loggedIn.then(function(){
  20. illust.download('{{author}} - {{title}}{{suffix}}');
  21. });

Bookmark

Get the favorited bookmark.

Bookmark.prototype.getPage(page=1): Get the specified page of bookmarks.

Bookmark.prototype.get(page=1): Alias of getPage.

Bookmark.prototype.getPageContent(page=1): Get the page of bookmarks (only illust info, without page info).

Bookmark.prototype.getAll(): Get all bookmarks.

  1. var pixiv = require('pixiv-illust');
  2. var login = pixiv.login,
  3. Illust = pixiv.Illust,
  4. Bookmark = pixiv.Bookmark;
  5. var loggedIn = login.loads('./.cookies.json');
  6. var downloadIllusts = function(list) {
  7. list = list || [];
  8. var illust,
  9. info = list[0];
  10. if (!info) {
  11. return Promise.resolve(null);
  12. }
  13. illust = new Illust(info.illust_id);
  14. return illust.download().then(function(){
  15. return downloadIllusts(list.slice(1));
  16. });
  17. }
  18. // download the first page.
  19. loggedIn.then(function(){
  20. var bookmark = new Bookmark();
  21. return bookmark.getPageContent(1);
  22. }).then(downloadIllusts).catch(console.error);

Author

Get author info.

Author.prototype.getInfo(): Get author info array.

Author.prototype.getIllusts(page=1): Get the specified page of illusts by author.

Author.prototype.getIllustsContent(page=1): Get the specified page of illusts (without page info).

Author.prototype.getAllIllusts(): Get all illusts made by the author.

Rank

Rank.prototype.constructor(mode='daily',date=null): Constructor needs mode/date params. Vaild modes are daily,weekly,monthly,rookie,male,female (do not require login), daily_r18,weekly_r18,r18g,male_r18, female_r18 (r18 needs login). Params date should be a formated date-string yyyyMMdd, or a Date object. The default date is 30 hours ago.

Rank.prototype.getPage(page=1): Get the specified page of custom leaderboard.

Rank.prototype.get(page): Alias of getPage.

Rank.prototype.getRank(rank=500): Get the top n rank.

Rank.prototype.getAll(): Get the full list of custom rank.

  1. var pixiv = require('pixiv-illust');
  2. var login = pixiv.login
  3. Rank = pixiv.Rank;
  4. var loggedIn = login.loads('./.cookies.json');
  5. loggedIn.then(function(){
  6. var rank = new Date('weekly','20161001');
  7. // get weelky top 100 illusts ranked on 2016-10-01.
  8. return rank.getRank(100);
  9. }).then(console.log);

License

MIT