1.0.8 • Published 1 year ago

pixiv-node v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

About

pixiv-node is a simple JavaScript wrapper for Pixiv, which sends requests to their backend API.

Features

  • Fully asynchronous
  • Provides support for most read-only actions
  • Doesn't require authentication for SFW content
  • Provides a way of authenticating for features locked behind accounts
  • Built with TypeScript for improved IDE support

Installation

$ npm i pixiv-node

Usage

Methods

MethodDescriptionAuthentication
getA private utility method used in all other methodsN/A
getIllustGet the data of an illustration/mangaNo
getIllustCommentsGet all the comments of a specific illustration/mangaNo
getIllustImageGet all the images associated with a illustration/mangaIf NSFW
getNovelGet all the data associated with a novelIf NSFW
getNovelCommentsGet all the comments of a specific novelIf NSFW
getNovelSeriesGet all novels inside of a seriesIf NSFW
getUserGet info asociated with a specific user idIf using bookmarks
loginStore your cookie in memory for authenticationN/A
searchSearch for a specific query with additional optional parametersIf using r18

Pixiv groups illustrations and manga together, which is why some of the methods aren't called getIllustMangaX

Method parameters

// dist/index.d.ts

type NumericString = string | number;
export default class Pixiv {
	private static token;
	private static get;
	static getIllust(id: NumericString): Promise<Object>;
	static getIllustComments(
		id: NumericString,
		limit?: NumericString
	): Promise<Object>;
	static getIllustImages(id: NumericString): Promise<Object>;
	static getNovel(id: NumericString): Promise<Object>;
	static getNovelComments(
		id: NumericString,
		limit?: NumericString
	): Promise<Object>;
	static getNovelSeries(id: NumericString): Promise<Object>;
	static getUser(
		id: NumericString,
		option: "all" | "top" | "bookmarks/illusts" | "bookmarks/novels",
		limit?: NumericString
	): Promise<Object>;
	static login(token: string): typeof Pixiv;
	static search({
		query,
		order,
		mode,
		type,
		ai,
	}: {
		query: string;
		order?: "date" | "date_d";
		mode?: "all" | "safe" | "r18";
		type?: "top" | "illust_and_ugoira" | "manga" | "artworks" | "novels";
		ai?: 0 | 1;
	}): Promise<Object>;
}
export {};

Authentication

If you would like to authenticate in order to access account restricted features (NSFW content, bookmarks), then you can pass in part of your browser cookie to the login() method before calling any other methods. It should look something like the following:

const token = "PHPSESSID=xxxxxxx_xxxxxxxxxxxxxxxxx";

In order to access this, you can follow these steps:

  1. Log into pixiv
  2. Open up your browser developer tools
  3. Visit a post
  4. Go to the networks tab in developer tools and search for https://www.pixiv.net/ajax/illusts
  5. Click on the corresponding GET request and scroll down to the first Cookie: section
  6. Copy the part of the cookie that has PHPSESSID=

Example

import Pixiv from "pixiv-node";

(async () => {
	// get 3 comments of a specific illustration or manga
	const comments = await Pixiv.getIllustComments(119640517, 3);

	// get all the data of a specific illustration or manga
	const illust = await Pixiv.getIllust(119640517);

	// get all images of a specific illustration or manga
	const images = await Pixiv.getIllustImages(119640517);

	// get a specific novel
	const novel = await Pixiv.getNovel(17814676);

	// advanced usage:
	// login with browser cookie, then search for all nsfw artwork
	// with the query "gawr gura" using descending order (oldest)
	// and allowing ai artwork
	const search = await Pixiv.login(process.env.TOKEN).search({
		query: "gawr gura",
		order: "date_d",
		mode: "r18",
		type: "illust_and_ugoira",
		ai: 1,
	});
})();

For a more detailed example of how to use this library, you can refer to pixiv-cli.

Development

$ git clone https://github.com/FireStreaker2/pixiv-node.git
$ cd pixiv-node
$ npm i
$ npm run build
$ ./dist/index.js

License

MIT

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago